Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# Is there a good tutorial about doing a third person camera class in direct3d?

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

Greetings, I was wondering if there is good tutorial about doing a third person camera class in direct3d? I am not sure how to have a camera and a player''s movement match, and work together. I was just wondering if there was a place I could start to learn about this. I am not sure where to begin, I have a basic world created, and a model that I can move around. But now I don''t know how I can link the camera to the player''s movement. Any suggestions, on where to begin would be great! Thanks in advance.

#### Share this post

##### Share on other sites
Advertisement
I''m not very familiar with this but I think you can just have your characters coords equal to your camera view coords and then move both camera position and view forward when moving forward and to rotate or turn, just move the camera position around the view.

#### Share this post

##### Share on other sites
Here''s a quick start. You''ll need to do a little bit of vector mathematics. You need to store your camera position as an offset from the character (ie a vector). How you decide which way this vector points is up to you really. If your character has a front then you might want to have the offset as:

vector(-subjectLookVector.x * dist, worldHeight, -subjectLookVector.z * dist)

This will let you alter ''dist'' to make the camera be further away from the subject, or closer. Here I have not use the subject look vector for the up component as you will probably want this in world space to stop the camera going really high, or underground when the subect looks up or down (though you might want to factor it in a little bit later on if you feel like it).

So, to get the camera position every frame, you just use:

  vector cameraPos = subjectPos + cameraOffset;

This means that the camera will now follow along behind the subject. One thing you will notice with this is that the camera is very jerky because of the way the character moves. You will also need to apply position damping (smoothing).

Do a search on "camera smoothing" or something like that. I was part of a discussion on this a month or two ago.

If you''ve got any questions I''ll be happy to answer them,

Rory.

#### Share this post

##### Share on other sites
Use 3 points: Position of camera, look at point for camera, and up vector (0,1,0).

D3DXMatrixLookAtLH
The D3DXMatrixLookAtLH function builds a left-handed, look-at matrix.

D3DXMATRIX* D3DXMatrixLookAtLH(
D3DXMATRIX* pOut,
const D3DXVECTOR3* pEye,
const D3DXVECTOR3* pAt,
const D3DXVECTOR3* pUp
);
Parameters
pOut
A pointer to the D3DXMATRIX structure that is the result of the operation.
pEye
A pointer to the D3DXVECTOR3 structure that defines the eye point. This value is used in translation.
pAt
A pointer to the D3DXVECTOR3 structure that defines the camera look-at target.
pUp
A pointer to the D3DXVECTOR3 structure that defines the current world''s up, usually [0, 1, 0].
Return Values
A pointer to a D3DXMATRIX structure that is a left-handed, look-at matrix.

Remarks
The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixLookAtLH function can be used as a parameter for another function.

Requirements
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Windows CE: Unsupported.
Version: Requires DirectX 7.0.
Header: Declared in d3dxmath.h.
Library: Use d3dx.lib.

See Also
D3DXMatrixLookAt

#### Share this post

##### Share on other sites

There is an opengl based 3rd person camera tutorial here (look in the articles) - if you can get past the opengl portion it has all of the necessary equations and such for you to get a robust camera, I have used it''s techniques as the base for my 3pc and it has turned out great.

#### Share this post

##### Share on other sites
Thanks to all who posted an answer!
I will definately be trying your suggestions.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5
• Advertisement

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632913
• Total Posts
3009189
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!