PDA

View Full Version : Sorry but its another Local/Global rotation question



joolz
06-23-2005, 08:24 AM
Hi guys

I have created an app that reads in Finite Element models (3 - 4 sided polys)

So far its taken a couple of days to get it crudely working and I am loving this OGL stuff :-)

I have spent most of today on this forum looking for past posts on 3D rotation and local/global axes....

So far my app rotates pretty well about the 3 global axes using glRotatef (I am using different mouse buttons to split the X Y and Z)

Now my question.....

The model rotates about its own axis system (global or whatever you wish to call it) ... fine I need to do this But....

I also want to rotate about the screen X, Y and Z - in fact I want this to be my default rotation as its more intuitive and like other 3D apps I use

To be clear - Imagine the screen as a 2D plane with X horizontal, Y vertical and Z out the screen - Thats the rotation axes I want

I could do with a few pointers on what to research. The OGL Superbible is going home with me tonight.

Is there a simple way to rotate about the screen or is it a 'transformation job - digging out my oooold Uni text books?'

Many thanks for your time.

Julian

06-23-2005, 05:53 PM
All transformations transform the coordinate system so once you transform you change the axes.

That is, when you do glRotatef (90, 0, 1, 0), your initial x-axis and z-axis become z-axis (-ve) and x-axis (-ve) respectively. The initial y-axis stays put.

I feel your pain cos I want to do that myself many times but this is the way OGL works.

06-28-2005, 11:59 AM
To be clear - Imagine the screen as a 2D plane with X horizontal, Y vertical and Z out the screen - Thats the rotation axes I wantthat's eye space. in opengl the eye is looking down the negative zaxis with the positive xaxis to the right and the positive yaxis going up.

these 3 vectors form a right handed coordinate system for the eye.

transforming points or vectors in eye space is no different than transforming points and vectors in any other space. its just another matrix as far as opengl is concerned.

you could supply opengl the eye vectors yourself. each eye_* represents the desired oientation of each axis. how you define these axes is arbitrary. all you are doing is giving opengl the desired orientation of your coordinate system (rotation matrix).

vec3 x = eye_right;
vec3 y = eye_up;
vec3 z = -eye_forward;
float eye_rotation[16] = {
x.x, x.y, x.z, 0,
y.x, y.y, y.z, 0,
z.x, z.y, z.z, 0,
0, 0, 0, 1
};
glMultMatrixf(eye_rotation);

consider that opengl matrices are column major, which means that points are premultiplied (multiplied on the left) for rotation, contrary to what you see in most texts, hence the eye axes are in the rows rather than the columns.

rotation matrices are a lot easier to understand when you realize that they are nothing more than oriented coordinate systems. all you need to do is supply opengl with the desired orientation, either directly, or with glRotate commands, which do nothing more than create a matrix for you and multiply it onto the matrix stack.

joolz
07-10-2005, 11:43 PM
Just thought I would feed back in case anyone else has similar problems.

My 3D rotation issue was solved by lots of research into quaternions etc...

The best thing I came up with is rotation using Ken Shoemake's code

Here is a good place to start...

www.psychology.nottingham.ac.uk/staff/cr1/3d.html (http://www.psychology.nottingham.ac.uk/staff/cr1/3d.html)

or try google using - arc ball Ken Shoemake etc

Julian