Bounding Box Creation

Started by
12 comments, last by AdmiralBinary 22 years, 4 months ago
I''ve worked out some stuff with my "3d engine", and now the monster can turn thru 360 degrees, and can move in the direction he is facing. YAHOOOOO! However, I have come upon another problem. Collision detection. No! No! Don''t run away! All I want to know is how to use DirectX 8 to create a simple bounding box for a mesh (so as the monster doesn''t keep walking through a nearby power plant). I''ve looked around the documentation, and have seen functions like D3DXComputeBoundingBox etc, but I can''t figure out how exactly to use them. Can someone give me a couple of lines of source just to put me on the right track? Thanks in advance --------------- I finally got it all together... ...and then forgot where I put it.
Advertisement
Okay, i had this idea last week. Have you ever used RECTs in 2d? I got an idea like that. Here''s my class. I''m making this up right on the spot so if its not totally correct sorry. What it does is alows you to set the values for the top left back corner and bottom right front corner. It also can do tests with points if they are in the box and returns either of the defines at the top.

  #define IS_COLLISION 1             //define testing results for #define NO_COLLISION 2             //collisions. Return valuesclass CCollisionBox3D{public:   void SetTopCorner(float x, float y, float z);   void SetBottomCorner(float x, float y, float z);   int TestCollisions(CollisionBox3D OtherBox);public:   float top_x, top_y, top_x;      //for the top corner of thebox   float bot_x, bot_y, bot_z;      //bottom corner};void CCollisionBox3D::SetTopCorner(float x, float y, float z){   top_x=x;   top_y=y;   top_z=z;}void CCollisionBox3D::SetBottomCorner(float x, float y, float z){   bot_x=x;   bot_y=y;   bot_z=z;}int CCollisionBox3D::TestCollisions(float x, float y, float z){   if(x > top_x && x < bot_x && y > top_y && y < bot_y &&       z>top_z && z < bot_z )   {      return(IS_COLLISION);   }   else   return(NO_COLLISION);   return(NO_COLLISION);}  


Hmmm, I think i might even find this useful
Okay, i had this idea last week. Have you ever used RECTs in 2d? I got an idea like that. Here''s my class. I''m making this up right on the spot so if its not totally correct sorry. What it does is alows you to set the values for the top left back corner and bottom right front corner. It also can do tests with points if they are in the box and returns either of the defines at the top.

    #define IS_COLLISION 3#define NO_COLLISION 2        class CCollisionBox3D{public:   void SetTopCorner(float x, float y, float z);   void SetBottomCorner(float x, float y, float z);   int TestCollisions(CollisionBox3D OtherBox);public:   float top_x, top_y, top_x;      //for the top corner of thebox   float bot_x, bot_y, bot_z;      //bottom corner};void CCollisionBox3D::SetTopCorner(float x, float y, float z){   top_x=x;   top_y=y;   top_z=z;}void CCollisionBox3D::SetBottomCorner(float x, float y, float z){   bot_x=x;   bot_y=y;   bot_z=z;}int CCollisionBox3D::TestCollisions(float x, float y, float z){   if(x > top_x && x < bot_x && y > top_y && y < bot_y &&       z>top_z && z < bot_z )   {      return(IS_COLLISION);   }   else   return(NO_COLLISION);   return(NO_COLLISION);}    


Hmmm, I think i might even find this useful
Thanx very much for taking the time to reply, but I already have a class almost identical to yours: CD3DRect

  class CD3DRect{public: CD3DRect(); CD3DRect(FLOAT,FLOAT,FLOAT,FLOAT,FLOAT,FLOAT); FLOAT fMinX, fMinY, fMinZ; FLOAT fMaxX, fMaxY, fMaxZ;};  


I know, i know...public member data...but for a small class like that i think easy and fast access is more important.

Anyway, what I REALLY need to know is how to compute the bounding box of a 3d mesh in directX 8. Anyone?

---------------

I finally got it all together...
...and then forgot where I put it.
Doesn''t D3DXComputeBoundingBox solve the problem?
Yeah i tried that, but i couldn''t figure out how to get the vertex buffer to pass to it (i''m using a mesh). I got all confused... And for some strange reason it accepts a BYTE**

---------------

I finally got it all together...
...and then forgot where I put it.
Are AABBs good enough? If so, then just find the maximum and minimum x, y, and z values.

  float xmax = object.origin.x;for(int i = 0; i < NUM_VERTS; i++){      if(object.verts[i].x > xmax)      {         xmax = object.verts[i].x;      }}//Do same for y and z       


OBBS are a little more complicated...
Well, erm, thanx again for the help...I could do that if I had the mesh''s vertices. I don''t have them. I could also use D3DXComputeBoundingBox - IF I had the vertices. Anyway, if anyone out there knows direct3d 8 and wants to help me...it would be appreciated.

P.S. My question is API-specific (Direct3D 8.0 to be precise)

---------------

I finally got it all together...
...and then forgot where I put it.
Use ID3DXMesh->GetVertexBuffer() and then lock the buffer. Pass the returned pointer to D3DXComputeBoundingBox after casting it to PVOID.
d00d thanx! That helps alot!

---------------

I finally got it all together...
...and then forgot where I put it.

This topic is closed to new replies.

Advertisement