   Some problem with C++ Array and some question in graphics..
  I may be asking to much question :)I just wondering about the array in c++ like if i create a class with array variable like so:class A {  Data* terrain;   ... }I want to define the size of an array inside the constructor, how do i do that? most of the language can easily do it but I not sure about c++. The second problem defining an two dimensional array argument in a function e.g.void func(Data terrain[][12]); Is it possible to define without the requirement of the size 12? ////Question for the GraphicWhat is the land of detail? Is it something about reducing the number of polygons drawing on the screen when the distance is on the far side to the viewer.  Is there any good reference for BSP tree that is easily understand?What are the ways of casting a shadow in opengl apart from using stencil buffer? Stencil buffer seems hard when I looked at the nehe.gamedev.net   
  To create an array with specified type use: Data *data = new Data[SIZE_OF_ARRAY];There's no way that I know of around the two dimensional function parameter. The compiler needs to know the size of each row in order to traverse the array correctly.   ;Quote:Original post by kbundyI may be asking to much question :)I just wondering about the array in c++ like if i create a class with array variable like so:class A {  Data* terrain;   ... }I want to define the size of an array inside the constructor, how do i do that? most of the language can easily do it but I not sure about c++. You could use a dynamic array, like a std::vector, and not have to. Or, you could set up your c-tor to take the array size as a param:class A{public:A(const int arraySize);}Which you can use by calling new:new array[arraySize];The other option would be to templatize the class with the array size the template argument.Quote:Original post by kbundyThe second problem defining an two dimensional array argument in a function e.g.void func(Data terrain[][12]); Is it possible to define without the requirement of the size 12? No. When passing a 2D array, you must specify the size if the first dimension. Honestly, I think its best to not use 2D arrays at all. They add unnecessary complexity and are easy enough to fake:array[row][col] = array[row * columns + col][Edited by - Driv3MeFar on June 21, 2006 2:23:39 AM];  For BSP, you may want to read this:http://www.gamedev.net/reference/articles/article657.aspLOD means 'level of detail'. It is used to reduce the amount of work, i.e. trees far away can be rendered with fewer polygons, terrain may be tesselated into fewer triangles, objects may be replaced by simple sprites.Now your array question:An array is a contiguous sequence of values. C++ does not store/check the size of an array at runtime. In your example, class A contains a pointer to an object of type Data. If the pointer is valid (i.e. points to some location), it may either point to a single object or to an array. To create an array, you can call new: "terrain = new Data[4711];".In the second array problem, your function func() expects a pointer to a two-dimensional array. Since the compiler must know how to index such an array using two indices, at least one of the sizes must be known. Instead of letting the compiler perform the mapping from a 2D-array (using two indices) to a 1D-array (representation in memory), you may also perform the calculation by hand: "void func(Data* terrain, int n) { ... terrain[y*n + x] = ...; }"Hope that helped.   ;  A normal C++ array is defined like this, at a set size:Data terrain[12];What you seem to be after is a dynamic array:Data* terrain;terrain = new Data[size];...delete [] terrain;  // Don't forget to destroy your objects, unless you like memory leaksAs for function arguments, what is possible is taking a Data* argument, and as you've seen, that can be a pointer to a Data array. However, I think you're better off encapsulating the 2D array of terrain data into a class of it's own, a Terrain class. I don't know what functions you wanted to call on this terrain, but some are perhaps better suited as member functions of this Terrain class.As for land of detail, I assume you mean level of detail. It's indeed a general term for reducing detail when objects get further away, or out of focus. It's not just reducing poly count, it may also be using billboards for far-away models, for example.Have you taken a look at Wikipedia's binary space partitioning page already?   ;  a little brush up on arrays:memory can best be imagined as a group of boxes on top of each , last one in is first one out,also referred to as a stack of dishes. every bit of memory you store is in one of those boxesand the order they are stored in is sequential.when you ask to retrive a specfic memory , a memory pointer (a.k.a register) is assigned the address of that specfic memory. diffrentdata types demand diffrent sizes , so memory zones are created (e.g for a 4byte integer youneed 4*8 boxes , so yor memory zones is from StartingAddress -> Starting address + (4*8)).anything higher is considered invalid. an array books a zone in this manner range = StartingAddress -> StartingAddress + IndexOfArray*SizeOfType , still it also has a pointer to each starting address of a member of that array , and can be accessed using the index.C++ provides pointers , which basicly point to the address of an object that it's type is defined on creation (there are some exceptions). you can book memory zones manualy by using the NEW key word where you provide a type of data and it books it. arrays can be created using the NEW keyword in the mannerexample: int * ptr = new int[Size];the data created can only be accessed using that pointer , and it's not considered local.Note: arrays that are created normally (with using NEW) are considered local and are destroyed when the function returns. avoid deleting you pointer before you delete the datait's pointing to , to avoid memory leaks. use delete [] ptr to delete the data in the that address.C++ let's you create a pointer to any address, and attempting to read random addresses isdefined to have random behavior.attempting to read past the end of an array is also like the latter.regarding your question the only reason i can think of , that justify not wanting to set a size of an array , is basicly you need to change the size of the array at anytime. the standard library has a vector classwhich is basicly a dynamic array and has a bunch of usefull functionality , i advice that youcheck it out.   