OSG Matrix transformation node-----translation rotation Scaling
Transferred from: http://www.cnblogs.com/ylwn817/articles/1973396.html
Translation rotation Scaling This three is the most common operation of the OSG matrix operation, the following shows an example as well as a description
First understand the next OSG space direction:
The OSG direction is shown on the left, the x-axis indicates the horizontal orientation of the screen, the y-axis is the vertical orientation of the screen and the orientation of the screen, and the z axis indicates the vertical orientation of the screen, each arrow pointing to the positive direction
Here's how to learn matrix transformations
First, Pan:
#include <osgDB/ReadFile>#include<osgViewer/Viewer>#include<osg/Node>#include<osg/MatrixTransform>voidMain () {Osgviewer::viewer Viewer; Osg::ref_ptr<osg::Group> root=NewOsg::group (); Osg::ref_ptr<osg::Node> Osgcool=osgdb::readnodefile ("COW.OSG"); Osg::ref_ptr<osg::MatrixTransform> trans=NewOsg::matrixtransform (); Trans->setmatrix (Osg::matrix::translate (0,0, -)); Trans->addchild (Osgcool.Get()); Root->addchild (Osgcool.Get()); Root->addchild (trans.Get()); Viewer.setscenedata (Root.Get()); Viewer.realize (); Viewer.run ();}
where Trans->setmatrix (Osg::matrix::translate (0,0,20)) is used to translate the object, which is represented in the positive direction of the z-axis, which is just above the screen.
Zoom operation:
#include <osgDB/ReadFile>#include<osgViewer/Viewer>#include<osg/Node>#include<osg/MatrixTransform>voidMain () {Osgviewer::viewer Viewer; Osg::ref_ptr<osg::Group> root=NewOsg::group (); Osg::ref_ptr<osg::Node> Osgcool=osgdb::readnodefile ("COW.OSG"); Osg::ref_ptr<osg::MatrixTransform> trans=NewOsg::matrixtransform (); Trans->setmatrix (Osg::matrix::scale (0.5,0.5,0.5) *osg::matrix::translate (0,-Ten,0)); Root->addchild (Osgcool.Get()); Root->addchild (trans.Get()); Viewer.setscenedata (Root.Get()); Viewer.realize (); Viewer.run ();
View Code
Osg::matrix::scale (0.5,0.5,0.5) represents the scale of the scaling, that is, the normal size of the original object
Rotating:
#include <osgDB/ReadFile>#include<osgViewer/Viewer>#include<osg/Node>#include<osg/MatrixTransform>voidMain () {Osgviewer::viewer Viewer; Osg::ref_ptr<osg::Group> root=NewOsg::group (); Osg::ref_ptr<osg::Node> Osgcool=osgdb::readnodefile ("COW.OSG"); Osg::ref_ptr<osg::MatrixTransform> trans=NewOsg::matrixtransform; Trans->setmatrix (Osg::matrix::rotate (OSG::D Egreestoradians (90.0),0,1,0)); Trans->addchild (Osgcool.Get()); Root->addchild (Osgcool.Get()); Root->addchild (trans.Get()); Viewer.setscenedata (Root.Get()); Viewer.realize (); Viewer.run ();
View Code
Osg::matrix::rotate (OSG::D Egreestoradians (90.0), 0,1,0) The method parameter represents an angle, x, y, z when there is a value in XYZ, then the object rotates around the object. When the angle is positive, the object is rotated to the right around the x, Y, z arrows, otherwise the object is rotated to the left around the X, Y, z arrows
Rotation may have an understanding error, whichever is the actual effect
OSG Matrix transformation node-----translation rotation Scaling