• 12
• 9
• 9
• 13
• 10

# HELP : d3d movement and FPS view [SOLveD]

This topic is 3290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im having problems getting my character like a FPS view. Before i solve that problem my camera doesnt seem to be operating properly The camera rotates fine but moving up and down seems to be a problem. To summarise, 1)the character doesnt seem to be position like a FPS view 2)the camera doesnt move backwards or forward properly. thanks for your time and co-operation.

D3DXVECTOR3 m_pos, m_rot;

void drawChar()
{

D3DXMATRIX view, rx, ry, rz, t, tm, mat;

D3DXMatrixRotationX(&rx, m_rot.x);
D3DXMatrixRotationY(&ry, m_rot.y);
D3DXMatrixRotationZ(&rz, m_rot.z);
D3DXMatrixTranslation(&t, m_pos.x, m_pos.y, m_pos.z);

D3DXMatrixTranslation(&view, 1, 1, -1.2f);   //1) calculate the offset of the view matrix

tm = rx * ry * rx * t;

mat = view * tm;                                //3) multiply 1 and 2 so camera is relative to the meshs position
D3DXMatrixInverse( &mat, NULL, &mat );  //4) invert the result and
d3ddev->SetTransform(D3DTS_VIEW, &mat); //5) set the matrix as the view

//--RENDER
for(DWORD n=0; n<numPlayerMaterials; n++)       //looping throught each subset
{
d3ddev->SetMaterial(&playerMaterial[n]);
if(texture6[n] !=NULL)
d3ddev->SetTexture(0, texture6[n]);     //set the material

meshPlayer->DrawSubset(n);              //render the mesh
}
//--RENDER
}

void keyMovement(HWND hWnd)
{

D3DXVECTOR3 k_vector(0.f,0.f,0.f);      //keyboard vector

if(keystate[DIK_UP] & 0x80)
{
k_vector = D3DXVECTOR3(0.0f,0.0f,1.0f);
m_pos.z += (k_vector.z * m_rot.y);
}
if(keystate[DIK_DOWN] & 0x80)
{
k_vector = D3DXVECTOR3(0.0f,0.0f,-1.0f);
m_pos.z -= (k_vector.z * m_rot.y);
}
if(keystate[DIK_RIGHT] & 0x80)
m_rot.y += camSpeed;
if(keystate[DIK_LEFT] & 0x80)
m_rot.y -= camSpeed;

if(keystate[DIK_ESCAPE] & 0x80)
PostMessage(hWnd, WM_DESTROY, 0, 0);
}


[Edited by - daanyaal on March 17, 2009 12:18:13 PM]

##### Share on other sites
Can you post a render of what you got on display

##### Share on other sites
ok for the starters the vector multiplication tm = rx * ry * rx * t; is not the right way to do vector. you need to study vector multiplication.
The structure of D3DVECTOR is defined as follows:
typedef struct D3DVECTOR {    float x;    float y;    float z;} D3DVECTOR, *LPD3DVECTOR;

Hence as you see you cannot multiply it for the party.

In this code you replace "*" with a function that follows:
D3DXMATRIX * D3DXMatrixMultiply(  D3DXMATRIX *pOut,  CONST D3DXMATRIX *pM1,  CONST D3DXMATRIX *pM2);

Also the code is better than what you did before. Actually the older code had a direct approach and you used floats directly but as I said there the translation indexed were wrong, anyway I think you should get it now.

##### Share on other sites
Cheers poeple. I got it to work now.

Basically i got rid of the 3 rotation matrix and replaced it one (MatrixRotationYawPitchRoll). then i carried out the following steps

1) made a vector3 (0,0,1) for the z component
2) made a rotation matrix as said earlier using m_rot (vector) values
3) transformed step 1) by the rotation matrix using transformCoord.
4) Finally took the transformed vector, multiplied it with the speed and increased the position vector by that.

peace.