PDA

View Full Version : pseudoSpherical Billboarding



Kent767
08-18-2002, 11:00 PM
I'm writing a basic particle system and need each particle to face the camera at all times
I found a really insightful tutorial at http://www.lighthouse3d.com/opengl/billboarding/index.php3?billCheat which should fit my situation perfectly.

this code makes calls to the graphics class to display the particles



for (int q=--00;q<=100;q+=1){
gfx.Particle(1,q,0,0);
gfx.Particle(1,0,q,0);
gfx.Particle(1,0,0,q);
}


my Particle function handles the call in this way




void GFX::Particle(int ParticleID,GLfloat xpos,GLfloat ypos,GLfloat zpos)
{
float modelview[16];
int i,j;

// save the current modelview matrix
glPushMatrix();

// get the current modelview matrix
glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

// undo all rotations
// beware all scaling is lost as well
for( i=0; i<3; i++ )
for( j=0; j<3; j++ ) {
if ( i==j )
modelview[i*4+j] = 1.0;
else
modelview[i*4+j] = 0.0;
}

// set the modelview with no rotations
glLoadMatrixf(modelview);


glTranslatef(xpos,ypos,zpos);
glEnable(GL_BLEND);
glColor4f(1.0f,1.0f,1.0f,0.5f);
glBindTexture(GL_TEXTURE_2D, PartTextures[ParticleID]);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f);glVertex3f(0.5f,-0.5f,0.0f);
glTexCoord2f(1.0f,1.0f);glVertex3f(0.5f,0.5f,0.0f) ;
glTexCoord2f(1.0f,0.0f);glVertex3f(-0.5f,0.5f,0.0f);
glTexCoord2f(0.0f,0.0f);glVertex3f(-0.5f,-0.5f,0.0f);
glEnd();
glDisable(GL_BLEND);

glPopMatrix();


the problem I am having, is that the particles in effect aren't rotating individually. The entire group is. (instead of moving freely around 3 axes of particles, i am always staring down one axis of drawn particles, while still being able to freely move around the scene). This tells me its something wrong I am doing with the Matrix Stack, but I am unable to pinpoint it.

Any help would be great,
Thanks
Kent

[This message has been edited by Kent767 (edited 08-19-2002).]