# align particle to view and vector

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

## Recommended Posts

How can I calculate the 4 vertices of a quad that is both aligned to the viewing direction and the motion vector in which the particle is moving? I'd like to do this for a particle system, individual quads but also smoke trails (triangle strip). Can someone explain this in simple pseudo code (I'm no math whiz)?

bumpa :)

##### Share on other sites
I'm not sure what you're asking. If it's rotated to view the camera (billboard), then you can't simultaneously have it rotated to the direction its moving in because 2 of the 3 axes of rotation are being used to get it to face the camera.

##### Share on other sites
I figured it out myself. Well, I had to cos the forums where down.

Quote:
 Original post by Sc4FreakI'm not sure what you're asking. If it's rotated to view the camera (billboard), then you can't simultaneously have it rotated to the direction its moving in because 2 of the 3 axes of rotation are being used to get it to face the camera.

It will not work in every situation (e.g. when the viewing direction is parallel to the motion vector) but will generally look ok:

It is surprisingly simple:

'compute vector from eye to pointvec1 = Vector3d(eyepos, pnt1)    'compute vector along line lengthvec2 = Vector3d(pnt1, pnt2)    'cross productvec = CrossProduct(vec1, vec2)vec = Normalize(vec)'compute verticesv1.x = pnt1.x + vec.xv1.y = pnt1.y + vec.yv1.z = pnt1.z + vec.z    v2.x = pnt1.x - vec.xv2.y = pnt1.y - vec.yv2.z = pnt1.z - vec.zv3.x = pnt2.x - vec.xv3.y = pnt2.y - vec.yv3.z = pnt2.z - vec.z    v4.x = pnt2.x + vec.xv4.y = pnt2.y + vec.yv4.z = pnt2.z + vec.z'render quadglBegin GL_QUADS glTexCoord2i 0, 0: glVertex3fv v4.x glTexCoord2i 0, 1: glVertex3fv v3.x glTexCoord2i 1, 1: glVertex3fv v2.x glTexCoord2i 1, 0: glVertex3fv v1.xglEnd

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013600
×