PDA

View Full Version : CameraPitch: How to use it?

B_old
10-16-2002, 09:37 AM
Hello.
I am trying to implent a simple camera in my project and I am having some problems with the code. Actually for quite a while now, so I am almost desperate for help. http://www.opengl.org/discussion_boards/ubb/smile.gif
Thanks for the time.
(Heading should be called Yaw I guessed)

gluLookAt(Camera.PosX,
Camera.PosY,
Camera.PosZ,
Camera.DirX,
Camera.DirY,
Camera.DirZ,
0.0, 1.0, 0.0);
//The above is in the Drawing code and not the problem actually

//Ok, that works fine.

DirY = PosY + PitchSin;
//That works semifine.

The Pitch-part is the problem.
When the value starts getting close 90
the camera starts pointing downwards again.
I know that makes sense and I tried lots of
different approaches using PitchCos and so
on... Sometimes the camera will just point
in the reversed direction.
I don't understand it.
Should this not be working:
DirY = PosY + PitchCos;
DirZ = PosZ + PitchSin;
?
I hope you have some advice. It is very appreciated.

[This message has been edited by B_old (edited 10-16-2002).]

dunken69
10-16-2002, 12:21 PM
I think I had the same problem recently. Then I found out that it is quite important how you set the up-vector of the camera (the last 3 floats). That is the vector that goes perpendicular (more or less) to the upper part of the "camera". When the angle between the up-vector and the directional-vector became >=180 (or 0, I suppose), the camera would behave strangely.
So, whenever I look more or less down the z- or x-axis, (0, 1, 0) is fine for the up-vector. But if I look down the Y-axis, I had to change the up-vector to (0, 0, -1). Now the camera top is pointing down the negative z-axis. I hope that helped.

Dunken

[This message has been edited by dunken69 (edited 10-16-2002).]

dunken69
10-16-2002, 12:24 PM
I think I had the same problem recently. Then I found out that it is quite important how you set the up-vector of the camera (the last 3 floats). That is the vector that goes perpendicular (more or less) to the upper part of the "camera". When the angle between the up-vector and the directional-vector became >=180 (or 0, I suppose), the camera would behave strangely.
So, whenever I look more or less down the z- or x-axis (0, 1, 0) is fien for the up-vector. But if I look down the Y-axis, I had to change the up-vector to (0, 0, -1). Now the camera top is pointing down the negative z-axis. I hope that helped.

Dunken

lgnnn
10-16-2002, 11:55 PM
i think that gluLookAt is to generate the matrix indicating how the world projects in the camera!
for example
gluLookAt(
GLdouble eyex,
GLdouble eyey,
GLdouble eyez,
GLdouble centerx,
GLdouble centery,
GLdouble centerz,
GLdouble upx,
GLdouble upy,
GLdouble upz
); according it we can get the camera's coordinates orientation in the world coordinate
zaxis = normal(center - eye)
xaxis = normal(cross(up, zaxis))
yaxis = cross(zaxis, xaxis)
then we can get the projection matrix from two coordinate

B_old
10-17-2002, 02:33 AM
Dunken:
So do you have some formula to calculate the approperiate occasion to change the last 3 values of the camera?
I am really wondering why it is not working the way I think of it, though. Makes no sense to me.
Thanks for the tip!

Ignn:
I now nothing about matrixes yet so honestly I don't understand what you are talking about. My approach is working perfectly as long I only 'turn' the camera.
Looking up/down works to as long it's only about 80° from the orgin. Strange huh?