More particletrouble

Ok, let’s start with the code:

glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix();
float modelview[16];

glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

for(int i=0; i<3; i++ )
for(int 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);

//glPopMatrix();

ParticleVec::iterator itend = m_Particles.end();
for(ParticleVec::iterator it=m_Particles.begin(); it!=itend; ++it)
{
glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip
glColor3ub(it->m_Col.r, it->m_Col.g, it->m_Col.b); // Use particle’s color

  glTexCoord2d(1,1); 
  glVertex3f(it-&gt;m_Pos.x+it-&gt;m_Size,it-&gt;m_Pos.y+it-&gt;m_Size,it-&gt;m_Pos.z); // Top Right
	  
  glTexCoord2d(0,1); 
  glVertex3f(it-&gt;m_Pos.x-it-&gt;m_Size,it-&gt;m_Pos.y+it-&gt;m_Size,it-&gt;m_Pos.z); // Top Left
	  
  glTexCoord2d(1,0); 
  glVertex3f(it-&gt;m_Pos.x+it-&gt;m_Size,it-&gt;m_Pos.y-it-&gt;m_Size,it-&gt;m_Pos.z); // Bottom Right
	  
  glTexCoord2d(0,0); 
  glVertex3f(it-&gt;m_Pos.x-it-&gt;m_Size,it-&gt;m_Pos.y-it-&gt;m_Size,it-&gt;m_Pos.z); // Bottom Left
  glEnd(); // Done Building Triangle Strip
//it-&gt;Render();

} // end for

glPopMatrix();

As you se I’m trying to use billboarding but something ain’t right. This works fine if the particlesystem is on coordinates 0,0,0 but if I try to move it it dissappers. I know there is something wrong with my coordinates but I don’t know what. If someone could show me what I’ve forgotten that would be nice. Now don’t think I’m asking here becouse I’m lazy, I’ve already tried several things but nothing worked abd I’ve read a tutorial on billboarding but didn’t understand it all. Appart from showing me what to do an explaination would be very nice.
Thanks

Originally posted by ArchMiffo:
[b]Ok, let’s start with the code:

glPushMatrix();
float modelview[16];

glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

for(int i=0; i<3; i++ )
for(int 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);
//glPopMatrix();
[/b]

First, instead of manually loading the identity matrix, just call glLoadIdentity();
I don’t know what’s wrong with your coordinates.

[This message has been edited by lucidmm (edited 09-03-2002).]

I don’t know, that’s the code from the tutorial. But it doesn’t work better if I remove push and pop.

What do you try moving the coordinates to? Maybe you are moving outside the window.

Well, I know where the particles should end up (that’s where they are if I don’t use billboarding). Let’s see if you can help me answer another question. If I have the coordinates for one quad and the view vector (the direction the camera is facing) and the cameras position, how do I use billboarding to make that one quad face the camera?
What I’ve understood so far is that you can do something like this:
float modelview[16];

glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

for(int i=0; i<3; i++ )
for(int 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);

DrawQuad();

But it seems as if I have to change the quads coordinates.

The simplest way to do billboarding is to apply the inverse rotations to your particles. For example,if you rotate the scene by a certain amount, to get the billboard effect, rotate by the negative of that amount to cancel the rotation. In this way, the polygon will still face the camera. To see an example of this method, look at http://nehe.gamedev.net/tutorials/lesson.asp?l=09

Here is another more mathematical approach. http://nate.scuzzy.net/docs/billboard/

I should add that you have to be careful when you say “changing the quad coordinates”. You can change where an object is in a scene by calling matrix transformations, but you are not changing the object’s coordinates explicitly.

Thanks lucidmm, that tutorial at http://nate.scuzzy.net/docs/billboard/ did the trick. It’s working like a charm