Jump to content
  • Advertisement
Sign in to follow this  
matrix2681

NeHe #19 and Spinning Particles

This topic is 3567 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

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


Link to post
Share on other sites
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.

Share this post


Link to post
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);
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?

Share this post


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


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!