Billboarding in a Particle System

First off, I’m really new to 3-D Graphics, OpenGL and JOGL, so go easy on me please.

I’m writing a 3-D simulation of our galaxy and am trying to use a particle system to represent the spiral arms and deep sky objects. Some of the particles will be textured with a nebulous pattern and will be part of the star clouds. Some particles will basically be icons that will represent star clusters and other “objects”.

By lifting pieces of the JOGL particles and gears demos I have part of it limping along. The user will be able to rotate the galaxy in 3-D to look at it. In order to have the particles display properly I think I need to billboard them. I’m hoping someone can show me the matrix transformations to do that. Here are bits of the code:

// Here is a particle's draw routine.  The coordinate system has already been rotated 
// when this is called.
public void draw( GL gl, Texture texture, RGBA tendToColor )
{
    texture.bind( );
    gl.glColor4f( rgba.r, rgba.g, rgba.b, rgba.a );

    gl.glBegin( GL.GL_QUADS );
    gl.glTexCoord2f( 0.0f, 0.0f );
    gl.glVertex3f( currentPos.x, currentPos.y - 2, currentPos.z );
    gl.glTexCoord2f( 1.0f, 0.0f );
    gl.glVertex3f( currentPos.x + 2, currentPos.y - 2, currentPos.z );
    gl.glTexCoord2f( 1.0f, 1.0f );
    gl.glVertex3f( currentPos.x + 2, currentPos.y, currentPos.z );
    gl.glTexCoord2f( 0.0f, 1.0f );
    gl.glVertex3f( currentPos.x, currentPos.y, currentPos.z );
    gl.glEnd( );
}


// Here is the GLJPanel's display method that sets things up and calls the particle's draw method.
public void display( GLAutoDrawable drawable )
{
    final GL gl = drawable.getGL( );

    gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
    gl.glPushMatrix( );

    gl.glRotatef( view_rotx, 1.0f, 0.0f, 0.0f );
    gl.glRotatef( view_roty, 0.0f, 1.0f, 0.0f );
    gl.glRotatef( view_rotz, 0.0f, 0.0f, 1.0f );

    for ( int i = 0; i < particles.size( ); i++ )
    {
        ( (Particle) particles.get( i ) ).draw( gl, texture );
    }

    gl.glPopMatrix( );
}


// And here is the reshape method

public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height )
{
GL gl = drawable.getGL( );
// the size of openGL
gl.glViewport( 0, 0, width, height );

    // perspective view (smaller for further behind)
    gl.glMatrixMode( GL.GL_PROJECTION );
    gl.glLoadIdentity( );

    // perspective
    double ratio = (double) width / (double) height;
    // angle, ratio, nearest, farthest
    glu.gluPerspective( 65.0, ratio, 0.0, 1.0 );

    // draw into the model matrix now
    gl.glMatrixMode( GL.GL_MODELVIEW );
    gl.glLoadIdentity( );
    gl.glTranslatef( 0.0f, 0.0f, -40.0f );
}

So, can someone give me a hand and tell me what is need to rotate particles so they are face on with the screen when drawn? Thanks a million…

Bill

I figured it out. The particle draw() method needs to be changed as:

public void draw( GL gl, Texture texture, float view_rotx, float view_roty )
{
    texture.bind( );
    gl.glColor4f( rgba.r, rgba.g, rgba.b, rgba.a );

    gl.glPushMatrix( );
    
    gl.glTranslatef( currentPos.x, currentPos.y, currentPos.z );
    gl.glRotatef( -view_rotx, 1.0f, 0.0f, 0.0f );
    gl.glRotatef( -view_roty, 0.0f, 1.0f, 0.0f );

    gl.glBegin( GL.GL_QUADS );

    gl.glTexCoord2f( 0.0f, 0.0f );
    gl.glVertex3f( -PARTICLE_RADIUS, PARTICLE_RADIUS, 0.0f );
    gl.glTexCoord2f( 0.0f, 1.0f );
    gl.glVertex3f( -PARTICLE_RADIUS, -PARTICLE_RADIUS, 0.0f );
    gl.glTexCoord2f( 1.0f, 1.0f );
    gl.glVertex3f( PARTICLE_RADIUS, -PARTICLE_RADIUS, 0.0f );
    gl.glTexCoord2f( 1.0f, 0.0f); gl.glVertex3f( PARTICLE_RADIUS, PARTICLE_RADIUS,0.0f);
    
    gl.glEnd( );
    
    gl.glPopMatrix( );
}