Camera, Spheres, Headaches..

  • Follow


Hi,

I've posted before but failed miserably to explain myself very well
and hope that somebody can come to my rescue with some suggestions..

I have some data loaded that sits on the side of a sphere, however I
want to view it as if I was standing on the sphere and the data was
upright (eg. Buildings on a planet!).

Now.. I have written a 6dof camera (with much help from you guys!)
that gives me complete freedom to move around my scene. However
because it is completely free I get no coupling in the movements..eg.
If I look up.. rotate right... look down.. the horizon is now no
longer level... good for a flight sim.. not so good for a FPS.

The 6dof rotations are stored in a 4x4 matrix which I multiply into
the view.

What I would like to do is have an option to "lock" the horizon so
that as I move around the sphere it is always level. E.g. I have the
ability to walk on the surface of the planet.

I have the ability to get the UpVector by using the coordinates of my
position and the "planet" centre. This gives me my level horizon.

However I can not find a good way of using this upVector with my 6dof
Matrix so that I can "lock" the horizon.

Currently I load the data and do a gluLookAt to get myself level.. but
from then on all my rotations are done with the matrix and mulitplied
into the model view.. and then I get the horizon movement I want to
eliminate.

Help!.. Basically I want the option to switch between a Flight Sim
camera and a FPS camera using my matrix.. effectively disabling any
roll elements that could corrupt the horizon.. The way I see by doing
this is locking my UpVector.. but I can't see how to do this with the
4x4 rotation matrix that I have...

Cheers

Mark

0
Reply mark.christyuk (6) 7/4/2007 10:38:55 AM

 > Help!.. Basically I want the option to switch between a Flight Sim
 > camera and a FPS camera using my matrix.. effectively disabling any
 > roll elements that could corrupt the horizon.. The way I see by doing
 > this is locking my UpVector.. but I can't see how to do this with the
 > 4x4 rotation matrix that I have...

Maybe you could switch to a different camera model when you're on the 
planet? i.e just store rotation as a bearing and elevation.

0
Reply Jonno 7/4/2007 12:52:29 PM


Hi Jonno,

I've been round several experiments but nothing seems to work...
obviously I'm doing something wrong but for the life of me I can't get
my head around it.

I thought about switching to a simple glRotatef type camera once I'm
on the planet as then I don't have to worry about Gimbal lock as my
movements are limited.... however when I do that very weird rotations
happen.. probably because of the matrix that is currently loaded in
the scene from my previous 6dof camera.

I keep saying to myself that there has to be a way to get rid of the
UpVector change when I pitch my view up and down.. I seem to have the
opposite of most people whom want to get rid of the one effect I want!

Cheers

Mark


0
Reply mchristyuk 7/4/2007 1:36:47 PM

On Jul 4, 12:38 pm, mchristyuk <mark.christ...@gmail.com> wrote:
>
> What I would like to do is have an option to "lock" the horizon so
> that as I move around the sphere it is always level. E.g. I have the
> ability to walk on the surface of the planet.
>

This is a situation where Euler angles actually work
nicely.

Store your position on the sphere, then "pitch" and
"heading" in two separate vars. Pitch and Heading
will be easy to manipulate.

Now all you need to do is turn the numbers into
a matrix. This is easy with glRotate(), etc.


--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.


0
Reply fungus 7/4/2007 8:59:25 PM

Hi Fungus,

This is what I thought.. however when I try to use glRotate after
setting up my viewpoint using gluLookAt it doesn't work at all. I try
to look up and down and all I see is the floor.. it works fine until I
call gluLookAt to position myself on the sphere correctly...

Cheers

Mark

0
Reply mchristyuk 7/5/2007 6:20:11 AM

Hi Fungus,

Almost got things working... again until I use glLookAt which breaks
everything!

When I initialise my camera I call:
Glu.gluLookAt(position.x, position.y, position.z, viewVector.x,
viewVector.y, viewVector.z, upVector.x, upVector.y, upVector.z);

which gets me in the right position, standing upright on the sphere
and looking forwards.

Then to perform the camera/mouse "tracking" I do:

