#102279 - Uncle Vig - Tue Sep 12, 2006 3:41 pm
Hello,
I'm looking for a way to get the camera angle when a look at is being used. I'm quite new to 3d/Ds development, and I wonder If it's possible to get these datas (maybe using the projection matrix).
Thanks in advance.
#102283 - hellfire - Tue Sep 12, 2006 5:00 pm
Quote: |
a way to get the camera angle |
and what "angle" exactly are you looking for ? :)
_________________
"The three chief virtues of a programmer are: Laziness, Impatience and Hubris"
#102291 - Uncle Vig - Tue Sep 12, 2006 6:05 pm
Angles between eye and lookat positions , on each axis :D.
#102293 - sajiimori - Tue Sep 12, 2006 6:20 pm
Going from a matrix to angles is slow and awkward, not to mention ambiguous (because you can generally represent a single rotation matrix with a variety of Euler angle triples).
If you already have your position and look-at points, you can derive yaw and pitch from those easily. However, that's not enough information to get roll -- you can stand at one point, look at another point, and tilt your head to the left or right without disturbing either point.
So, what information do you have to work with?
#102296 - Uncle Vig - Tue Sep 12, 2006 6:31 pm
Only eye and lookat positions, and I Hope you can help me anyway :).
#102299 - sajiimori - Tue Sep 12, 2006 7:17 pm
Sure. Take the vector from the eye to the lookat, and get its yaw and pitch this way:
Code: |
Angle Vector3::yaw() const
{
return atan2(x, z);
}
Angle Vector3::pitch() const
{
return -atan2(y, Vector2(x, z).length());
}
|
Put these on a post-it and stick it to your monitor:
Zero yaw and zero pitch points along positive Z.
Positive yaw goes counterclockwise when looking down negative Y. It is to the left from a first-person view.
Positive pitch goes counterclockwise when looking down negative X. It is downward from a first-person view.
#102302 - Uncle Vig - Tue Sep 12, 2006 7:38 pm
It works,
I've tried so many things using cos, sin, cross and dot product, and it's so simple, but it's always like this when you have the answer...
thanks a lot :D.
Edit : just a question, what about the "roll" you're talking about. Is it necessary for a lookat camera type ? (I mean just follow a position in space like a security cam).
#102339 - sajiimori - Wed Sep 13, 2006 1:49 am
Most FPS games don't let you roll the camera, just because it's not needed for normal gameplay. Doing a barrel roll in a flight sim rotates the camera by 360 degrees.
#102374 - Uncle Vig - Wed Sep 13, 2006 10:36 am
I see now, thanks :D.