Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

pebben

Camera Problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi There Programmers! I have created a camera that looks at the player, like Tomb Raider you know. I use the D3DXMatrixLookAtLH function, and it works fine to look at the player, but the problem is that it doesn´t seem to move right? What is wrong in my code? Please take a look. D3DXMATRIX m_PlayerMatToWorld; m_PlayerMatToWorld = ((TransformNode*)g_GameManager->NodePlayer)->m_toWorld; //Get the Player´s Position. (Don´t care about the type casting) D3DXVECTOR3 vLookAt; vLookAt.x = m_PlayerMatToWorld(3,0); //a D3DXVECTOR3 with Player´s Position. vLookAt.y = m_PlayerMatToWorld(3,1); vLookAt.z = m_PlayerMatToWorld(3,2); D3DXVECTOR3 vMoveCamBack; //The Cam are placed some meters behind the player. D3DXVec3TransformNormal(&vMoveCamBack, &D3DXVECTOR3(0.0f, 40.f, -200.0f), &m_CameraMatToWorld); if (FirstTimeUpdateMatrices == true) //To Get A good starting points for the lerp function. { FinalPosLerpCamera = vMoveCamBack; FirstTimeUpdateMatrices = false; } else //Now the Nice camera lerp can start. { D3DXVECTOR3 vGoalPos; vGoalPos.x = vMoveCamBack.x; vGoalPos.y = vMoveCamBack.y; vGoalPos.z = vMoveCamBack.z; //GoalPos == The Place the camera is lerping to. D3DXVec3Lerp( &FinalPosLerpCamera, &FinalPosLerpCamera, &vGoalPos, 0.003 * elapsedMs); } D3DXMatrixLookAtLH(&m_matFromWorld, &FinalPosLerpCamera, &vLookAt, &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); //And Finally create the matrix. m_pDevice->SetTransform( D3DTS_VIEW, &m_matFromWorld ); /Have A Nice Day -Patrick [edited by - pebben on June 7, 2004 6:58:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
The translation is wrong, it doesn´t move along with the player. It´s just looking at the player.

Share this post


Link to post
Share on other sites
i don't know DirectX but it looks like you are moving the camera relative to the camera:


m_PlayerMatToWorld = ((TransformNode*)g_GameManager->NodePlayer)->m_toWorld; //Get the Player´s Position. (Don´t care about the type casting)


<snip...>

//notice that here you are doing something with m_CameraMatToWorld

//not with m_PlayerMatToWorld as you probably should be doing

D3DXVECTOR3 vMoveCamBack; //The Cam are placed some meters behind the player.

D3DXVec3TransformNormal(&vMoveCamBack, &D3DXVECTOR3(0.0f, 40.f, -200.0f), &m_CameraMatToWorld);


in other words you are never doing anything with vMoveCamBack to make it relative to the player position.

-me

[edited by - Palidine on June 7, 2004 7:20:08 PM]

Share this post


Link to post
Share on other sites
Thanx For your opinion, it solved my problem. But how could I miss it? (feel stupid) Here is the working code for anyone who wants to borrow it.

D3DXMATRIX m_PlayerMatToWorld;
m_PlayerMatToWorld = ((TransformNode*)g_GameManager->NodePlayer)->m_toWorld; //Get the Player´s Position. (Don´t care about the type casting)

D3DXVECTOR3 vLookAt;
vLookAt.x = m_PlayerMatToWorld(3,0); //a D3DXVECTOR3 with Player´s Position.
vLookAt.y = m_PlayerMatToWorld(3,1);
vLookAt.z = m_PlayerMatToWorld(3,2);

D3DXVECTOR3 vMoveCamBack; //The Cam are placed some meters behind the player.
D3DXVec3TransformCoord(&vMoveCamBack, &D3DXVECTOR3(0.0f, 40.f, -200.0f), &((TransformNode*)g_GameManager->NodePlayer)->m_Combined);

if (FirstTimeUpdateMatrices == true) //To Get A good starting points for the lerp function.
{
FinalPosLerpCamera = vMoveCamBack;
FirstTimeUpdateMatrices = false;
}
else //Now the Nice camera lerp can start.
{
D3DXVECTOR3 vGoalPos; vGoalPos.x = vMoveCamBack.x; vGoalPos.y = vMoveCamBack.y; vGoalPos.z = vMoveCamBack.z; //GoalPos == The Place the camera is lerping to.
D3DXVec3Lerp( &FinalPosLerpCamera, &FinalPosLerpCamera, &vGoalPos, 0.003 * elapsedMs);
}

D3DXMatrixLookAtLH(&m_matFromWorld, &FinalPosLerpCamera, &vLookAt, &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); //And Finally create the matrix.
D3DXMatrixInverse(&m_matToWorld, NULL, &m_matFromWorld);

m_object->VSetTransform(&m_matToWorld, &m_matFromWorld);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!