Advertisement

How to access boolean* space = (boolean*)malloc( 640*480*100*sizeof(boolean));

Started by July 14, 2001 03:53 AM
4 comments, last by Afterlife 23 years, 7 months ago
How do I define points in this 3d space true and false?
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
  int x, y, z;  // defined as the 3d coordinates you''re looking forint width = 640;int height = 480;int depth = 100;space[(z * (width * height)) + (y * width) + x] = whatever;  


And that''s it.

Be aware, if sizeof(boolean) is 1 byte, that structure will take up about 30 MB of memory...



War Worlds - A 3D Real-Time Strategy game in development.
Advertisement
Thanks. Is this btw the usual way of defining a 3d space (with malloc() I mean)? In what kind of variable would pros store a 3d map for example?

Edited by - Afterlife on July 14, 2001 9:35:44 AM
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
You probably should look into

Binary Trees ( Binary Space Partition BSP ) or Oct Trees for storking information like that. Both are methods of storing that king od data effeciently based on the fact that there will be large chunks of space that are normally empty all of the time.

Good luck.

Afterlife:

Sorry, but you are approaching this all wrong. What is normally done is you have an object. This object is made up of a bunch of polygons, usually triangles. The triangles are stored as a set of three 3D coordinates. Here is a very basic idea:

  struct Point3D{    float x;    float y;    float z;}struct Triangle3D{    Point3D point[3];  // the three points that define this tri.     Texture texture;   // possibly some sort of texture def.}  


Then you make a 3D object out of a bunch of Triangle3D structs.

You most definitely do not make a big 3D array (unless you are doing something with VOXELS) for normal 3D work.

If you needed to define points in a 3D space as true or false, just store a list (1D array) of "true" points.


Thanks, all help greatly appritiated. 3d, I''m getting there...
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-

This topic is closed to new replies.

Advertisement