Camera issue

Started by
2 comments, last by Evil Steve 15 years, 3 months ago
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]
EnJOJ Gaming
Advertisement
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?
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]
EnJOJ Gaming
Quote:Original post by Johannes1991
So i should do like this
matTranslate 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.

This topic is closed to new replies.

Advertisement