SDK Question OpenGL 4 by 4 matrix to Orbiter transformation

dumbo2007

Crazy about real time sims
Joined
Nov 29, 2009
Messages
675
Reaction score
0
Points
0
Location
India
Hi,

I am trying to integrate a physics engine into orbiter. I have got the position of various objects in the physics world as opengl 4 by 4 matrices.

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

If I was directly rendering this in opengl I could simply pass these matrices one by one to glMultMatrix() and then render the object. However I want to render these objects in Orbiter.

So I want to change the orientation of meshes which are a part of a vessel to match the position of the physics world objects. This is basically to help make a base which has objects inside it.

So given a standard opengl 4 by 4 matrix which has the rotation and translation data is there any way to directly send this matrix to an Orbiter API function and have my mesh moved there immediately ?

Here is some information on the OpenGL transformation matrix :

http://pages.cs.wisc.edu/~psilord/docs/local_axis.html
http://www.cprogramming.com/tutorial/3d/rotationMatrices.html

Opengl
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml
http://www.opengl.org/sdk/docs/man/xhtml/glTranslate.xml

Basically the output of glRotate() and glTranslate() are combined into a single matrix as far as I understand. But getting the exact information out of the standard opengl transformation matrix appears to be non trivial. Also the rotation axes themselves can apparently be oriented differently from the standard axes.



Thanks.
 
Last edited:
I don't know the specifics about the OpenGL transformation pipeline (for example, I don't know if it follows the weird DirectX convention of multiplying its transformation matrices from the right), but given sensible conventions, the way of encoding a rotation and translation into a 4x4 matrix is as follows:

Given a standard 3x3 rotation matrix R and a 3x1 translation vector t, the transformation of a point x to x' is given by
[math]
\vec{x}' = \mathsf{R} \vec{x} + \vec{t}
[/math]
or in full
[math]
\begin{array}{l}
x'_1 = R_{11} x_1 + R_{12} x_2 + R_{13} x_3 + t_1 \\
x'_2 = R_{21} x_1 + R_{22} x_2 + R_{23} x_3 + t_2 \\
x'_3 = R_{31} x_1 + R_{32} x_2 + R_{33} x_3 + t_3
\end{array}
[/math]
By combining the rotation and translation into an augmented transformation matrix A,
[math]
\mathsf{A} = \left[
\begin{array}{cccc}
R_{11} & R_{12} & R_{13} & t_1 \\
R_{21} & R_{22} & R_{23} & t_2 \\
R_{31} & R_{32} & R_{33} & t_3 \\
0 & 0 & 0 & 1
\end{array}
\right]
[/math]
you can now express the linear system as
[math]
\vec{X}' = \mathsf{A} \vec{X}
[/math]
where X and X' are augmented 4x1 position vectors
[math]
\vec{X} = \left[ \begin{array}{c} x_1 \\ x_2 \\ x_3 \\ 1 \end{array} \right],
\qquad
\vec{X}' = \left[ \begin{array}{c} x'_1 \\ x'_2 \\ x'_3 \\ 1 \end{array} \right]
[/math]
 
Thanks for the reply Martin. Yes that seems to be pretty much how opengl does it :

gl_anglestoaxes01.png


Also it seems opengl does do multiplication of the matrices in the reverse order in which the transformations are supplied :
Note that OpenGL performs matrices multiplications in reverse order if multiple transforms are applied to a vertex. For example, If a vertex is transformed by MA first, and transformed by MB second, then OpenGL performs MB x MA first before multiplying the vertex. So, the last transform comes first and the first transform occurs last in your code.

gl_transform05.png


// Note that the object will be translated first then rotated
glRotatef(angle, 1, 0, 0); // rotate object angle degree around X-axis
glTranslatef(x, y, z); // move object to (x, y, z)
drawObject();

from http://www.songho.ca/opengl/gl_transform.html#matrix

So is there some function in the Orbiter API which directly accepts the augmented transformation matrix A for a mesh which is part of a vessel ? Perhaps a variant of bool VESSEL::MeshgroupTransform() ?

If not then I would need to extract the rotations around the individual axes from the matrix A and supply the appropriate parameters in a MESHGROUP_TRANSFORM Struct .
 
Last edited:
Back
Top