Third person camera help directx 9

Anddos 103 Apr 07, 2012 at 01:05

what i want todo is follow the model and direction of the camera so it follows it, ive got it working so it follows the positon but i cant get the direction right

D3DXVECTOR3 src(0.0f,0.0f,-1.0f);
    D3DXVECTOR3 r(1.0f,0.0f,0.0f);
    D3DXMATRIX mYaw;

    D3DXVECTOR3 vCharPos(0.0f,0.0f,mWalkForward);
    D3DXVECTOR3 vCharFacing(r.x,r.y,r.z);
    D3DXVECTOR3 vEye;
    D3DXMATRIX mxView;
    static float posy = 1.0f; //posy += 0.001f;

    vEye = D3DXVECTOR3( vCharPos.x,0.25f , vCharPos.z += +6.0f ); //0.25f
            D3DXVECTOR3 vAt  ( vCharPos.x, 0.125f, vCharPos.z ), //0.0125f
                vUp  ( 0.0f, 1.0f, 0.0f );
            vCharFacing.x *= .25; vCharFacing.y = 0.f; vCharFacing.z *= .25;
            vEye -= vCharFacing;
            vAt += vCharFacing;

            D3DXMatrixLookAtLH( &mxView, &vEye, &vAt, &vUp );
            d3ddev->SetTransform( D3DTS_VIEW, &mxView );

5 Replies

Please log in or register to post a reply.

kurlyak 101 Apr 07, 2012 at 10:27

Your code is wrong.

At first you must be create two class: CModel and CCamera.

Class CModel: controls the you 3D model (loading model, draw model, keyboard input);
Class CCamera: camera follows for model; to the position of the model you have to add the vector of camera position; must be distinguished two things: Model position and Camera position. In the class CCamera you must be get Model position from class CModel and add vector specifies the offset of the camera relative to the model. vector of model must look to where you turn a model of the keyboard. And vector of camera must look on the model.

In the class CModel you must be construct World Matrix for model and in the class CCamera you must be construct View Matrix for your model and whole your 3D world.

Its very simple. See my source code:

Anddos 103 Apr 07, 2012 at 17:48

Download not available
The following download is not available: 1.35 MB
kurlyak 101 Apr 15, 2012 at 12:41

So why I can download this link, and you do not? Can you even use the Internet? At first go to link, second do click on “Download”, and at the final click “Free download” and enjoy.

P.S. I often see your topics on the forum and I do not understand - you’re really stupid or pretending? Really not understand, sorry.

Anonymous Apr 16, 2012 at 07:39

Hi kurlyak, I would recommend against using classes.

How do you know if the OP likes OOP?

Try structs or open consideration for another next time outside your beliefs. Thank you.

20+ years of programming experience.

  • Mikey
Anddos 103 Apr 16, 2012 at 11:05

alright i manage to get the download to work in internet explorer, firefox wouldnt work for some reason , anyway this sample is wierd, there is a exe and src folder, i run the exe and see lara in third person but when i look at the src there is a first person camera?