PDA

View Full Version : Translating -- how to get matching coordinates



PSzalapski
03-07-2002, 08:08 PM
I have a series of points stored in trackpoints[][3] (where the second subscript is the x,y,z components) that define a "track" along which I would like to move my object, a "bird". Let us start with a simpler problem. First, I would like to draw the bird at some point on the track--pick it at random, say point with index 112. My bird and track should be drawn, and obviously, the line representing the track should "impale" the bird. Why doesn't it? My bird is not drawn on the track.

In my display function, I have

void gDisplay(){
...
glLoadIdentity();
set up camera using glLookAt();
glPushMatrix();
birdX = trackPoints[112][0];
birdY = trackPoints[112][1];
birdZ = trackPoints[112][2];
glTranslatef(birdX, birdY, birdZ);
drawBird();
glPopMatrix();
drawTrack(); /* draws line loop connecting all points in trackPoints[] */
glutSwapBuffers();
}

Obviously, if I remove the push/pop operations, I end up with the whole system of bird and track translated. I want the track stationary but the bird translated. What am I doing wrong?

Thanks in advance

blood.angel
03-07-2002, 08:29 PM
You try drawing the track before the bird?

zeckensack
03-07-2002, 08:50 PM
If you really want your track to run straight through the bird, you must make sure that the geometry of the bird model is centered around (0;0;0). This may be really easy depending on the modeler you use. If you don't have access to modeling software, you can construct the 'mass center' of the bird model - and move the vertices accordingly - when you load it.

03-08-2002, 03:26 AM
Hmm...

So, the whole thing is something like

void gDisplay()
{
glTranslatef(birdX, birdY, birdZ);
drawBird();
drawTrack();
}

Right? Because then the Track is also translated! Everything after you've called glTranslatef(...) is translated, and since your Track is drawn after you've called glTranslatef(...), it's translated too.

How about drawing the track first, then translate, then draw the bird?

void gDisplay()
{
drawTrack();
glTranslatef(birdX, birdY, birdZ);
drawBird();
}

You could also just translate everything back.

void gDisplay()
{
glTranslatef(birdX, birdY, birdZ);
drawBird();
glTranslatef(-birdX, -birdY, -birdZ);
drawTrack();
}

PSzalapski
03-08-2002, 12:31 PM
bloodangel, drawing the track before the bird doesn't help, regardless of whether I put drawTrack() before glPushMatrix(), after, or simply remove the push and pop operations.

Zecken, My bird IS centered on (0,0,0).

MainMan, Please pay attention to my glPushMatrix and glPopMatrix operations. The track does not translate with the bird when I used these stack operations as I originally wrote.

Please help! I am stuck.

PSzalapski
03-08-2002, 12:39 PM
Unbelievable! I had it right, but my drawTrack() function had a typo! Sorry, I should have checked that sooner.

P-Sz