Jump to content
  • Advertisement


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



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

I suck in math. I mean I REALLY SUCK. Now that I have said that you dont have to bitch at me about how stupid this question is. I''m making a particle system. I got my particles up and moving and everything is pretty much done. The particles are just two triangle strips with textures on them. When viewed from the side they look like peices of paper shooting through the air. How can I use the glRotatef function to make these particles constantly face a certain point on the screen?

Share this post

Link to post
Share on other sites
Billboard: A 2D image rotated in 3D so that its normal follows the normal of the viewing direction.
Another definition would be: A 2D image that is rendered on the same plane as the viewing camera in a 3D world.

Without knowing what math your using in your system Ill just throw out some psudo code:

//get the two normals we are considering

Vector particleNormal = normalize(particle.normal);
Vector cameraView = normalize(camera.view); //(default camera in opengl is looking along (0,0,-1) )

//do a healthy amount of error checking here, see if the two normals are already equal, or close enough that you can ignore it

//we use the dotproduct to figure out how far out of line the particle actually is

double temp = dotProduct(particleNormal,cameraView);
double angle = radiansToDegrees(acos(temp));
//we will need to rotate the particle around an axis orthagonal to both the particle normal and view vector

Vector fixAxis = crossProduct(particleNormal,cameraView);
fixAxis = normalize(fixAxis); //not sure if this is needed by opengl''s glRotate

//now just rotate it using the angle we found around the axis we found


As for the dotProduct and crossProduct, a trig book or a quick search on the net can fill that in. The acos() is the arc cosine function found in math.h.
The formula used for the angle is:
(assume vector1 and vector2 are unit vectors)
cos(angle)=vector1 dot vector2
thus: angle = acos(vector1 dot vector2)

In wrote this really quickly and didnt test anything but it should be generally accurate.

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.

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!