Jump to content
  • Advertisement
Sign in to follow this  
SmajlerKamil

OpenGL gluLookAt and 3ds max transformation matrix

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

Hi everyone i'm having a problem. I've got a transfromation matrix from 3ds max camera and it looks like:

[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]camera transformation:
[-0.007877, -0.999873, -0.013804]
[-0.050222, -0.013391, 0.998648]
[-0.998706, 0.008560, -0.050110]
[-666.493, -28.1239, 11.2804]
camera focal len:[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.154917
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"] [/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now I'd like to know how can i use it with gluLookAt in openGL. I was searching about this matix and i only found that the second vector (-0.007877, -0.999873,-0.013804) is UP vector and fouth is position but i don't know is it true. Can anyone help me with this matrix ?[/font]

Share this post


Link to post
Share on other sites
Advertisement
Most likely the first row specifies the world-space direction of the local +X axis of the camera, the second row the local +Y axis, and the third row the local +Z axis of the camera. The fourth row specifies the x,y,z coordinates of the camera in world space.

Typically in OpenGL, projections are set up in such a way that the camera -Z axis is mapped to the front direction in the projection matrix. Therefore, pass in the fourth row as (eyeX, eyeY, eyeZ), then 'fourth row - third row' as the (centerX, centerY, centerZ), and second row as (upX, upY, upZ). The first row is not needed, but assert that the first, second and third row together form an orthonormal right-handed basis to catch any handedness flip issues, or otherwise bad input.

Share this post


Link to post
Share on other sites

Hi everyone i'm having a problem. I've got a transfromation matrix from 3ds max camera and it looks like:

[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]camera transformation:
[-0.007877, -0.999873, -0.013804]
[-0.050222, -0.013391, 0.998648]
[-0.998706, 0.008560, -0.050110]
[-666.493, -28.1239, 11.2804]
camera focal len:[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.154917
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"] [/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now I'd like to know how can i use it with gluLookAt in openGL. I was searching about this matix and i only found that the second vector (-0.007877, -0.999873,-0.013804) is UP vector and fouth is position but i don't know is it true. Can anyone help me with this matrix ?[/font]


The first and third are most likely the forward and right vectors.

http://www.songho.ca/opengl/gl_transform.html

Changing your matrix to a 1x16 array containing:
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"][-0.007877, -0.999873, -0.013804] [-666.493] [-0.050222, -0.013391, 0.998648] [-28.1239] [-0.998706, 0.008560, -0.050110] [11.2804] [0][0][0][1]

should allow y[/font]ou to simply call glLoadMatrix instead of gluLookAt. (You might have to invert some vectors though)

Share this post


Link to post
Share on other sites

Hi everyone i'm having a problem. I've got a transfromation matrix from 3ds max camera and it looks like:

[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]camera transformation:
[-0.007877, -0.999873, -0.013804]
[-0.050222, -0.013391, 0.998648]
[-0.998706, 0.008560, -0.050110]
[-666.493, -28.1239, 11.2804]
camera focal len:[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.154917
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"] [/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now I'd like to know how can i use it with gluLookAt in openGL. I was searching about this matix and i only found that the second vector (-0.007877, -0.999873,-0.013804) is UP vector and fouth is position but i don't know is it true. Can anyone help me with this matrix ?[/font]


There isn't a concept of focal lens in GL.

As for the matrix, GL matrices are 4x4 and you seem to have a 4x3 matrix. I think you need to transpose your matrix
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"][-0.007877, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.050222[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.998706[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-666.493[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.999873[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.013391, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.008560[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-28.1239[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.013804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.998648[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.050110, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]11.2804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[/font]
and then for the last row, add {0, 0, 0, 1}

Share this post


Link to post
Share on other sites

[quote name='smajler' timestamp='1323859342' post='4893792']
Hi everyone i'm having a problem. I've got a transfromation matrix from 3ds max camera and it looks like:

[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]camera transformation:
[-0.007877, -0.999873, -0.013804]
[-0.050222, -0.013391, 0.998648]
[-0.998706, 0.008560, -0.050110]
[-666.493, -28.1239, 11.2804]
camera focal len:[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.154917
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"] [/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now I'd like to know how can i use it with gluLookAt in openGL. I was searching about this matix and i only found that the second vector (-0.007877, -0.999873,-0.013804) is UP vector and fouth is position but i don't know is it true. Can anyone help me with this matrix ?[/font]


There isn't a concept of focal lens in GL.

As for the matrix, GL matrices are 4x4 and you seem to have a 4x3 matrix. I think you need to transpose your matrix
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"][-0.007877, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.050222[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.998706[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-666.493[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.999873[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.013391, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.008560[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-28.1239[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.013804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.998648[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.050110, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]11.2804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[/font]
and then for the last row, add {0, 0, 0, 1}
[/quote]
So the matrix will look like:
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"][-0.007877, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.050222[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.998706[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-666.493[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.999873[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.013391, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.008560[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-28.1239[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]]
[[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]-0.013804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.998648[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"], -0.050110, [/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]11.2804[/font][font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]][/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"][0, 0, 0, 1 ][/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now the fourth column is position, second column is up vector. First is left vec, third is forward vector. How can i get the camera eye and camera target ?
[/font]

Share this post


Link to post
Share on other sites
You can probably reverse the code here to get eye and the center3D. http://www.opengl.org/wiki/GluLookAt_code

Share this post


Link to post
Share on other sites

Hi everyone i'm having a problem. I've got a transfromation matrix from 3ds max camera and it looks like:

[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]camera transformation:
[-0.007877, -0.999873, -0.013804]
[-0.050222, -0.013391, 0.998648]
[-0.998706, 0.008560, -0.050110]
[-666.493, -28.1239, 11.2804]
camera focal len:[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]0.154917
[/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"] [/font]
[font="Verdana, Tahoma, Arial, Tahoma, Calibri, Geneva, sans-serif"]Now I'd like to know how can i use it with gluLookAt in openGL. I was searching about this matix and i only found that the second vector (-0.007877, -0.999873,-0.013804) is UP vector and fouth is position but i don't know is it true. Can anyone help me with this matrix ?[/font]





Looks you are trying to implement MAXScript scene exporter...


You have a camera transform ("m") and you need to make a look from it in your application. So, do next steps:

1. Convert 3ds max's handled coordinate system into OpenGL's coordinate system:



-- THIS IS MAX SCRIPT CODE

m = cameras[1].transform * ToOpenGLAxis; -- let's play with first camera's transform.

-- where ToOpenGLAxis = matrix3 [-1,0,0] [0,0,1] [0,1,0] [0,0,0]



2. Make an inverse matrix of it (if you want to make a look from that camera):



m = inverse m;



3. Make an OpenGL's style matrix (column-major order): (let's make a print of matrix to log)



format "float viewMatrix[]={";

format " %,%,%,%,\n" m.row1.x m.row1.y m.row1.z 0.0;

format " %,%,%,%,\n" m.row2.x m.row2.y m.row2.z 0.0;

format " %,%,%,%,\n" m.row3.x m.row3.y m.row3.z 0.0;

format " %,%,%,%\n" m.row4.x m.row4.y m.row4.z 1.0;

format "};\n";






EDIT: Oops... Never mind. I missed "you want to do this with gluLookAt"...

EDIT2: But maybe this post can be useful for you (even small part of this):




m = cameras[1].transform * ToOpenGLAxis;

[m.row1.x, m.row2.x, m.row3.x] -- right vector

[m.row1.y, m.row2.y, m.row3.y] -- up vector

[m.row1.z, m.row2.z, m.row3.z] -- forward vector

[m.row4.x, m.row4.y, m.row4.z] -- position




gluLookAt(position.x,position.y,position.z,

position.x+forward.x,position.y+forward.y,position.z+forward.z,

up.x, up.y, up.z); // I'm not sure is this correct...



end of EDIT2




Best wishes, FXACE.

Share this post


Link to post
Share on other sites
Hi, i don't have 3ds max scene, i only have matrixes. Today i've got some information about this matrix:

R=[-0.007877, -0.999873, -0.013804
-0.050222, -0.013391, 0.998648
-0.998706, 0.008560, -0.050110]
And i think R is romation

C= 2.54 * [-666.4930, -28.12390, 11.280400]

C is position, 2.54 is conversion from inches to centimeters i don't know why and i don't know is it important.
f=1549.17 *2.54 this is focal length and also *2.54 is conversion to centimeters

Cx=360
Cy=288
Window size is 720x576, Cx and Cy is a center of window

K=[-f, 0, Cx]
0, f Cy
0, 0, 1]

Now can you tell me what f (focal length) does and is is important? Is it possible that K is some kind of projection matrix ?

And another question, 3d max has replaced Y and Z axis. In 3dmax up axsis is Z, in OGL up axis is Y. Do i have to change it before your 'algoritm' ? And what matrix should i use to change Z and Y to draw my model from 3dmax in openGL ?

Share this post


Link to post
Share on other sites





m = cameras[1].transform * ToOpenGLAxis;

[m.row1.x, m.row2.x, m.row3.x] -- right vector

[m.row1.y, m.row2.y, m.row3.y] -- up vector

[m.row1.z, m.row2.z, m.row3.z] -- forward vector

[m.row4.x, m.row4.y, m.row4.z] -- position




gluLookAt(position.x,position.y,position.z,

position.x+forward.x,position.y+forward.y,position.z+forward.z,

up.x, up.y, up.z); // I'm not sure is this correct...



end of EDIT2




Best wishes, FXACE.


This is before an inversion or after inversion ??

Share this post


Link to post
Share on other sites

[quote name='FXACE' timestamp='1324231226' post='4895036']


m = cameras[1].transform * ToOpenGLAxis;

[m.row1.x, m.row2.x, m.row3.x] -- right vector

[m.row1.y, m.row2.y, m.row3.y] -- up vector

[m.row1.z, m.row2.z, m.row3.z] -- forward vector

[m.row4.x, m.row4.y, m.row4.z] -- position




gluLookAt(position.x,position.y,position.z,

position.x+forward.x,position.y+forward.y,position.z+forward.z,

up.x, up.y, up.z); // I'm not sure is this correct...



end of EDIT2




Best wishes, FXACE.


This is before an inversion or after inversion ??
[/quote]
No inverse matrix operation required.

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!