Skip to main content
gamedev.net
🔒 Locked

please answer this simple question...

Started by monkey_face Jan 4, 2002 at 2:20 AM 6 replies 400+ views
Original Post
monkey_face
monkey_face
up until now, i''ve been declaring all my vertices as below: { -20.0f, 0.0f, -20.0f, 0.0f, 0.0f }, { -20.0f, 0.0f, -10.0f, 0.0f, 1.0f }, { -10.0f, 0.0f, -20.0f, 1.0f, 0.0f }, { -10.0f, 0.0f, -10.0f, 1.0f, 1.0f }; x, y, z, then my texture coordinates. to my knowledge, these coordinates are being declared in "world space", as i am rendering a room, and "drawing" things in relation to each other. all i have so far is a room with a hallway, and i guess it''s okay to render the walls with world coordinates? my other question is what is the best way to declare object coordinates? i suppose to best way to do this would be to declare them in their own space, then convert them to world space, as they would be easier to move simply but incrementing/decrementing their world coordinates...but i can''t figure out the code. how is this done? thanks for the help.
rapso
rapso
you should look at some tutorials with matrices (matrix).

dynamic objects should be strored as object with local coordinates and a matrix.
static objects can be store in worldspace or the same way like dynamic objects.

in the matrix you put all you need, like translation,rotation,scaling and you set them to opengl or d3d7/8 and the APIs should do the rest for you.

rapso->greets();
monkey_face
monkey_face
can anyone show me a short sample piece of code demonstrating this?
Mark Duffill
Mark Duffill
DirectX 8 C++ help , DirectX Graphics->DirectX Graphics C/C++ Tutorials->Tutorial 3: Using Matrices
steg
steg
You should declare your objects in some structure each having a world x-coordinate, world y-coordinate, world z-coordinate and possible x,y,z rotations. From this you would use the objects world x,y,z coordinates as part of your world matrix translation into world space. Now to move your object you would just adjust it''s world x,y,z coordinates, of course you may need to apply rotations on the object dependent on which way it is moving i.e. if coming out of the screen(moving) forward you would want it to look forward.

Example - please note this is a very basic implementation...

class Object
{
protected:
float wXpos, wYPos, wZPos;
float wXRot, wYRot, wZRot;
// etc...
};

Object obj;

D3DXMatrixTranslations(&matWorld,obj->wXPos,wYPos,wZPos);

and to move....

obj->wXPos += 0.1f;

Of course you would use affinite translations to do the rotations (basically concatinate all the translations into one).

Hope this has shed some light ?

Regards,
sTeVe


If it isn't working, take a bath, have a think and try again...
monkey_face
monkey_face
yes! steg, your post helped very much. thank you! to do all the translations as you mentioned, is that just multiplying them?
steg
steg
Hi guys,
I''m pleased I''ve shed some light on this, yes you do multiply all the matrices (concatinate - affinite...), here is an example of a method to do object->world translations:

void CTransfromation::MakeWorldMatrix(D3DXMATRIX* pMatWorld, CObject* pObject)
{
D3DXMATRIX MatTemp;
D3DXMATRIX MatRot;

D3DXMatrixTranslation(pMatWorld,
pObject->m_fXPos,
pObject->m_fYPos,
pObject->m_fZPos);

D3DXMatrixIdentity(&MatRot);

D3DXMatrixRotationX(&MatTemp, pObject->m_fPitch);
D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

D3DXMatrixRotationY(&MatTemp, pObject->m_fYaw);
D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

D3DXMatrixRotationZ(&MatTemp, pObject->m_fRoll);
D3DXMatrixMultiply(&MatRot, &MatRot, &MatTemp);

D3DXMatrixMultiply(pMatWorld, &MatRot, pMatWorld);
}

Where pObject is a pointer to an object such as :

class CObject
{
int m_nType;
int m_nStartVertexBuffer;
int m_nEndVertexBuffer;
float m_fXPos, m_fYPos, m_fZPos;
float m_fPitch, float m_fYaw, float m_fRoll;
// etc...
....
....
};

In your render code you could do something like (not this is taken from my game, pMap is a pointer to a map of many CObjects):

// view transformation
camera.Update();
pDevice->SetTransform(D3DTS_VIEW, &camera.GetView());
// world transformation etc..
while(pMap)
{
CObject* pObject = pMap->next;
pTransformation->MakeWorldMatrix(&WorldMatrix, &pObject);
pDevice->SetTransform(D3DTS_WORLD,&WorldMatrix);
pDevice->SetStreamSource(0, pVBuffer, sizeof(CVERTEX));
pDevice->DrawPrimitive(pObject->m_nType,
pObject->m_nStartVertexBuffer,
pObject->m_nEndVertexBuffer);
pMap = pMap->next;
}

Hope this helps ?!

Regards,
sTeVe
If it isn't working, take a bath, have a think and try again...

Topic Locked

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

Sign in to reply to this topic.