Sign in to follow this  
nlo

Normal vector to Matrix

Recommended Posts

nlo    130
is there any article about this ? i'm not a 3d maths guru, i wanna convert a normal vector to a "rotation matrix", but search arround the internet with no luck, anyone help ? thanks for help. :) [Edited by - nlo on August 4, 2005 2:01:26 AM]

Share this post


Link to post
Share on other sites
deathwearer    367
Well not that hard

Let's say you have the vector x,y,z

The matrice would be

X
Y
Z

(If i remember corectly about my maths classes ;))

For more info visit that link http://www.gamedev.net/reference/articles/article1832.asp

It's talk only about matrices and vectors ;)

Share this post


Link to post
Share on other sites
Kuladus    380
I just came across this problem and this was my naive solution. It has issues but works for my application. :D


GLfloat* p = pts[i]; // p is my normal vector (I want a rotation mtx with p as the z axis)
||| GLfloat x[3], y[3];
||| // p is now the z-axis
||| // find two perpendicular vectors to create my orthonormal basis
|||
||| if (p[0]>0.5) // if the z-axis has a substantial x component
||| {
23- // find p x j
234
234 x[0] = - p[2]*1;
234 x[1] = 0;
234 x[2] = p[0]*1;
||| }
||| else
||| {
23- x[0] = 0;
234 x[1] = p[2]*1;
234 x[2] = - p[1]*1;
||| }
|||
||| y[0] = x[1]*p[2] - x[2]*p[1];
||| y[1] = x[2]*p[0] - x[0]*p[2];
GLfloat mtx[] = { y[0],y[1],y[2],0,
--- x[0],x[1],x[2],0,
>>> p[0],p[1],p[2],0,
>>> p[0],p[1],p[2],1 }; //rotation and translation
||| glPushMatrix();
|||
||| glMultMatrixf(mtx);

Share this post


Link to post
Share on other sites
timw    598
you're saying you want to convert a vector to a rotation matrix? just do google on glrotatef this function does the same thing, just impliment the matrix forumla there. to extract the angle paramater it would be of course the magnatude of the vector

Share this post


Link to post
Share on other sites
nlo    130
thx guys, but i think i did something stupid, i didn't explain my question well, what i mean is, i wanna convert a "direction-vector" to "rotation matrix", is that mean same as RotationYawPitchRoll ??

Share this post


Link to post
Share on other sites
Kuladus    380
well what i posted gives a rotation matrix to change the z-axis into the vector you specify. this will make anything pointing in the z-direction now point in the direction of your vector.

Share this post


Link to post
Share on other sites
deathwearer    367
These are the rotation matrix

Remember if you matrix is 4x4 your vector need to be 4x1 So if your Vector is 5,6,3 JUst add 0

5
6
3
0

http://www.gamedev.net/reference/articles/1832/image192.gif

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this