Jump to content
  • Advertisement


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

Billy Lee

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.

If you intended to correct an error in the post then please contact us.

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

				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

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 this post

Link to post
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

Örhugi Software

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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!