if (FrontX[SKELE][0] / BackX[3][0] > 0.98 && FrontX[SKELE][0] / BackX[3][0] < 1)
{
Movement = FALSE;
}
else
{
Movement = TRUE;
}
Coordinates of object [3]:
TranslateX[3] = 5.0f; TranslateY[3] = 0.0f; TranslateZ[3] = 0.0f;
[SKELE] is the skeleton that I move around with. [0] above is the first corner out of four, I only go with one corner to test the results.
So I get the values I need from XAnimator and store them, then transform.
D3DXVECTOR3 cornersInModelSpace[8];
cornersInModelSpace[0] = D3DXVECTOR3( minBoundsModelSpace.x, minBoundsModelSpace.y, minBoundsModelSpace.z ); // xyz
cornersInModelSpace[1] = D3DXVECTOR3( maxBoundsModelSpace.x, minBoundsModelSpace.y, minBoundsModelSpace.z ); // Xyz
cornersInModelSpace[2] = D3DXVECTOR3( minBoundsModelSpace.x, maxBoundsModelSpace.y, minBoundsModelSpace.z ); // xYz
cornersInModelSpace[3] = D3DXVECTOR3( maxBoundsModelSpace.x, maxBoundsModelSpace.y, minBoundsModelSpace.z ); // XYz
cornersInModelSpace[4] = D3DXVECTOR3( minBoundsModelSpace.x, minBoundsModelSpace.y, maxBoundsModelSpace.z ); // xyZ
cornersInModelSpace[5] = D3DXVECTOR3( maxBoundsModelSpace.x, minBoundsModelSpace.y, maxBoundsModelSpace.z ); // XyZ
cornersInModelSpace[6] = D3DXVECTOR3( minBoundsModelSpace.x, maxBoundsModelSpace.y, maxBoundsModelSpace.z ); // xYZ
cornersInModelSpace[7] = D3DXVECTOR3( maxBoundsModelSpace.x, maxBoundsModelSpace.y, maxBoundsModelSpace.z ); // XYZ
// Now we transform each corner by the world matrix
D3DXVECTOR3 cornersInWorldSpace[8];
for( int i = 0; i < 8; i++ )
{
D3DXVec3TransformCoord( &cornersInWorldSpace[i], &cornersInModelSpace[i], &IdentityMatrix);
}
IdentityMatrix is set here, before the function is called
for (int count = 0; count < ObjectQuantity; ++count)
{
D3DXMatrixMultiply(&IdentityMatrix, &matRotateY[count], &matTranslate[count]);
// d3ddev->SetTransform(D3DTS_WORLD, &IdentityMatrix); // set the world transform
RenderBoundingBoxes(count);
d3ddev->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, 8, 0, 24);
}
Like you see above, I draw the indexed primitive above, after I loaded the vertices (below). But
the bounds I get for all objects are wrong, unless I uncomment the settransform above, which
draws the bounds correctly for every object, except object [3], in which case the bounds are not only
in the wrong place, but the object bound is longer in size.
D3DXVECTOR3 front[4],back[4];
front[0] = cornersInWorldSpace[0];
front[1] = cornersInWorldSpace[2];
back[2] = cornersInWorldSpace[3];
back[3] = cornersInWorldSpace[1];
front[3] = cornersInWorldSpace[4];
front[2] = cornersInWorldSpace[6];
back[1] = cornersInWorldSpace[7];
back[0] = cornersInWorldSpace[5];
static float (* FrontX)[4] = new float[ObjectQuantity][4];
static float (* FrontY)[4] = new float[ObjectQuantity][4];
static float (* FrontZ)[4] = new float[ObjectQuantity][4];
static float (* BackX)[4] = new float[ObjectQuantity][4];
static float (* BackY)[4] = new float[ObjectQuantity][4];
static float (* BackZ)[4] = new float[ObjectQuantity][4];
for (int count = 0; count < 4; ++ count)
{
FrontX[ObjNum][count] = front[count].x;
FrontY[ObjNum][count] = front[count].y;
FrontZ[ObjNum][count] = front[count].z;
BackX[ObjNum][count] = back[count].x;
BackY[ObjNum][count] = back[count].y;
BackZ[ObjNum][count] = back[count].z;
}
CUSTOMVERTEX vertices[] =
{
{ FrontX[ObjNum][0], FrontY[ObjNum][0], FrontZ[ObjNum][0], D3DCOLOR_XRGB(0, 0, 255), },
{ FrontX[ObjNum][1], FrontY[ObjNum][1], FrontZ[ObjNum][1], D3DCOLOR_XRGB(0, 0, 255), },
{ FrontX[ObjNum][2], FrontY[ObjNum][2], FrontZ[ObjNum][2], D3DCOLOR_XRGB(0, 0, 255), },
{ FrontX[ObjNum][3], FrontY[ObjNum][3], FrontZ[ObjNum][3], D3DCOLOR_XRGB(0, 0, 255), },
{ BackX[ObjNum][0], BackY[ObjNum][0], BackZ[ObjNum][0], D3DCOLOR_XRGB(0, 0, 255), },
{ BackX[ObjNum][1], BackY[ObjNum][1], BackZ[ObjNum][1], D3DCOLOR_XRGB(0, 0, 255), },
{ BackX[ObjNum][2], BackY[ObjNum][2], BackZ[ObjNum][2], D3DCOLOR_XRGB(0, 0, 255), },
{ BackX[ObjNum][3], BackY[ObjNum][3], BackZ[ObjNum][3], D3DCOLOR_XRGB(0, 0, 255), },
};
// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();
The 4 BackX corners of object [3] are at X = 5
The 4 FrontX corners of object [3] are at X = -24.4257
Now if I think logically, my object is not that big really. So I take my skeleton and
go to the back side of my object.
So I'm with the skeleton where the back of my object is.
BackX then is approximately -10
then I go to the front of object [3]
and the coordinates are the same as above, approx -24
----------------
So my question is, how is that possible? Where is my error?
As you can see above, I did indeed set the object[3] X coordinate to 5,
that is where collision happens, but my object is drawn at -10 for some reason.
Strangely enough, the front of the cube does collision correctly at where it is drawn.
Please help!
If there is anything unclear, I am willing to supply any information needed, so please post!
Theo
EDIT:
Here's the drawing code, in case it helps any..
for (int CountRender = 0;CountRender < ObjectQuantity; ++ CountRender) //draw all the objects despite of which object time calculation is executing
{
D3DXMatrixTranslation(&matTranslate[CountRender], TranslateX[CountRender], TranslateY[CountRender], TranslateZ[CountRender]);
XAnimator->Render(ModelID[CountRender], matRotateY[CountRender] * matTranslate[CountRender] ,(float)timeElapsedSinceLastUpdate[CountRender]);
}
Edited by theo2005, 02 July 2012 - 04:39 AM.






