Ok, I'm lost --> rotating a vector around a point.

Hi Gurus,

I’m using gluLookAt to focus the viewpoint on a dynamic (moving) object in my scene. Now, I would like the user to be able to move towards\away from the focal point (easy to do) or rotate around it. The problem is, I need to know the position of the observer in order to use gluLookAt, but as the position relative to the focal point is changing, I cannot store an Angle value for rotation around the target, as this changes when the focal point moves.

Basically, I can build a vector to the focus, make it unit length, but then how to rotate it in a given plane by x degrees, without knowing the total rotation?

In other words: how do you rotate a vector around a point, in a plane, incrementally, by x degrees.

Cheers.

The usual way to handle this is to find the normal to the plane; call it (xn, yn, zn). Then apply glRotate*(angle, xn, yn, zn).

I haven’t used gluLookAt, so I don’t know if there are any peculiar problems with this approach.

HTH, P.

You will have to do that like this

// viewpoint is current viewpoint
// objectpoint is the position of the object

XYZ temp = ( viewpoint - objectpoint );

float flLen = sqrt( temp.x * temp.x + temp.y * temp.y + temp.z * temp.z )

flLen = 1 / flLen;
temp = Vector( temp.x * flLen, temp.y * flLen, temp.z * flLen );

Vector newview = viewpoint + temp * dist; // where dist is the distance you want to move to the object.