• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# help me convert a third person camera in d3d11 to d3d9

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Anddos  Members

Posted 17 November 2012 - 08:30 AM

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(&amp;amp;amp;amp;amp;amp;yawPitchRollMat,-camPitch, camYaw, 0); //d3d9
camPosition = D3DXVec3TransformNormal(&amp;amp;amp;amp;amp;amp;DefaultForward,&amp;amp;amp;amp;amp;amp;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(&amp;amp;amp;amp;amp;amp;camPosition,&amp;amp;amp;amp;amp;amp;camPosition);
camPosition = ((*camPosition * charCamDist)) + camTarget;
camvec3 = camTarget - camPosition;
camForward = D3DXVec3Normalize(&amp;amp;amp;amp;amp;amp;camvec3,&amp;amp;amp;amp;amp;amp;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, 17 November 2012 - 08:43 AM.

### #2simpler  Members

Posted 17 November 2012 - 09:15 AM

You can change
[source lang="cpp"]camPosition = D3DXVec3TransformNormal(&amp;DefaultForward,&amp;DefaultForward, camRotationMatrix );[/source]
To
[source lang="cpp"]D3DXVec3TransformNormal(&amp;camPosition,&amp;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, 17 November 2012 - 09:19 AM.

### #3Anddos  Members

Posted 17 November 2012 - 10:40 AM

how would i do this line then

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

### #4simpler  Members

Posted 17 November 2012 - 10:52 AM

[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.

### #5Anddos  Members

Posted 17 November 2012 - 10:53 AM

so far i have

camTarget = charPosition;
camTarget.y = ((camTarget.y)+5.0f);
camRotationMatrix = D3DXMatrixRotationYawPitchRoll(&amp;amp;amp;amp;amp;yawPitchRollMat,-camPitch, camYaw, 0); //d3d9
D3DXVec3TransformNormal(&amp;amp;amp;amp;amp;camPosition,&amp;amp;amp;amp;amp;DefaultForward, camRotationMatrix );
D3DXVec3Normalize(&amp;amp;amp;amp;amp;camPosition,&amp;amp;amp;amp;amp;camPosition);
camPosition = ((camPosition * charCamDist)) + camTarget;
D3DXVec3Normalize((&amp;amp;amp;amp;amp;camForward),&amp;amp;amp;amp;amp;(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((&amp;amp;amp;amp;amp;camForward),&amp;amp;amp;amp;amp;(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, 17 November 2012 - 11:12 AM.

### #6Anddos  Members

Posted 18 November 2012 - 12:19 AM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.