Quaternion quat = new Quaternion();
                float[] temp = quat.getRotationMatrix();
                temp[5] = (float)Math.Cos(pitchDegrees / 2);
                temp[6] = (float)-Math.Sin(pitchDegrees / 2);
                temp[9] = (float)Math.Sin(pitchDegrees / 2);
                temp[10] = (float)Math.Cos(pitchDegrees / 2);

                Gl.glMultMatrixf(temp);

                temp = quat.getRotationMatrix();
                temp[0] = (float)Math.Cos(-headingDegrees / 2);
                temp[2] = (float)-Math.Sin(-headingDegrees / 2);
                temp[8] = (float)Math.Sin(-headingDegrees / 2);
                temp[10] = (float)Math.Cos(-headingDegrees / 2);

                Gl.glMultMatrixf(temp);

If I don't call gluLookAt then my camera works just how I want and the
horizon is locked. However if I call gluLookAt and do the following it
completely overwrites my gluLookAt and puts me on my side and pointing
in the wrong direction! Why? Surely I'm just multiplying into the
current matrix with my new rotations doing this?... I thought it might
be because the new rotation matricies contained 0's and were
overwriting the current matrix values... so I changed them to 1's to
help preserve the current matrix values.. but this didn't work
either... sigh...

Cheers

Mark

0
Reply mchristyuk 7/5/2007 7:40:34 AM

On Jul 5, 9:40 am, mchristyuk <mark.christ...@gmail.com> wrote:
> Hi Fungus,
>
> Almost got things working... again until I use glLookAt which breaks
> everything!
>
> When I initialise my camera I call:
> Glu.gluLookAt(position.x, position.y, position.z, viewVector.x,
> viewVector.y, viewVector.z, upVector.x, upVector.y, upVector.z);
>
> which gets me in the right position, standing upright on the sphere
> and looking forwards.
>
> Then to perform the camera/mouse "tracking" I do:
>
> Quaternion quat = new Quaternion();
>                 float[] temp = quat.getRotationMatrix();

Quaternions???

> If I don't call gluLookAt then my camera works just how I want and the
> horizon is locked.

Do the rotates before the LookAt()

glLoadIdentity()
glRotate(heading,0,0,1);
glRotate(pitch,1,0,0);
gluLookAt(...)



0
Reply fungus 7/5/2007 9:11:14 AM

Hi Fungus,

Ignore the Quaternion object.. I use it in my 6dof camera but it also
has a helper method that just gives me a standard rotation matrix.
This is what I was applying my new rotations too and trying to
multiply in.

I found out just before reading your message about doing the gluLookAt
after the glRotate... however again this nearly works except I have
the age old problem of a stuck axis.. If I look to the left and then
look up and down.. it looks up and down as if I was still looking in
my old direction... I want my "y" axis stuck so that my horizon stays
level.. however I do want the local "z" axis to rotate when I turn
around so that my "view vector" updates and that I can travel along
it...

Cheers

Mark


0
Reply mchristyuk 7/5/2007 9:21:44 AM

Hi Fungus,

Ignore the Quaternion object.. I use it in my 6dof camera but it also
has a helper method that just gives me a standard rotation matrix.
This is what I was applying my new rotations too and trying to
multiply in.

I found out just before reading your message about doing the gluLookAt
after the glRotate... however again this nearly works except I have
the age old problem of a stuck axis.. If I look to the left and then
look up and down.. it looks up and down as if I was still looking in
my old direction... I want my "y" axis stuck so that my horizon stays
level.. however I do want the local "z" axis to rotate when I turn
around so that my "view vector" updates and that I can travel along
it...

Cheers

Mark


0
Reply mchristyuk 7/5/2007 9:25:56 AM

Hi Fungus,

Finally got a working solution after thinking on it over the weekend.

What I decided to do in the end (and which allows me keep most of my
6dof code) is to keep track of the total "pitch" degrees travelled.
Therefore what I can do now is check to see whether the user wants
"roll" locked or not.. and if they do I simply multiply into my matrix
the negative of total pitch travel before doing my heading rotation.
Then I multiply back in the total pitch before multiplying in the
pitch required on this iteration of the camera cycle. This gives me
the effect of lowering my view to the horizon before each rotation of
heading.. and then restoring me back once the rotation is complete.

Not sure why I couldn't get the glRotate and gluLookAt stuff to work
as I think it should.. seems pretty straight forward. But atleast this
way I can easily switch between the two different camera modes without
hugely different code bases.

Many Thanks

Mark

0
Reply mchristyuk 7/9/2007 7:20:25 AM

9 Replies
180 Views

(page loaded in 0.106 seconds)


Reply: