I’m currently making a modified version of NeHe’s lesson 19 tutorial.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19
I’ve got it set up to do a couple different kinds of particle systems, but the 3d version is throwing me off. I currently have it set up to emit little 3d cubes, but in order to show off the 3d I want them to rotate as they move away from the emitter. However, when I add the code to rotate I can’t figure out where it needs to go or what values need to be in it to make the rotatation work properly. My code is a bit long now, so I’ll only post the part in question unless someone requests the rest.
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Textures
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
if (TextureImage[0]=LoadBMP("Data/blank.bmp")) // Load Particle Texture
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create One Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The ModelView Matrix
for (loop=0;loop<MAX_PARTICLES;loop++) // Loop Through All The Particles
{
if (particle[loop].active) // If The Particle Is Active
{
float x=particle[loop].x; // Grab Our Particle X Position
float y=particle[loop].y; // Grab Our Particle Y Position
float z=particle[loop].z+zoom; // Particle Z Pos + Zoom
// Draw The Particle Using Our RGB Values, Fade The Particle Based On It's Life
glColor4f(particle[loop].r,particle[loop].g,particle[loop].b,particle[loop].life);
glRotatef(0.3f,1.0f,0.0f,0.0f); // Rotate On The X Axis
glRotatef(0.2f,0.0f,1.0f,0.0f); // Rotate On The Y Axis
glRotatef(0.4f,0.0f,0.0f,1.0f); // Rotate On The Z Axis
glBegin(GL_QUADS); // Draw A Quad
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(x-0.5f, y-0.5f, z+0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+0.5f, y-0.5f, z+0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+0.5f, y+0.5f, z+0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(x-0.5f, y+0.5f, z+0.5f); // Top Left Of The Texture and Quad
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(x-0.5f, y-0.5f, z-0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(x-0.5f, y+0.5f, z-0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+0.5f, y+0.5f, z-0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+0.5f, y-0.5f, z-0.5f); // Bottom Left Of The Texture and Quad
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(x-0.5f, y+0.5f, z-0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(x-0.5f, y+0.5f, z+0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+0.5f, y+0.5f, z+0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+0.5f, y+0.5f, z-0.5f); // Top Right Of The Texture and Quad
// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(x-0.5f, y-0.5f, z-0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+0.5f, y-0.5f, z-0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+0.5f, y-0.5f, z+0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(x-0.5f, y-0.5f, z+0.5f); // Bottom Right Of The Texture and Quad
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f(x+0.5f, y-0.5f, z-0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(x+0.5f, y+0.5f, z-0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(x+0.5f, y+0.5f, z+0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(x+0.5f, y-0.5f, z+0.5f); // Bottom Left Of The Texture and Quad
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(x-0.5f, y-0.5f, z-0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(x-0.5f, y-0.5f, z+0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(x-0.5f, y+0.5f, z+0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(x-0.5f, y+0.5f, z-0.5f); // Top Left Of The Texture and Quad
glEnd(); // Done Drawing The Quad
particle[loop].x+=particle[loop].xi/(slowdown*1000);// Move On The X Axis By X Speed
particle[loop].y+=particle[loop].yi/(slowdown*1000);// Move On The Y Axis By Y Speed
particle[loop].z+=particle[loop].zi/(slowdown*1000);// Move On The Z Axis By Z Speed
particle[loop].xi+=particle[loop].xg; // Take Pull On X Axis Into Account
particle[loop].yi+=particle[loop].yg; // Take Pull On Y Axis Into Account
particle[loop].zi+=particle[loop].zg; // Take Pull On Z Axis Into Account
particle[loop].life-=particle[loop].fade; // Reduce Particles Life By 'Fade'
if (particle[loop].life<0.0f) // If Particle Is Burned Out
{
particle[loop].life=1.0f; // Give It New Life
particle[loop].fade=float(rand()%100)/1000.0f+0.003f; // Random Fade Value
particle[loop].x=0.0f; // Center On X Axis
particle[loop].y=0.0f; // Center On Y Axis
particle[loop].z=0.0f; // Center On Z Axis
particle[loop].xi=xspeed+float((rand()%60)-32.0f); // X Axis Speed And Direction
particle[loop].yi=yspeed+float((rand()%60)-30.0f); // Y Axis Speed And Direction
particle[loop].zi=float((rand()%60)-30.0f); // Z Axis Speed And Direction
particle[loop].r=colors[col][0]; // Select Red From Color Table
particle[loop].g=colors[col][1]; // Select Green From Color Table
particle[loop].b=colors[col][2]; // Select Blue From Color Table
}
// If Number Pad 8 And Y Gravity Is Less Than 1.5 Increase Pull Upwards
if (keys[VK_NUMPAD8] && (particle[loop].yg<1.5f)) particle[loop].yg+=0.01f;
// If Number Pad 2 And Y Gravity Is Greater Than -1.5 Increase Pull Downwards
if (keys[VK_NUMPAD2] && (particle[loop].yg>-1.5f)) particle[loop].yg-=0.01f;
// If Number Pad 6 And X Gravity Is Less Than 1.5 Increase Pull Right
if (keys[VK_NUMPAD6] && (particle[loop].xg<1.5f)) particle[loop].xg+=0.01f;
// If Number Pad 4 And X Gravity Is Greater Than -1.5 Increase Pull Left
if (keys[VK_NUMPAD4] && (particle[loop].xg>-1.5f)) particle[loop].xg-=0.01f;
if (keys[VK_TAB]) // Tab Key Causes A Burst
{
particle[loop].x=0.0f; // Center On X Axis
particle[loop].y=0.0f; // Center On Y Axis
particle[loop].z=0.0f; // Center On Z Axis
particle[loop].xi=float((rand()%50)-26.0f)*10.0f; // Random Speed On X Axis
particle[loop].yi=float((rand()%50)-25.0f)*10.0f; // Random Speed On Y Axis
particle[loop].zi=float((rand()%50)-25.0f)*10.0f; // Random Speed On Z Axis
}
}
}