My game has a relatively minor but frustrating problem. It might be easier to illustrate with a screenshot.
In the left screenshot, my sprite is standing just in front of the bridge. In the right screenshot, I've moved my camera upwards without moving the sprite, and now it is sitting a few steps on the bridge.
Technically, that is correct: my billboarded sprite's center is at the same spot (ie, the X and Z coordinates of the center of the sprite are the same). But since the perspective changes, the sprite is rotated to face the camera (which is just fine.) However, this places its feet either too far ahead or too far behind where they should be.
Drawing the sprite is pretty simple.
glTranslatef(0.0f, -0.53f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(fXPos + 0.25f, gID + 0.1875f); glVertex3f( 0.240f, 0.00f, 0);
glTexCoord2f(fXPos + 0.25f, gID + 0.0025f); glVertex3f( 0.240f, 0.75f, 0);
glTexCoord2f(fXPos , gID + 0.0025f); glVertex3f(-0.240f, 0.75f, 0);
glTexCoord2f(fXPos , gID + 0.1875f); glVertex3f(-0.240f, 0.00f, 0);
glEnd();
This is how I handle billboarding.
ES_Graphics::SetBillboard(bool Activation)
{
int i, j;
float Matrix[16];
/* If we're turning it on, alter the model view matrix. */
if(Activation)
{
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
Matrix[(i<<2) + j] = (i == j) ? 1.0f : 0.0f;
glLoadMatrixf(Matrix);
}
/* Otherwise, restore the model view matrix. */
else
{
glPopMatrix();
}
}
Any idea what could be wrong, or how I could fix this?
[Edited by - RuneLancer on July 10, 2005 3:00:50 PM]