Camera Problems..
I am using gluLookAt(). Right now I have my camera rotating about the y axis with a radius of 7 on the XZ plane in a perfect circle using sin and cos. I''ve converted my degrees to radians so that I can use the math.h library. Now also want to rotate my camera about the YZ axis as well. But I have no clue on how to do that. In othwer words I want to rotate my camera around the pt 0,0,0 in a perfect sphere along the xz and yz planes. How can this be done?
Any help would be great!
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
http://members.home.com/chucklez/wtc/index.html
April 13, 2001 01:07 PM
Well, If i am assuming correctly (on how you did it), you''d do that like so:
struct Vertex
{
float x,y,z;
};
float Radius = 7;
Vertex Camera = {0,0,Radius}; //Nothing here .
float CameraXZ=1, CameraYZ=1; //Angle to rotate each time!
void RotateCamera(void)
{
float Temp;
//Rotate around y (XZ)
Temp = Camera.x;
Camera.x = Temp*cos(CameraXZ*3.1415/180) - Camera.z*sin(CameraXZ*3.1415/180);
Camera.z = Temp*sin(CameraXZ*3.1415/180) + Camera.z*cos(CameraXZ*3.1415/180);
//Rotate around x (YZ)
Temp = Camera.y;
Camera.y = Temp*cos(CameraXZ*3.1415/180) - Camera.z*sin(CameraYZ*3.1415/180);
Camera.y = Temp*sin(CameraXZ*3.1415/180) + Camera.z*cos(CameraYZ*3.1415/180);
}
void Idle(void) //Assuming this is your Idle function..
{
RotateCamera();
gluLookAt(Camera.x, Camera.y, Camera.z,0,0,0,0,1,0);
}
struct Vertex
{
float x,y,z;
};
float Radius = 7;
Vertex Camera = {0,0,Radius}; //Nothing here .
float CameraXZ=1, CameraYZ=1; //Angle to rotate each time!
void RotateCamera(void)
{
float Temp;
//Rotate around y (XZ)
Temp = Camera.x;
Camera.x = Temp*cos(CameraXZ*3.1415/180) - Camera.z*sin(CameraXZ*3.1415/180);
Camera.z = Temp*sin(CameraXZ*3.1415/180) + Camera.z*cos(CameraXZ*3.1415/180);
//Rotate around x (YZ)
Temp = Camera.y;
Camera.y = Temp*cos(CameraXZ*3.1415/180) - Camera.z*sin(CameraYZ*3.1415/180);
Camera.y = Temp*sin(CameraXZ*3.1415/180) + Camera.z*cos(CameraYZ*3.1415/180);
}
void Idle(void) //Assuming this is your Idle function..
{
RotateCamera();
gluLookAt(Camera.x, Camera.y, Camera.z,0,0,0,0,1,0);
}
Hello
That''s a question I''m figthing with for some time now.
One way is simple. Think about a sphere coordinate system (don''t know if it is called in the english language this way too, I''m thinking about a coordinate system where the position is described through two angle (call theta and phi) and the distance frome the center of the sphere). Radius isn''t important because it''s constant. Now the user can change these angles with four keys (increase and decrease theta and phi). You can transform these spherical coordinates into cartesian (normal) ones with the following formulars:
x = r*cos(theta)*sin(phi)
y = r*sin(theta)
z = r*cos(theta)*cos(phi)
and in the other direction:
r = sqrt(sqr(x)*sqr(y)*sqr(z))
tan(phi) = x/z
tan(theta) = z/sqrt(sqr(z)+sqr(x))
here r is radius
phi is the angle that lies in the xz plane (plane with y==0)
phi is is if you look from the top positive in the counterclockwise direction
theta is the angle that goes from the xz plane up (positive) and down (negative)
the cartesian axes are the following:
z points "out of the monitor"
x points from left to right
y points from bottom to top
(that''s standard in OpenGL)
Try to paint this, it''s difficult to explain. Hope you get the point, if not mail me, and I''ll send you a picture.
With these formulas it is easy to calculate the eye point for gluLookAt(), a problem is calculating the up vector. I''ve not found a good way until now. You can''t leave it like it was ( (0,1,0) I guess ), because this will definitely crash if theta is 90 degrees.
Another problem with this is called the gimbal lock. Imagine the situation of having theta at 90 degrees. Now every change of phi would not have a result.
This can be solved by using quaternion. But until now I haven''t understand this. So I can''t explain. Try to search the web for this (e.g. gamedev.net).
In order to understand you will definitely need some vector and matrix maths.
Greetings Ben
That''s a question I''m figthing with for some time now.
One way is simple. Think about a sphere coordinate system (don''t know if it is called in the english language this way too, I''m thinking about a coordinate system where the position is described through two angle (call theta and phi) and the distance frome the center of the sphere). Radius isn''t important because it''s constant. Now the user can change these angles with four keys (increase and decrease theta and phi). You can transform these spherical coordinates into cartesian (normal) ones with the following formulars:
x = r*cos(theta)*sin(phi)
y = r*sin(theta)
z = r*cos(theta)*cos(phi)
and in the other direction:
r = sqrt(sqr(x)*sqr(y)*sqr(z))
tan(phi) = x/z
tan(theta) = z/sqrt(sqr(z)+sqr(x))
here r is radius
phi is the angle that lies in the xz plane (plane with y==0)
phi is is if you look from the top positive in the counterclockwise direction
theta is the angle that goes from the xz plane up (positive) and down (negative)
the cartesian axes are the following:
z points "out of the monitor"
x points from left to right
y points from bottom to top
(that''s standard in OpenGL)
Try to paint this, it''s difficult to explain. Hope you get the point, if not mail me, and I''ll send you a picture.
With these formulas it is easy to calculate the eye point for gluLookAt(), a problem is calculating the up vector. I''ve not found a good way until now. You can''t leave it like it was ( (0,1,0) I guess ), because this will definitely crash if theta is 90 degrees.
Another problem with this is called the gimbal lock. Imagine the situation of having theta at 90 degrees. Now every change of phi would not have a result.
This can be solved by using quaternion. But until now I haven''t understand this. So I can''t explain. Try to search the web for this (e.g. gamedev.net).
In order to understand you will definitely need some vector and matrix maths.
Greetings Ben
Thanks...but this is how I have set it up...
radius = 7;
radian = (2*pi/360)*theta;
//Conversion of degrees in to radians
X_POSITION = radius*cos(radian);
Z_POSITION = radius*sin(radian);
Camera(X_POSITION,Y_POSITION,Z_POSITION,0,0,0,0,1,0);
So what about the Y_POSITION?
I will look at what you gave me to see what I can do to fix it. Howver, if you have any suggestions - that would be great!
Thanks!
John William Blair
radius = 7;
radian = (2*pi/360)*theta;
//Conversion of degrees in to radians
X_POSITION = radius*cos(radian);
Z_POSITION = radius*sin(radian);
Camera(X_POSITION,Y_POSITION,Z_POSITION,0,0,0,0,1,0);
So what about the Y_POSITION?
I will look at what you gave me to see what I can do to fix it. Howver, if you have any suggestions - that would be great!
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
http://members.home.com/chucklez/wtc/index.html
Ben_ , i put my own camera class together sometime ago but my trig sux so it has some flaws. yours looks alot better
but i don''t exactly get this line
"phi is is if you look from the top positive in the counterclockwise direction"
thuned
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
but i don''t exactly get this line
"phi is is if you look from the top positive in the counterclockwise direction"
thuned
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
oh yeah, and with ur system, how would u go forward and backwards along those 2 angles?
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
phi is an angle, and with this line I only wanted to clear in which direction you have to use the positive angle.
So if you look at the coordinate system from the top (means looking in the direction of the negative y-axe), then you have to use a positive angle if you want to move your camera counterclockwise. Hope you get it, else I will mail a graphic.
With the other point your hitting a weak point of the system.
Mathematically it''s easy. You can access the whole space with a sphere coordinate system. Moving towards the center, and away from it is done with the value of r (if this was the point of your question, just increase r to zoom out, and decrease it to zoom in).
What I didn''t find a solution for is, how to set up the up vector correctly (it will be easy, if it isn''t important what should be seen up, and what down, simply choose a vector that is perpendicular on the vector from position to center of sphere).
For working with the angles it is the easiest way to store them and r in addition to the current position, and recalc the position whenever the angles or r change.
So if you look at the coordinate system from the top (means looking in the direction of the negative y-axe), then you have to use a positive angle if you want to move your camera counterclockwise. Hope you get it, else I will mail a graphic.
With the other point your hitting a weak point of the system.
Mathematically it''s easy. You can access the whole space with a sphere coordinate system. Moving towards the center, and away from it is done with the value of r (if this was the point of your question, just increase r to zoom out, and decrease it to zoom in).
What I didn''t find a solution for is, how to set up the up vector correctly (it will be easy, if it isn''t important what should be seen up, and what down, simply choose a vector that is perpendicular on the vector from position to center of sphere).
For working with the angles it is the easiest way to store them and r in addition to the current position, and recalc the position whenever the angles or r change.
Got it!
Thanks man!
Thanks man!
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
http://members.home.com/chucklez/wtc/index.html
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement