#### Archived

This topic is now archived and is closed to further replies.

# Problem when billboarding particles

This topic is 5660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

My code is based on NeHe''s lesson 19 particle system. I''m trying to billboard the particles so that they always face the camera but it''s only drawing one triangle per particle, so only half of the particle is drawn.
        // Variables for billboarding

float modelview[16];
glGetFloatv (GL_MODELVIEW_MATRIX, modelview);
float up[3] = {modelview[0], modelview[4], modelview[8]};
float right[3] = {modelview[1], modelview[5], modelview[9]};

for (loop = 0; loop < MAX_PARTICLES; loop++)
{
if (particle[loop].active)									// If particle is active

{
// Get particle position

float x = particle[loop].x;
float y = particle[loop].y;
float z = particle[loop].z + zoom;

// Colour the particle using RGB values. Fade the particle based on its life

glColor4f (particle[loop].r, particle[loop].g, particle[loop].b, particle[loop].life);

// Draw particle

glBegin (GL_TRIANGLE_STRIP);
glTexCoord2d(1,1); glVertex3f(x+(up[0]+right[0]), y+(up[1]+right[1]), z+(up[2]+right[2]));	// Top right

glTexCoord2d(0,1); glVertex3f(x+(up[0]-right[0]), y+(up[1]-right[1]), z+(up[2]-right[2]));	// Top left

glTexCoord2d(1,0); glVertex3f(x+(right[0]-up[0]), y+(right[1]-up[1]), z+(right[2]-up[2]));	// Bottom right

glTexCoord2d(0,0); glVertex3f(x+(right[0]+up[0]), y+(right[1]+up[1]), z+(right[2]+up[2]));	// Bottom left

glEnd();
...

What am I doing wrong? I have a suspicion that I am supposed to add the whole ''up'' and ''right'' vectors instead of e.g. up[0]+right[0] but when I do that, I get an error saying "cannot add two pointers".

##### Share on other sites
Well you are using the exact same coords for the first and last vertex and therefor you draw 2 identical triangles.

You should be subtracting both values instead of adding them to get the coords right.

Eggert Jóhannesson
Kálfhól 1, 801 Selfoss
ICELAND

Örhugi Software

[edited by - Eggert on June 19, 2003 4:23:23 AM]

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013636
×