Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a 3d flying game and using DXUTCamera for my view.

I can get the camera to take on the characters position, But I would like to view my character in the 3rd person.

Here is my code for first person view:

    //Put the camera on the object.                     

    D3DXVECTOR3 viewerPos;
    D3DXVECTOR3 lookAtThis;
    D3DXVECTOR3 up         ( 5.0f, 1.0f, 0.0f );
    D3DXVECTOR3 newUp;
    D3DXMATRIX matView;

    //Set the viewer's position to the position of the thing.

    viewerPos.x = character->x;   viewerPos.y = character->y;
    viewerPos.z = character->z;

    // Create a new vector for the direction for the viewer to look

    D3DXVECTOR3 newDir, lookAtPoint;
    D3DXVec3TransformCoord(&newDir, &character->initVecDir,

    // set lookatpoint

    D3DXVec3Normalize(&lookAtPoint, &newDir);
    lookAtPoint.x += viewerPos.x;
    lookAtPoint.y += viewerPos.y;
    lookAtPoint.z += viewerPos.z;

    g_Camera.SetViewParams(&viewerPos, &lookAtPoint);

So does anyone have an ideas how I can move the camera to the third person view? preferably timed so there is a smooth action in the camera movement. (I'm hoping I can just edit this code instead of bringing in another camera class)

share|improve this question
As an unrelated note, there is zero reason at all to use D3D10 instead of D3D11. Even if you have older hardware, D3D11 supports down-level hardware (even D3D9 hardware), but allows you to use the newer version of the API and tools. – Sean Middleditch Aug 18 '12 at 22:51

For those of you wanting code. Here's my solution

LookAtPoint is my static view position, and then I simply transform the coords to that of the objects world.

        D3DXVECTOR3 viewerPos;

        viewerPos.x = character->x;   viewerPos.y = character->y;
        viewerPos.z = character->z;

                D3DXVECTOR3 newDir, newDirNorm, lookAtPoint( 0.0f, 1.0f, 5.0f  );
                D3DXVec3TransformCoord(&newDir, &lookAtPoint,

    D3DXVec3Normalize(&newDirNorm, &newDir);

    D3DXVECTOR3             vecEye = newDir;
    D3DXVECTOR3             vecAt = viewerPos;

    g_Camera.SetViewParams ( &vecEye, &vecAt);

   // g_Camera.SetProjParams(D3DXToRadian (60.0f), 5.5, 0.5f, 100.0f);

    // Set the Camera parameters
    g_Camera.SetProjParams ( D3DX_PI/4, 5.5, 30.0f, 30.0f);
    g_Camera.SetResetCursorAfterMove ( true);

share|improve this answer

You can see third person camera implemented in MultiAnimation sample in DirectX SDK (June 2010):

MultiAnimation sample screenshot


It is static attached first person camera (static relative to person), not good for person, but sufficient for airplane plane.

Anyway, DXUT is full of bugs (reading uninitialised variables, for example), (i think) it is sufficient just for SDK samples, or rewrite it to stl compliant and run through static code analysis.

It is better to use XNAMath / DirectxMath instead (deprecated) D3DXMath.

share|improve this answer
Thank you, but that is a DirectX9 example. Anything in DX10? – David Aug 18 '12 at 18:14
It is only about computing position and rotation of camera (it uses CFirstPersonCamera internaly), thus this code should work in DX9/10/11, maybe that is why they are not in samples specifically for DX10 and DX11. – ErikEsTT Aug 18 '12 at 18:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.