• Advertisement

# Rotate a 4-vev plane to be aligned with to a vector

This topic is 1736 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 have a particle system whereby strips, which are just 4-vector triangle strips, shoot out of a central location in a calculated direction.  I would like the strips to be aligned with their direction of travel.

My strip has four vertices as you'd expect:  0,0,0  0,5,0  1,0,0  1,5,0                       // [ 1 unit wide, 5 units long ]

I then have a direction it will be going in:  Vector3 particleDirection;            // Direction vector it's going to fly out in

So my challenge is to rotate those four points so that the little plane they form is aligned with its direction of travel.  Right now, of course, they're just flat (orthogonal) to the Z plane.

I only need to do this once, as they can continue to fly once oriented in the right direction.

I'm guessing this is as simple as a matrix that translates it to the center, rotates it, and translates it back.  But I'm too much of a noob to know how to get that rotation.

Thanks!

Dave

#### Share this post

##### Share on other sites
Advertisement

it is done by setting your matrix axes oriented in the direction you need using crossproducts.

dirWant : the direction to align to, normalized.

ref: a reference vector for 3D alignment. Could be set to (0,1,0)

a = normalize(crossProduct(dirWant, ref));

b = crossproduct(a, dirWant);

c = dirWant;

Then you set your matrix like so if your vertices are on the Z plane:

a.x  b.x  c.x  t.x
a.y  b.y  c.y  t.y
a.z  b.z  c.z  t.z
0    0    0    1


t being your particle position.

Note that if dirWant == ref vector, it won't work. So choose another ref if they are equals.

Hope that help!

#### Share this post

##### Share on other sites

• Advertisement