#### Archived

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

# Rotating to a vector

## Recommended Posts

aleks_1661    188
i need to rotate an object to be so it is aligned with the normal of a plane. ie from this...

plane          Object

_|__
\             |    |
\            |____|
\
\


to this...

plane    _  Object
-  \/
\     \   \
\     \_-
\
\


Obviously i know the normal of the plane, but i cant figure out how to rotate the object so that the object is lying on the plane. ( im using opengl by the way, if it helps) its probably staring me in the face and waving a union jack, but i''m short sighted.

##### Share on other sites
Scarab0    122
Basically what you want to do is this:
1. Create a rotation matrix that rotates the object''s Up-vector onto the plane''s normal-vector.
2. Rotate the entire object by that matrix

I assume that you know how to do step 2, and step 1 is a common programming problem. Here''s one site that explains how to do it, but there surely are many more: http://www.doe-mbi.ucla.edu/~grothe/rotmat/rotmat.html

Hope that helped.

##### Share on other sites
aleks_1661    188
whoa it cant be that hard can it, that site confused the hell out of me. isnt there a way using dot products or something im sure i saw something i just cant remember it.

+ do you have an implementation of that, i dont want to rip code from people, but maybe you could direct me to some pseudo code or something ?

if you could it would be great, i look into this a bit more as well. i like doing things on my own, not the newbie - "rip code from any where and every where, whack it all in one file and pass it off as my own pile of s**t". it just means they achieve nothing. (point of view came from my own experience, i was like that, just had to re learn everything cos i never learnt it properly)

---------------------------------------------------------------

back to the problem...

im also sure i saw some ting like this,
    normal = A      rotation matrix =  A  B  C            B                         x  x  x            C                         x  x  x

cant for the life of me remember what the x''s were or even if any of that means anything i may just be getting confused. help

I dont know.

"why dont you work you f*#@&\$g piece of junk!"