Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

B00Zagl0

Help with rotating camera.

This topic is 5732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!