#### Archived

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

# Rotation

This topic is 5483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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.

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011831
• ### Who's Online (See full list)

There are no registered users currently online

×