Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AdmiralBinary

Bounding Box Creation

This topic is 6007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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 values


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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Use ID3DXMesh->GetVertexBuffer() and then lock the buffer. Pass the returned pointer to D3DXComputeBoundingBox after casting it to PVOID.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!