David Sigley
David Sigley

Reputation: 1198

DirectX Camera positioning (Third Person View)

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 core 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

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

        // 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)

Upvotes: 0

Views: 1117

Answers (1)

elelec
elelec

Reputation: 11

Well, I believe I can help you in theory to change from a first person view to a third person. I'm sorry I can't give you the actual code, but I'm typing from a phone. You will have to put the point where your view starts slighty behind the player and make the lookAtPoint to look at the player. Also, be sure to make the , x , y and z to move according to the third person's logic. Hope that helps. I'm sorry if it doesn't help at all, but typing from a phone is kinda hard for me, and I can't explain it really good.

Upvotes: 1

Related Questions