Jump to content
  • Advertisement
Sign in to follow this  
remdul

align particle to view and vector

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

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)?

Share this post


Link to post
Share on other sites
Advertisement
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 this post


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

Quote:
Original post by Sc4Freak
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.

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 point
vec1 = Vector3d(eyepos, pnt1)

'compute vector along line length
vec2 = Vector3d(pnt1, pnt2)

'cross product
vec = CrossProduct(vec1, vec2)
vec = Normalize(vec)

'compute vertices
v1.x = pnt1.x + vec.x
v1.y = pnt1.y + vec.y
v1.z = pnt1.z + vec.z

v2.x = pnt1.x - vec.x
v2.y = pnt1.y - vec.y
v2.z = pnt1.z - vec.z

v3.x = pnt2.x - vec.x
v3.y = pnt2.y - vec.y
v3.z = pnt2.z - vec.z

v4.x = pnt2.x + vec.x
v4.y = pnt2.y + vec.y
v4.z = pnt2.z + vec.z

'render quad
glBegin 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.x
glEnd


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!