# spherical camera movement

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

## Recommended Posts

hi,

im having trouble trying to simulate camera movement based on spherical coordinate. so it basically moved around the azimuth and altitude following this pattern

http://en.wikipedia.org/wiki/File:Coord_system_SZ_0.svg

i set a and d to increase and decrease the azimuth respectively. s and w to increase. the radius is constant 1. after i got the spherical coordinate, i change the spherical coordinate to cartesian corrdinate using this equation

http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates

and i simply set the lookat value using the cartesian i just got

gluLookAt (cameraCartesianPos.x, cameraCartesianPos.y, cameraCartesianPos.z,
cameraLookAt.x, cameraLookAt.y,cameraLookAt.z,
cameraUp.x, cameraUp.y, cameraUp.z);

the cameraLookat will always stay at 0, 0, 0. Im not sure about the up value and currently im using the value 0, 1, 0 (pointing up).

now im not sure how to describe the problem but it seems like the altitude does not behaving right. when im at azimuth 0, changes on altitude does not change anything. at azimuth 90 (perhaps) the altitude reach the max point (top of the hemisphere). Im not sure where i did wrong, the calculation seems right for me.

Any help on this one? or perhaps any info how to do a hemisphere to orbit the camera around the scene?

##### Share on other sites
There are various ways spherical coordinates can be converted to Cartesian coordinates; maybe you're using the wrong method given how your coordinate system is oriented.

If you need further help, perhaps you could post your spherical-to-Cartesian conversion code.

##### Share on other sites
hi,

for example i have a specific spherical coordinate(with constant radius 1), i convert it to cartesian using this code

double xOutput = x * getSinValue(y) * getCosValue(z);
double yOutput = x * getSinValue(y) * getSinValue(z);
double zOutput = x * getCosValue(y);

return Vector3D(xOutput, yOutput, zOutput);

getSinValue and getCosValue is a standard sin and cos function. The output value is then set into gluLookAt method

gluLookAt (cameraCartesianPos.x, cameraCartesianPos.y, cameraCartesianPos.z,
cameraLookAt.x, cameraLookAt.y,cameraLookAt.z,
cameraUp.x, cameraUp.y, cameraUp.z);

with CameraLookAt value 0, 0, 0. i think one of the problem is try to find out the up value (i set it to 0, 1, 0). But i think there are than that.

any hint?

##### Share on other sites
It looks like your conversion code considers Z to be up, but you want Y to be up. So, you'll (most likely) need to revise the conversion code accordingly.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634047
• Total Posts
3015231
×