Sphere Maths help for camera positioning

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fallingbrickwork
Posts: 52
Joined: Sun Jun 22, 2008 4:09 pm
Contact:

Sphere Maths help for camera positioning

Post by fallingbrickwork »

Hi all,

I have a sphere - it's actually a map of the world and I want to be able to rotate 360 around it (imagine going around the equator, hence X axis and Z axis)... for this I am using:

Code: Select all

campos.X = sin(deg_rads(m_cameraAngleX)) * m_cameraRadius;
campos.Z = cos(deg_rads(m_cameraAngleX)) * m_cameraRadius;
the above is working perfectly.

Now comes the prob.. I also want limited up and down movement... i'm going to limit this to above 45 degrees up and 45 degrees down, so I wont be worrying about gimbel lock... hence i thought i wouldnt need quaternions.

I thought i could somehow do the following and then combine the campos.Z data as this is needed for both rotation types with: (this is both rotations)

Code: Select all

campos.X = sin(deg_rads(m_cameraAngleX)) * m_cameraRadius;
		campos.Y = sin(deg_rads(m_cameraAngleY)) * m_cameraRadius;
		campos.Z = cos(deg_rads(m_cameraAngleX)) * m_cameraRadius;
		campos.Z += sin(deg_rads(m_cameraAngleY)) * m_cameraRadius;
But I'm getting a zooming in/out motion and weird positioning.... it actually looks quite good but not what i want.... can someone help with the above equations or give advise?? (BTW, I incrementing the angle variable with the keyboard)

Many thanks in advance....
Casus Belli - Realtime strategy war game
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You want to move the camera in a spherical coordinate system. I posted the necessary equations and some sample code a while back. You may find it useful.

Travis
fallingbrickwork
Posts: 52
Joined: Sun Jun 22, 2008 4:09 pm
Contact:

Post by fallingbrickwork »

Many many thanks, that *should do exactly what I'm after! :lol:
Casus Belli - Realtime strategy war game
Image
Post Reply