I'm trying to detect collision between planes (particles) and boxes (building bounding box) so I can prevent rain/snow particles from entering buildings.
Here is what I'm doing (not working though):
// q1, q2, q3, q4 = Particle plane verticesAABB aabb = GetBuildingBoundaryBox(); // *** The bounding box is calculated using D3DXComputeBoundingBox() ***
D3DXVECTOR3 boxPosition = GetBuildingPosition();
D3DXMATRIX matBox;
D3DXMatrixTranslation(&matBox, boxPosition.x, boxPosition.y, boxPosition.z);
D3DXVec3TransformCoord(&aabb.Min, &aabb.Min, &matBox);
D3DXVec3TransformCoord(&aabb.Max, &aabb.Max, &matBox);
Plane plane;
plane.normal = GetTriangleNormal(q1, q2, q3);
plane.offset = D3DXVec3Dot(&plane.normal, &q1);
if (TestBoxToPlaneCollision(plane, aabb))
{
// Collision detected
} else {
// Collision NOT detected
}
Is the above code valid? It's not working with me (It's detecting collision when there is no collision)