Advertisement

Rotation

Started by November 18, 2003 12:24 AM
0 comments, last by noname12345 21 years, 3 months ago
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?
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 consideringVector 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 isdouble 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 vectorVector 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 foundglRotatef(angle,fixAxis.x,fixAxis.y,fixAxis.z);


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.
Just because the church was wrong doesn't mean Galileo wasn't a heretic.It just means he was a heretic who was right.

This topic is closed to new replies.

Advertisement