Help with rotating camera.
I having problem rotating a camera in some cases.
I have an object on the screen.
the object is moving on the Z and the X axis.
I am using the camera to make my object allways on the center of the screen.
now , I want to have the ability to rotate the camera clockwise and counterclockwise and stay centered on my object. my rotation are only on the y axi.
I am using gluLookat to place the camera, but when I rotate the camera it seems like it losing the focus on the center. it is only work when the center is (0,0,0).
here is the code i am doing :
// moving to the place I want to draw my object.
glTranslate(xObject,yObject,zObject);
//Now I am drawing the object on xObj,yObj,zObj
DrawObject();
//moving the camera . the x,y,z is the distance minus the object
cordinations so i have a fix distance.
glLookAt(x,y,z,
xObject,yObject,zObject,
0,0,1);
glRotate(angle,0,1,0);
this is my code . I also tried to take the camera code and place it before drawing. the same results .
what should I do to rotate my camera and stay centered on my object in all places on the screen.
gluLookat(x,y,z);
thanks,
B00Zagl0
Use a bit of triganometry. As you move you''re camera around you''re world to make it move along its own x-axis you have to make it move the camera a number of units in the x - direction and z direction of the world. If you just Translate in one direction you''re camera will be moving along the axis of you''re world not you''re camera.
Hope this makes sense
Hope this makes sense
Thats what i thought to do . but doesnt open GL give me any way to do it by rotating ?
so what you meant is somthing like that :
x+=(sin(angle) * PI / 180) * radius;
y+=(cos(angle) * PI / 180) * radius;
gluLookAt(x,y,z,
XObj,YObj,ZObj,
0,0,1);
when the x,y,z is the distance from the center and the Xobj,Yobj,ZObj is the center ?
is that look fine ?
so what you meant is somthing like that :
x+=(sin(angle) * PI / 180) * radius;
y+=(cos(angle) * PI / 180) * radius;
gluLookAt(x,y,z,
XObj,YObj,ZObj,
0,0,1);
when the x,y,z is the distance from the center and the Xobj,Yobj,ZObj is the center ?
is that look fine ?
I just learned gluLookAt today and this is what I came up with
If you model is centered this will rotate around it perfectly
GLfloat piover180=blah blah blah;
GLfloat camera;
glLookAt(sin(camera*piover180)*40), 0.0, cos(camera*piover180)*40, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
camera-=0.01f;
If you model is centered this will rotate around it perfectly
GLfloat piover180=blah blah blah;
GLfloat camera;
glLookAt(sin(camera*piover180)*40), 0.0, cos(camera*piover180)*40, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
camera-=0.01f;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement