• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1theo2005  Members   -  Reputation: 114

Like
0Likes
Like

Posted 02 July 2012 - 04:36 AM

So here is the logical part:

	   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.

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.

### #2theo2005  Members   -  Reputation: 114

Like
0Likes
Like

Posted 05 July 2012 - 04:27 AM

bump

### #3larspensjo  Members   -  Reputation: 1448

Like
0Likes
Like

Posted 05 July 2012 - 01:22 PM

Some hints that may help:
• Use a better subject. There are lots of discussions and questions. People reading topics prefer to read those that are in their area of interest. With no area specified you miss out a lot of viewers.
• Use tags to also help people select.
• State the problem first in your post, and preferably also in the topic title. I started to read, but gave it up. It is simply not interesting to read a source code without know what you should look for.

Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

### #4Narf the Mouse  Members   -  Reputation: 318

Like
0Likes
Like

Posted 05 July 2012 - 02:36 PM

Sounds like you might be mixing corner coordinates and center coordinates.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS