Advertisement

Camera Position...

Started by April 02, 2001 07:29 PM
7 comments, last by jwblair 23 years, 7 months ago
My problem is this. I have a camera using gluLookAt() and I would like circle around position (0,0,0) on the xz plane at a fixed distance from the origin, with y being the up vector. Y would be a fixed height, lets say 10. And lets say that the radius of the circle in which my camera will rotate will be 20. As the camera rotates about the origin on the xz plane with a fixed radius 20 from the circle the x and z values change. How do I calculate those x and z values? Furthermore, I would like to use polar coordinates. For example, when the camera makes a half rotation, we are at 180 degrees. When a full rotation is accomplished we are at 360, then starting again at 0 for the next rotation. So I have gluLookAt(x,10,z, 0,0,0, 0,1,0); What about x and z? Any help would be greatly appreciated... Thanks! John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
since you''re having your camera rotating about the origin, you could consider your Camera Position as a vector.

Select a starting point for your camera: (0,10,20) // So that the camera will start rotating 20 units from the x-axis and then try looking up ''Vector rotations about the y-axis'' on google.com for the rotation equations. Then simply get the new Camera position from the equation by passing the original point (0,10,20) and the number of radians through it, and update the camera''s new co-ords.
Advertisement
Use sin and cos to calculate the x and z variables:

if you know the angle of rotation (0<theta<360) around the y axis then

x = radius * cos(theta);
z = radius * sin(theta);

I haven''t checked this so they may be the wrong way round and you might have to play with the signs.

IMPORTANT: if you use sin and cos from math.h you need to give the angle in radians

theta_rad = (2*pi/360) * theta_deg;

-DeVore
Thanks..to both of you... I will try that and get back to you!

Thanks!

John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
gluLookAt(
(r*cos(a*piover180)),
0,
r*sin(a*piover180),
-cos(a*piover180), //with out it, it doesn''t work
0,
-sin(a*piover180), //with out it, it doesn''t work
0,1,0);

float piover180 = 0.0174532925f
a - angle
r - radius of circle
Why are you chaning the look at position? I just want that position to stay stationary as I rotate about it....?



Thanks!

John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html
Advertisement
you can use
glRotatef(angle,x,y,z);

cos and sin but for targetpos
gluLookAt(1,1,1,
0,0,0, // target pos
0,1,0);
you can use
glRotatef(angle,x,y,z);

or

cos and sin but for targetpos
gluLookAt(1,1,1,
0,0,0, // target pos
0,1,0);
Understand that...but you had cos and sin in the target position too. I am just curious as to why...

Thanks!

John William Blair
Thanks!John William Blair "The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of the darkness. For he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee."
http://members.home.com/chucklez/wtc/index.html

This topic is closed to new replies.

Advertisement