Public Group

# Camera issue

This topic is 3633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I cant get my camera to rotate along the player in a certain radius and in the same direction. someine got a god equation? using directX and c++ Thanks in advance [Edited by - Johannes1991 on January 6, 2009 1:49:57 PM]

##### Share on other sites
It sounds like you're building a third-person game of some sort and want to have the camera follow the player at some distance above and behind him, and face in the same direction as the player?

Let's say you define +Y as up, +X as right, and +Z as the direction the camera faces. What you want to do is find out a couple of points relative to the player's position.

To do this, you'll need the player's World transformation matrix. The player's World transformation is what you would use to move the player's avatar from the origin to its actual location and orientation in the game world's space.

To find a point above and behind the player (the camera's actual location), you'd take a vector like (0, 10, -20) and multiply it by the player's World matrix. Then you'll want to find the point the camera is pointing at by taking a vector like (0, 0, 100) and multiplying it by the player's World matrix. The last vector you need to produce a camera matrix is an "up" vector. For this, if you're working with a human on the ground, you can almost always just use (0,1,0).

From there, DirectX has a utility function to produce a View matrix from vectors Camera, Target, and Up.

Is that what you were looking for?

##### Share on other sites
So i should do like this
matTranslate is the players position matrix
(0,10,20)*matTranslate

can someone write an example?

[Edited by - Johannes1991 on January 7, 2009 9:01:28 AM]

##### Share on other sites
Quote:
 Original post by Johannes1991So i should do like thismatTranslate is the players position matrix(0,10,20)*matTranslate
You need the players full matrix, not just position. otherwise all that will do is move the point (0, 10, 20) relative to the player's position, not their orientation.

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633762
• Total Posts
3013727
×