'rotate the camera around an object in spherical coordinates glulookat
so i'm trying to rotate the camera around a cube object , using the keyboard arrows to change the y angle and the x angle , i want a result like this : this video
Well now I want to move the camera in a circular motion around the shape, so I used the sphere parametric equation to determine the camera's x, y, and z coordinates on the parameter of the sphere using the x angle and the y angle , this is the equation : sphere parametric equation
For this moment, the equation is as following:
x = radius*cos(y_angle)*cos(x_angle)
y = radius*cos(y_angle)*sin(x_angle)
z = radius*sin(y_angle)
so the code will be :
gluLookAt(x, y, z, 0, 0, 0, 0, 1, 0); // x,y and z that we calculated above
Now it is supposed to work without problems, but the camera dose rotate in a strange way that is not as it should, I think this has something to do with the up vector in the glulookat() function because i'm using a constant up vector like (0,1,0)
Anyway, I can't calculate the up vector correctly, so I want help in making a circular motion around the cube like the one that appeared in the video using the glulookat , i hope i made it clear ، Because as you have noticed, I can't explain well
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
