# NeHe #19 and Spinning Particles

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

## Recommended Posts

Hi All, I'm working with NeHe's particle engine tutorial. Normally, the particles spew out from the center, but I've changed how the particles themselves look. They look a little like stars now. I would like to be able to have each particle rotate about its own z-axis while traveling. Everything I've tried makes the whole scene twirl around like it's going down the drain. Any ideas? Thanks, Michael Fritzius

##### Share on other sites
your on the right track, but you have to remember that in opengl, matrix transform is in the reverse order, which means that instead of introducing the rotation in the end, you must do so in the beginning.

Think of it not as moving the object, but moving the world (or camera if you like) around it.

##### Share on other sites
Well, what I have is this:

int DrawGLScene(GLvoid)
{
glClearColor(0.3f, 0.3f, 0.3f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
rotate += 0.5;

for (loop=0;loop<MAX_PARTICLES;loop++) //1000 particles
{
if (particle[loop].active)
{
float x=particle[loop].x; //get particle x position
float y=particle[loop].y; //get particle y position
float z=particle[loop].z+zoom; //get particle z position
//next three lines, rotate particle?
glTranslatef(x,y,z);
glRotatef(rotate, 0.0, 0.0, 1.0); //about z axis
glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip
glTexCoord2d(1,1); glVertex3f(x+0.5f,y+0.5f,z); //
glTexCoord2d(0,1); glVertex3f(x-0.5f,y+0.5f,z);
glTexCoord2d(1,0); glVertex3f(x+0.5f,y-0.5f,z);
glTexCoord2d(0,0); glVertex3f(x-0.5f,y-0.5f,z);
glEnd(); // Done Building Triangle Strip

//rest of the code not relevant here

I thought that might work, but it results in the down-the-drain effect like I was saying. Each time the axes are translated to where the particle is, then the particle is drawn, then the axes are reset. But it still seems to rotate everything about a global z axis, rather than the z axis for each particle.

It is at the beginning (I think) like you said--rotate before the object is drawn.

Right?

##### Share on other sites
that's because your translating while drawing the vertics glVertex3f(x+0.5f,y+0.5f,z);

in order for that to work you have to remove all the x+ and y+, and change z to 0 from these four lines.

##### Share on other sites
That did the trick. Vielen dank :)

##### Share on other sites
Quote:
 Original post by matrix2681Vielen dank :)

That's German. But maybe it's similar in Swedish. [rolleyes][lol]

##### Share on other sites
HA! I hadn't even noticed LC's nationality. I just felt like saying "thanks" in German.

##### Share on other sites
well it's close enough i guess.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 14
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015488
×