I've written the following so far for the Quick Start Guide, which I believe summarizes the situation. One thing I had considered adding was something along the lines of: "If you already have your own vector/matrix library designed around OpenGL notation, you do not need to scrap/rewrite it; your matrices will work with OSG." This is key to anyone porting OpenGL code to OSG, I think. -Paul
Matrices and osg::Matrix The osg::Matrix class stores and allows operations on a 4×4 matrix consisting of 16 floating point numbers. MatrixTransform uses Matrix internally to store the transformation. You configure MatrixTransform by configuring its Matrix. Matrix provides an interface that is somewhat backwards from the notation used in the OpenGL specification and most OpenGL textbooks. Matrix exposes an interface consistent with two-dimensional row-major C/C++ arrays: osg::Matrix m; m( 0, 1 ) = 0.f; // Set the second element (row 0, column 1) m( 1, 2 ) = 0.f; // Set the seventh element (row 1, column 2) OpenGL matrices are one-dimensional arrays, which OpenGL documentation usually displays as column-major: GLfloat m; m[1] = 0.f; // Set the second element m[6] = 0.f; // Set the seventh element In spite of this apparent difference, both OSG and OpenGL matrices are laid out in memory identicallyOSG doesnt perform a costly transpose before submitting its matrix to OpenGL. As a developer, however, remember to transpose an OSG matrix in your head before accessing individual elements. Matrix exposes a comprehensive set of operators for vector-matrix multiplication and matrix concatenation. To transform a Vec3 v by a rotation R around a new origin T, use the following code: osg::Matrix T; T.makeTranslate( x, y, z ); osg::Matrix R; R.makeRotate( angle, axis ); Vec3 vPrime = v * R * T; OpenGL documentation usually illustrates this using postmultiplcation notation: v' = TRv This produces the same result because OpenGL's postmultiplication notation with column-major matrices is equivalent to OSG's premultiplication operators with row-major matrices. To process an entire Geode with this transformation, create a MatrixTransform node containing T, add a child MatrixTransform node containing R, and add a child Geode to the rotation MatrixTransform. [TBD need a figure for this.] This is equivalent to the following sequence of OpenGL commands: glMatrixMode( GL_MODELVIEW ); glTranslatef( ... ); // Translation T glRotatef( ... ); // Rotation R ... glVertex3f( ... ); glVertex3f( ... ); ... In summary, while OSG exposes a row-major interface that differs from OpenGL documentations column-major notation, OSG and OpenGL perform equivalent operations internally and their matrices are 100% compatible.
clip_image002.gif
Description: GIF image
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
