BIG problem in DIRECT3D IM........
I''m having a problem in finding the world coords of any object in D3D IM.
The following code is what i have employed in the movement of my object -
////////////////////////////////////////////////////////////////////////////////////////////////////////
#define TEMP_TRANSFORM_OBJECT 1
#define SPEED 0.2
CD3DFile* m_pFileObject[MAX_MESH_OBJECTS]; // file object class
MeshObject m_MeshObject[MAX_MESH_OBJECTS];
D3DVECTOR pDeltaPos; // move increments
D3DVECTOR pDeltaDir; // rotate increments
// world matrices
D3DMATRIX m_matTemp;
D3DMATRIX m_matWorld;
D3DMATRIX m_matView;
D3DMATRIX matProj;
//----------------------------------------------------------// Name: FrameMove()
//----------------------------------------------------------HRESULT CMyD3DApplication::FrameMove( FLOAT fTimeKey )
{
static CD3DFileObject* pObject = m_pFileObject[TEMP_TRANSFORM_OBJECT]->FindObject( "Frame_World" );
static bool bFirstTime = true;
static D3DVECTOR vEyePt,vLookatPt,vUpVec;
static float fPhase;
fPhase = fTimeKey/3;
pDeltaDir.x=pDeltaDir.y=pDeltaDir.z=0;
pDeltaPos.x=pDeltaPos.y=pDeltaPos.z=0;
FillInputState();
// to rotate left
if(KeysState[DIK_COMMA] & 0x80)
{
pDeltaDir.y=-0.1f;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y-=0.05f;
CallRotateFunctions(TEMP_TRANSFORM_OBJECT);
pDeltaDir.x=pDeltaDir.y=pDeltaDir.z=0;
pDeltaPos.x=pDeltaPos.y=pDeltaPos.z=0;
}
// to rotate right
if(KeysState[DIK_PERIOD] & 0x80)
{
pDeltaDir.y=0.1f;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y+=0.05f;
CallRotateFunctions(TEMP_TRANSFORM_OBJECT);
pDeltaDir.x=pDeltaDir.y=pDeltaDir.z=0;
pDeltaPos.x=pDeltaPos.y=pDeltaPos.z=0;
}
// to move forward
if(KeysState[DIK_UP] & 0x80)
{
pDeltaPos.z=SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.x+=cos(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*sin((double)m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y)*SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.y+=sin(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.z+=cos(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*cos((double)m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y)*SPEED;
CallTranslateFunctions(TEMP_TRANSFORM_OBJECT);
pDeltaDir.x=pDeltaDir.y=pDeltaDir.z=0;
pDeltaPos.x=pDeltaPos.y=pDeltaPos.z=0;
}
// to move back
if(KeysState[DIK_DOWN] & 0x80)
{
pDeltaPos.z=-SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.x-=cos(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*sin((double)m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y)*SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.y-=sin(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*SPEED;
m_MeshObject[TEMP_TRANSFORM_OBJECT].pPos.z-=cos(m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.x)*cos((double)m_MeshObject[TEMP_TRANSFORM_OBJECT].pRot.y)*SPEED;
CallTranslateFunctions(TEMP_TRANSFORM_OBJECT);
pDeltaDir.x=pDeltaDir.y=pDeltaDir.z=0;
pDeltaPos.x=pDeltaPos.y=pDeltaPos.z=0;
}
// Set the object''s world matrix ( What the heck does this do?? )
m_pd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &m_matWorld );
return S_OK;
}
// does all the transformation stuff here
void CMyD3DApplication::CallTranslateFunctions(int meshno)
{
static CD3DFileObject* pObject = m_pFileObject[meshno]->FindObject( "Frame_World" );
D3DMATRIX* pmatObj = pObject->GetMatrix();
if( pObject )
{
D3DUtil_SetTranslateMatrix(m_MeshObject[meshno].MatTrans,pDeltaPos.x,pDeltaPos.y,pDeltaPos.z);
D3DMath_MatrixMultiply( *pmatObj, m_MeshObject[meshno].MatTrans, *pmatObj );
}
}
void CMyD3DApplication::CallRotateFunctions(int meshno)
{
static CD3DFileObject* pObject = m_pFileObject[meshno]->FindObject( "Frame_World" );
D3DMATRIX* pmatObj = pObject->GetMatrix();
if( pObject )
{
D3DUtil_SetRotateXMatrix(m_MeshObject[meshno].MatRotate,pDeltaDir.x);
D3DMath_MatrixMultiply( *pmatObj, m_MeshObject[meshno].MatRotate, *pmatObj );
D3DUtil_SetRotateYMatrix(m_MeshObject[meshno].MatRotate,pDeltaDir.y);
D3DMath_MatrixMultiply( *pmatObj, m_MeshObject[meshno].MatRotate, *pmatObj );
D3DUtil_SetRotateZMatrix(m_MeshObject[meshno].MatRotate,pDeltaDir.z);
D3DMath_MatrixMultiply( *pmatObj, m_MeshObject[meshno].MatRotate, *pmatObj );
}
}
////////////////////////////////////////////////////////////
is this method of moving an object correct???
vPos is a Point3D struct i have created to hold the coords of the object in 3d space which i am manually calculating every frame using the sin & cos methods which is pretty inacurate and slow.how do i get the world coords( from the object''s matrix probably )??if i access the vector m_MeshObject[meshno].MatTrans it gives me some screwed up values.
please could u also explain the use of settransform & gettransform routines??
ThanX a LOT for ur TIME!!!!
sandeep_kl@mailcity.com
Raptor
Oh man, you are truly desperate. You need to learn to have patience when trying to get answers from any forum. There is no need to post more than once, per day at least. If you post as you have this time, people will only be annoyed with you and ignore your question. Just a friendly advice.
From what I can see you update the objects position and orientation correctly, the problem is when you compute the transformmatrix. If you have position and rotation angles (which you do) the matrix can be computed like this:
D3DMATRIX T,Ry,Rx;
D3DUtil_SetRotateXMatrix(Rx, RotX);
D3DUtil_SetRotateYMatrix(Ry, RotY);
D3DUtil_SetTranslateMatrix(T, PosX,PosY,PosZ);
D3DMATRIX WorldMtx;
D3DMath_MatrixMultiply(WorldMtx, Rx, Ry);
D3DMath_MatrixMultiply(WorldMtx, WorldMtx, T);
- WitchLord
From what I can see you update the objects position and orientation correctly, the problem is when you compute the transformmatrix. If you have position and rotation angles (which you do) the matrix can be computed like this:
D3DMATRIX T,Ry,Rx;
D3DUtil_SetRotateXMatrix(Rx, RotX);
D3DUtil_SetRotateYMatrix(Ry, RotY);
D3DUtil_SetTranslateMatrix(T, PosX,PosY,PosZ);
D3DMATRIX WorldMtx;
D3DMath_MatrixMultiply(WorldMtx, Rx, Ry);
D3DMath_MatrixMultiply(WorldMtx, WorldMtx, T);
- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
It does not work as expected.
when the object is rotated it rotates around the origin and not around its axis.how do i fix this??
help!!!!!!!
when the object is rotated it rotates around the origin and not around its axis.how do i fix this??
help!!!!!!!
Raptor
You must rotate the object first then translate it. If you say it is rotated aroung world origin you have translated first and then rotated it.
The matrix computation should be done from scratch each time. If you do it as you do in your program where you multiply the old transform matrix with the new you will not get the expected transformation, and you will also get numerical errors that distorts your objects.
- WitchLord
The matrix computation should be done from scratch each time. If you do it as you do in your program where you multiply the old transform matrix with the new you will not get the expected transformation, and you will also get numerical errors that distorts your objects.
- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement