• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            OpenSceneGraph控制模型

            Posted on 2012-05-28 21:33 eryar 閱讀(3764) 評論(2)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenSceneGraph控制模型

            一、簡介

            對模型的控制就是修改模型的位置和方向屬性,使模型的位置和方向發生改變,通常通過移動、旋轉、縮放來實現。在三維CAD軟件中通常要對模型的位置進行修改,如裝配模型時把其中一個零件模型移動一個位置。由計算機圖形學知識得三維圖形的幾何變換可用一個四階齊次矩陣來表示,即模型的幾何變換都是對矩陣進行操作。

            二、OSG模型控制

            OSG中,加入模型的默認位置是屏幕中心,對模型的位置、方向控制是通過類osg::MatrixTransform來實現。由類圖知,類osg::MatrixTransform繼承自類osg::Transform,而類osg::Transform是由類osg::Group繼承而來。

            Class Diagram

            Figure 3.1 Inheritance Diagram for osg::MatrixTransform

            聲明類osg::MatrixTransform中的注釋為:

            /** MatrixTransform - is a subclass of Transform which has an osg::Matrix 
            * which represents a 4x4 transformation of its children from local coordinates 
            * into the Transform's parent coordinates. 
            */ 

            osg::MatrixTransform是類osg::Transform的子類,它有一個類osg::Matrix的成員變量_matrix來表示其子節點到其父節點的四階齊次坐標變換。

            聲明類osg::Transform中的注釋為:

             

            /** A Transform is a group node for which all children are transformed by 
            * a 4x4 matrix. It is often used for positioning objects within a scene, 
            * producing trackball functionality or for animation. 

            * Transform itself does not provide set/get functions, only the interface 
            * for defining what the 4x4 transformation is. Subclasses, such as 
            * MatrixTransform and PositionAttitudeTransform support the use of an 
            * osg::Matrix or a osg::Vec3/osg::Quat respectively. 

            * Note: If the transformation matrix scales the subgraph then the normals 
            * of the underlying geometry will need to be renormalized to be unit 
            * vectors once more. This can be done transparently through OpenGL's 
            * use of either GL_NORMALIZE and GL_RESCALE_NORMAL modes. For further 
            * background reading see the glNormalize documentation in the OpenGL 
            * Reference Guide (the blue book). To enable it in the OSG, you simply 
            * need to attach a local osg::StateSet to the osg::Transform, and set 
            * the appropriate mode to ON via 
            * stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON); 
            */ 

            OSG通過osg::Transform節點類家族來實現幾何數據的變換。osg::Transform類繼承自osg::Group類,它可以有多個子節點。但是osg::Transform類是一個無法由程序實例化的虛基類。用戶應當使用osg::MatrixTransformosg::PositionAttitudeTransform來替代它,這兩個類均繼承自osg::Transform類。根據用戶程序的需要,可以使用其中任意一個或者同時使用他們。關于類osg::Transformosg::MatrixTransform類的更多內容,請參考《OpenSceneGraph快速入門》書中的組節點一章。

            三、OSG中模型控制實現方法

            OSG中,因為矩陣變換類osg::MatrixTransform繼承自osg::Group,所以矩陣變換類可以當作一個特殊節點加入到場景中,矩陣變換類中也可以加入節點,加入的節點就會被這個矩陣變換類處理,可以對加入的節點模型進行移動、旋轉、縮放操作。

            編程實現模型控制程序,為了簡便起見,模型節點仍然從文件中得到。得到模型節點后,分別對其進行移動、旋轉和縮放操作。程序代碼如下:

             1:  //--------------------------------------------------------------------------
               2:  //    Copyright (c) 2012 eryar All Rights Reserved.
               3:  //
               4:  //        File    : Main.cpp
               5:  //        Author  : eryar@163.com
               6:  //        Date    : 2012-1-5 21:42
               7:  //        Version : 1.0v
               8:  //
               9:  //    Description : Model transformations: Translate, Rotate, Scale.
              10:  //
              11:  //==========================================================================
              12:   
              
            13:  #include <osgDB/ReadFile>
              
            14:  #include <osgViewer/Viewer>
              
            15:  #include <osg/MatrixTransform>
              
            16:  #include <osgViewer/ViewerEventHandlers>
              
            17:   
              
            18:  int main(int argc, char* argv[])
              
            19:  {
              
            20:      osgViewer::Viewer   viewer;
              
            21:      viewer.addEventHandler(new osgViewer::WindowSizeHandler);
              
            22:      viewer.addEventHandler(new osgViewer::StatsHandler);
              
            23:   
              
            24:      osg::ref_ptr<osg::Group> root   = new osg::Group;
              
            25:      osg::ref_ptr<osg::Node> axes   = osgDB::readNodeFile("axes.osgt");
              
            26:   
              
            27:      // Translate: Offset along X axis 2 unit;
              28:      osg::ref_ptr<osg::MatrixTransform> mtMove = new osg::MatrixTransform;
              
            29:      mtMove->setMatrix(osg::Matrix::translate(-200));
              
            30:      mtMove->addChild(axes.get());
              
            31:   
              
            32:      // Rotate: Rotate along Z axis about 45 degree then translate along x axis 2 unit.
              33:      osg::ref_ptr<osg::MatrixTransform> mtRotate = new osg::MatrixTransform;
              
            34:      mtRotate->setMatrix(osg::Matrix::rotate(
              
            35:          osg::DegreesToRadians(45.0),osg::Z_AXIS) * osg::Matrix::translate(2,0,0));
              
            36:      mtRotate->addChild(axes.get());
              
            37:   
              
            38:      // Scale
              39:      osg::ref_ptr<osg::MatrixTransform> mtScale  = new osg::MatrixTransform;
              
            40:      mtScale->setMatrix(osg::Matrix::scale(0.5,0.5,0.5));
              
            41:      mtScale->addChild(axes.get());
              
            42:   
              
            43:      root->addChild(mtMove);
              
            44:      root->addChild(mtRotate);
              
            45:      root->addChild(mtScale);
              
            46:   
              
            47:      viewer.setSceneData(root.get());
              
            48:      viewer.realize();
              
            49:      return viewer.run();
              
            50:  }

            運行效果如下圖所示:

            Transform

            Figure 3.2 Translate, Scale, Rotate Model

             

            PDF Version:

            OSG Transform

            Feedback

            # re: OpenSceneGraph控制模型  回復  更多評論   

            2012-05-30 10:21 by 11
            這內存還不是泄的嘩嘩的

            # re: OpenSceneGraph控制模型  回復  更多評論   

            2012-06-05 19:59 by eryar
            ??? @11
            青青热久久综合网伊人| 久久国产精品无码HDAV| 久久精品国产福利国产琪琪| 精品久久久久久久久久久久久久久| 91性高湖久久久久| 狠狠色综合网站久久久久久久高清| 久久综合狠狠综合久久综合88| 国产精品久久久天天影视| 国产精品美女久久久免费| 国产A级毛片久久久精品毛片| 日本一区精品久久久久影院| 亚洲欧美精品一区久久中文字幕| 亚洲AV无码久久精品色欲| 国内精品久久久久久中文字幕| 99久久精品免费看国产一区二区三区 | 久久w5ww成w人免费| 国产99久久久国产精品~~牛 | 久久人人妻人人爽人人爽| 久久久精品波多野结衣| 久久久久亚洲AV无码麻豆| 美女久久久久久| 一本久久久久久久| 77777亚洲午夜久久多喷| 亚洲乱码精品久久久久..| 国产精品99久久久久久猫咪| 久久亚洲私人国产精品| 久久久久亚洲AV无码观看| 国产三级精品久久| 91麻精品国产91久久久久| 精品久久久久久久无码| 久久99精品国产自在现线小黄鸭 | 久久精品国产亚洲AV香蕉| 久久精品国产72国产精福利| 99久久精品无码一区二区毛片| 国内精品久久久久久久97牛牛| 久久精品aⅴ无码中文字字幕不卡| 欧美一级久久久久久久大| 久久国产V一级毛多内射| 久久久精品国产Sm最大网站| 欧美日韩精品久久久免费观看| 国产99久久久久久免费看|