NeHe #19 and Spinning Particles

Started by
6 comments, last by lc_overlord 15 years, 3 months ago
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
Advertisement
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.
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);
glLoadIdentity();
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?
glLoadIdentity();
glTranslatef(x,y,z);
glRotatef(rotate, 0.0, 0.0, 1.0); //about z axis
glColor4f(r,g,b,fade);
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?

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.
That did the trick. Vielen dank :)
Quote:Original post by matrix2681
Vielen dank :)

That's German. But maybe it's similar in Swedish. [rolleyes][lol]
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
HA! I hadn't even noticed LC's nationality. I just felt like saying "thanks" in German.
well it's close enough i guess.

This topic is closed to new replies.

Advertisement