Original Post
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]