I'm having a bit of trouble with constructing the minimum and maximum corners of a collision mesh. I think it's best to explain what steps I'm going through:
1) load 3D mesh, assign a world matrix to it (translation, rotation), assign bounding box half extents
2) when a specific event happens in application, generate a 3D bounding box for the mesh using previously defined half extents. This is mainly for debugging as I'm filling the volume defined by this mesh with smaller cubes later. For rendering I'm generating a cuboid mesh centered around (0,0,0) with the half extents and assign the same world matrix as the original mesh. Rendering this shows the mesh is in the correct place.
3) Now I need to check for collisions only on the xz-plane. To do this, I "construct" a cuboid from min/max corners and transform that to the position of the mesh. Now here is the problem though: I don't know how/where I'm going wrong but the min/max corners don't seem to be right. For example:
mesh half extents on xz (1.05, 0.5) -> constructed min = (-4, -3.5) and max = (-5, -1.45). How can min.x > max.x?
Here's the relevant code bit (broadCollisionMeshExtents == half extents):
D3DXMATRIX wMat = linkedObj.object->GetWorldMatrix();
D3DXVECTOR2 extents(linkedObj.broadCollisionMeshExtents->x, linkedObj.broadCollisionMeshExtents->z);
D3DXVECTOR3 minimum = D3DXVECTOR3(-extents.x, 0.0f, -extents.y);
D3DXVECTOR3 maximum = D3DXVECTOR3(extents.x, 0.0f, extents.y);
D3DXVec3Transform(&min4, &minimum, &wMat);
D3DXVec3Transform(&max4, &maximum, &wMat);
minimum = D3DXVECTOR3(min4);
maximum = D3DXVECTOR3(max4);
This seems to work as long as the objects don't have any rotation on them. I can sort of force-fix it by doing:
float maxX = maximum.x;
float maxZ = maximum.z;
float minX = minimum.x;
float minZ = minimum.z;
maximum = D3DXVECTOR3(max(maxX, minX), 0.0f, max(maxZ, minZ));
minimum = D3DXVECTOR3(min(maxX, minX), 0.0f, min(maxZ, minZ));
... but that's just silly. I'm not entirely sure as to what is going on, any help would be greatly appreciated.
Thanks in advance!
Edited by dr4cula, 29 August 2014 - 07:35 AM.