Jump to content
  • Advertisement
Sign in to follow this  
Anddos

help me convert a third person camera in d3d11 to d3d9

This topic is 2213 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

I have found a nice example for a third person such like you see in the grand theft auto games, its in d3d11 but i want to convert it to d3d9 , i dont feel i know enough for d3d11 yet so i want to stay at d3d9 and implement this code

here is the directx 11 code

void UpdateCamera()
{
//d3d11 code
camTarget = charPosition;
camTarget = XMVectorSetY(camTarget, XMVectorGetY(camTarget)+5.0f);
camRotationMatrix = XMMatrixRotationRollPitchYaw(camPitch, camYaw, 0);
camPosition = XMVector3TransformNormal(DefaultForward, camRotationMatrix );
camPosition = XMVector3Normalize(camPosition);
camPosition = (camPosition * charCamDist) + camTarget;
camForward = XMVector3Normalize(camTarget - camPosition); // Get forward vector based on target
camForward = XMVectorSetY(camForward, 0.0f); // set forwards y component to 0 so it lays only on
camForward = XMVector3Normalize(camForward);
camRight = XMVectorSet(-XMVectorGetZ(camForward), 0.0f, XMVectorGetX(camForward), 0.0f);
camUp =XMVector3Normalize(XMVector3Cross(XMVector3Normalize(camPosition - camTarget), camRight));
camView = XMMatrixLookAtLH( camPosition, camTarget, camUp );
}


here is my attempt with d3d9


void UpdateCamera()
{

camTarget = charPosition;
camTarget.y = ((camTarget.y)+5.0f);
camRotationMatrix = D3DXMatrixRotationYawPitchRoll(&yawPitchRollMat,-camPitch, camYaw, 0); //d3d9
camPosition = D3DXVec3TransformNormal(&DefaultForward,&DefaultForward, camRotationMatrix );
//so far i am stuck on this line, because camPosition should be D3DXVECTOR3* but if i set it to that, then the code below is broken , please can anyone help with coverting this to work with d3d9.



camPosition = D3DXVec3Normalize(&camPosition,&camPosition);
camPosition = ((*camPosition * charCamDist)) + camTarget;
camvec3 = camTarget - camPosition;
camForward = D3DXVec3Normalize(&camvec3,&camvec3); // Get forward vector based on target
camForward = XMVectorSetY(camForward, 0.0f); // set forwards y component to 0 so it lays only on
camForward = XMVector3Normalize(camForward);
camRight = XMVectorSet(-XMVectorGetZ(camForward), 0.0f, XMVectorGetX(camForward), 0.0f);
camUp =XMVector3Normalize(XMVector3Cross(XMVector3Normalize(camPosition - camTarget), camRight));
camView = D3DXMatrixLookAtLH( camPosition, camTarget, camUp );
*/

}


here is a picture of the d3d11 app

http://imageshack.us/f/5/thirdpersoncam.jpg Edited by Anddos

Share this post


Link to post
Share on other sites
Advertisement
You can change
[source lang="cpp"]camPosition = D3DXVec3TransformNormal(&DefaultForward,&DefaultForward, camRotationMatrix );[/source]
To
[source lang="cpp"]D3DXVec3TransformNormal(&camPosition,&DefaultForward, camRotationMatrix );[/source]
Since the first argument gets set to the result of the operation as well. Now camPosition don't have to be a pointer any more. Edited by simpler

Share this post


Link to post
Share on other sites
how would i do this line then

camForward = XMVector3Normalize(camTarget - camPosition); // Get forward vector based on target

Share this post


Link to post
Share on other sites
[source lang="cpp"]D3DXVec3Normalize(&camForward, &(camTarget - camPosition));[/source]

I recommend taking a look at this page to see the DirectXMath counterpart for all D3DXMath functions.

Share this post


Link to post
Share on other sites
so far i have


camTarget = charPosition;
camTarget.y = ((camTarget.y)+5.0f);
camRotationMatrix = D3DXMatrixRotationYawPitchRoll(&yawPitchRollMat,-camPitch, camYaw, 0); //d3d9
D3DXVec3TransformNormal(&camPosition,&DefaultForward, camRotationMatrix );
D3DXVec3Normalize(&camPosition,&camPosition);
camPosition = ((camPosition * charCamDist)) + camTarget;
D3DXVec3Normalize((&camForward),&(camTarget - camPosition)); // Get forward vector based on target

camForward.y = camForward.y = 0.0f; // set forwards y component to 0 so it lays only on
D3DXVec3Normalize((&camForward),&(camForward));



now i am stuck

would this be

camRight = XMVectorSet(-XMVectorGetZ(camForward), 0.0f, XMVectorGetX(camForward), 0.0f);

camRight.z = -camForward.z,
camRight.y = 0.0f,
camRight.z = camForward.x Edited by Anddos

Share this post


Link to post
Share on other sites
i cannot for the life of me get this line right

//camUp =XMVector3Normalize(XMVector3Cross(XMVector3Normalize(camPosition - camTarget), camRight)); //d3d11

D3DXVec3Normalize(&camUp,D3DXVec3Cross(D3DXVec3Normalize(&(camPosition - camTarget), &camRight))); //d3d9

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!