Opengl animation looks 'wrong' when windows gets busy!???

Hey folks

We’ve developed an ActiveX animation control for a client using OpenGL, and it works great - You can request that an object moves at a velocity, and then the ActiveX control uses the system timer to process, animate and draw…

I’m pleased cause its my first OpenGL app ever! (Yes, I am a bit of a newbie!)

Its also my first ActiveX too - The reason being that this is to be integrated into a clients VB application later on. (our job is to simply provide a visual engine for a simulation system)

The viewport simply locks onto the object as it moves - Boring, I know, but there’s supposed to be a background later on.

However…

Here’s the problem - If the system gets busy, the object in the middle of the view starts to skip forward and backwards intermittantly… Theoretically, this shouldn’t happen since the camera is supposed to lock on - Ideally, you’d think that the object would remain in the center of the view perfectly, right?

The ActiveX works by calling the openGL updates and processes on a timer event as follows:

// Clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Update the object position using the time
// and a set velocity

// First we calculate the time to make sure
// our object will be at the correct pos.
// at the right time.
current_time=glutGet(GLUT_ELAPSED_TIME);
move_mult=(current_time-lasttime)/1000;
lasttime=current_time;

// Calculate the movement of the object
// to ensure we move the correct distance
move_step=velocity * move_mult;

// Update the objects x coordinate (move!)
ox += move_step;

// Draw the Object using OpenGL
glPushMatrix();
glTranslatef(ox, oy, oz);
glCallList(theObject);
glPopMatrix();

// Use the Objects ox,oy,oz to calculate and
// target the ‘camera’ (using gluLookAt)
//
// Camera is placed oy + 1 to be slightly
// above.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 1, 1, 4000);
gluLookAt(ox, oy + 1, oz, ox, oy, oz, 0, 1, 0);

// Block any OpenGL until finished
glFinish();

// Draw the buffer to screen
SwapBuffers();

Anyone got any ideas? Its almost like the camera/boat position do not match - Like somehow perhaps the ActiveX control is ‘skipping’ some code? Perhaps the last camera settings are being used? Hmmm…

Any help would be REALLY, REALLY appreciated before I tear my hair out!

Thanks people!

Kev.

I believe you need to set the projection matrix before you draw the model, not after.
Also, the Windows timer events are horribly inaccurate, so you’ll get time steps of varying sizes, especially when Windows is doing other tasks, this may manifest itself as stuttering. To make time flow more smoothly, you need to update the system anytime a Window’s message is not in the queue, and keep track of time by using either the high performance timer or system timer. I’ve never done any programming for ActiveX so I don’t even know if that is an option.

Yup!

Fixed it - Just moved the Camera calculations BEFORE I did any gl drawing, and viola… No more nasty jerking about…

Like this:

1 - Move boats
2 - Calculate Viewport (Camera)
3 - Draw Object
4 - Swapbuffers

Yippeeee! That’s one headache solved - Now for the rest of those lovely Windoze issues like ActiveX to solve!

Thanks dude!