Skip to main content
gamedev.net
🔒 Locked

how BoundingBox works?

Started by ElectronicSandClock Jan 9, 2004 at 6:39 AM 4 replies 550+ views
Original Post
ElectronicSandClock
ElectronicSandClock
I saw the funcion, D3DXComputeBoundingBox, I know this return an pointer to the max and min vertex, but how to make collision between to box with this? I want to do it even if the box is rotated abit... can someone help me?
Fidelio66
Fidelio66
The bounding box function returns 2 points, indicating min and max for a axis-aligned bounding box. Those are local coordinates.
Those parameters can be used as input for the D3DXBoxBoundProbe function.
BOOL D3DXBoxBoundProbe(
CONST D3DXVECTOR3* pMin,
CONST D3DXVECTOR3* pMax,
CONST D3DXVECTOR3* pRayPosition,
CONST D3DXVECTOR3* pRayDirection
);
Typically a game has a player which has a position and a direction in which he moves. You can test using this function to see whether he can walk in that direction or whether he would hit the box.

Rotating a mesh should be done by setting the appropriate world matrix. In this case you can still use it, by multiplying the position and raydirection with the inverse of the meshes world matrix.
ElectronicSandClock
ElectronicSandClock
aint this pixel detection?
because D3DXBoxBoundProbe is for raycasting, right?

well, lets say I have 2 boxes, and I want to see if they collide, how could I do this?
ElectronicSandClock
ElectronicSandClock
aint this pixel detection?
because D3DXBoxBoundProbe is for raycasting, right?

well, lets say I have 2 boxes, and I want to see if they collide, how could I do this?
circlesoft
circlesoft
For a simple check, you need to find the 8 vertices of one of the boxes according to the lowerLeft/lowerRight combination. Then, test to see if any one of those points are inside the second box. Like:

// points[8] is the array of vertices
for( int i = 0; i < 8; i++ )
{
if( (point.x >= lowerLeftBoxTwo.x && point.x <= upperRightBoxTwo.x) &&
(point.y >= lowerLeftBoxTwo.y && point.y <= upperRightBoxTwo.y) &&
(point.z >= lowerLeftBoxTwo.z && point.z <= upperRightBoxTwo.z))
{
// The point is inside the box - there is a collision
}
}


[edited by - circlesoft on January 9, 2004 11:14:08 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.