OSG Matrix transformation node-----translation rotation Scaling

Source: Internet
Author: User
Tags addchild readfile

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.