camera rotation on a planet

Posted By: Matt_Aufderheide

camera rotation on a planet - 06/05/11 14:54

I'm making a game with spherical terrain. So obviously, when walking on this terrain you can't use standard movement and camera code because the down vector is always pointing to the center of the planet relative to your position on the surface.

It's trivial to calculate the "down" vector: just normalize(position.xyz)...and of course simply aligning a model to this is also easy...vec_to_angle(my.pan,downvector).

The problem comes when trying to do this for a camera...when you align a camera angle to the planet surface, pan and tilt can't be used like when the surface is flat.

So does anyone understand the math for this?
Posted By: Joey

Re: camera rotation on a planet - 06/05/11 16:30

in principle I'd calculate the normal the camera is pointing to behind the scenes in flat space and then do a coordinate transformation to spherical polar coordinates. The thing is, when you set up the transformation matrix J(phi, theta) (and you know phi and theta from the normal you just calculated in your last post), you simply multiply the camera normal with J and get the vector in spherical coordinates. Then, after that, you have to extract pan, tilt and roll from this vector. The transformation (pan, tilt, roll) <--> (nx, ny, nz) can be found everywhere and since it is in flat space I guess you even know how to do it.

for the coordinate transformation jacobian - see here:
http://en.wikipedia.org/wiki/List_of_canonical_coordinate_transformations
take the inverse of the "To Cartesian coordinates-From spherical coordinates" thingy.
Posted By: Matt_Aufderheide

Re: camera rotation on a planet - 06/05/11 18:36

Thanks, but I'm not understanding this very well..

1) you calculate a direction vector for the new direction assuming the camera is in flat space.

2) set up what kind of matrix ....what is "J" here?

3) I dont know much trig so what is phi and theta in relation to a normal?

... the rest i don't even begin to understand..

I guess i was hoping this was a common problem with a standard solution in c_script.
Posted By: rojart

Re: camera rotation on a planet - 06/05/11 19:09

You've already tried with camera.c script library?
Posted By: Pappenheimer

Re: camera rotation on a planet - 06/05/11 20:14

There is indead an instruction for those problems, and JulzMighty already programed something in this direction.
Here is the instruction from the manual:
http://www.conitec.net/beta/ang_for_axis.htm
Posted By: Matt_Aufderheide

Re: camera rotation on a planet - 06/06/11 12:41

Ok, that function works perfectly.. thanks a lot
© 2024 lite-C Forums