• <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控制模型

            一、簡介

            對模型的控制就是修改模型的位置和方向?qū)傩裕鼓P偷奈恢煤头较虬l(fā)生改變,通常通過移動、旋轉(zhuǎn)、縮放來實現(xiàn)。在三維CAD軟件中通常要對模型的位置進行修改,如裝配模型時把其中一個零件模型移動一個位置。由計算機圖形學(xué)知識得三維圖形的幾何變換可用一個四階齊次矩陣來表示,即模型的幾何變換都是對矩陣進行操作。

            二、OSG模型控制

            OSG中,加入模型的默認(rèn)位置是屏幕中心,對模型的位置、方向控制是通過類osg::MatrixTransform來實現(xiàn)。由類圖知,類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來表示其子節(jié)點到其父節(jié)點的四階齊次坐標(biāo)變換。

            聲明類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節(jié)點類家族來實現(xiàn)幾何數(shù)據(jù)的變換。osg::Transform類繼承自osg::Group類,它可以有多個子節(jié)點。但是osg::Transform類是一個無法由程序?qū)嵗奶摶悺S脩魬?yīng)當(dāng)使用osg::MatrixTransformosg::PositionAttitudeTransform來替代它,這兩個類均繼承自osg::Transform類。根據(jù)用戶程序的需要,可以使用其中任意一個或者同時使用他們。關(guān)于類osg::Transformosg::MatrixTransform類的更多內(nèi)容,請參考《OpenSceneGraph快速入門》書中的組節(jié)點一章。

            三、OSG中模型控制實現(xiàn)方法

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

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

             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控制模型  回復(fù)  更多評論   

            2012-05-30 10:21 by 11
            這內(nèi)存還不是泄的嘩嘩的

            # re: OpenSceneGraph控制模型  回復(fù)  更多評論   

            2012-06-05 19:59 by eryar
            ??? @11
            九九久久99综合一区二区| 综合久久久久久中文字幕亚洲国产国产综合一区首 | av色综合久久天堂av色综合在| 色综合久久久久久久久五月| 久久久久一级精品亚洲国产成人综合AV区| 久久棈精品久久久久久噜噜| 亚洲另类欧美综合久久图片区| 久久精品一区二区国产| 久久国产乱子伦免费精品| 国色天香久久久久久久小说| 一本大道久久东京热无码AV| 老司机国内精品久久久久| 人妻精品久久无码区| 国产精品久久久香蕉| 亚洲v国产v天堂a无码久久| 欧美性大战久久久久久| 久久人人爽人人爽AV片| 久久久久久亚洲精品不卡| 国产A级毛片久久久精品毛片| 99久久综合国产精品二区| 久久精品国产福利国产秒| 久久九九亚洲精品| 久久久久久无码国产精品中文字幕| 一本久久久久久久| 久久亚洲电影| 亚洲AV无码久久精品色欲| 久久久久亚洲AV无码网站| 久久免费视频网站| 精品久久久久久无码国产| 成人亚洲欧美久久久久| 色婷婷久久久SWAG精品| 亚洲精品无码久久毛片| A级毛片无码久久精品免费| 久久成人国产精品| 久久99精品久久久久久9蜜桃 | 日韩精品久久久久久免费| 成人妇女免费播放久久久| 久久久久久久免费视频| 国产精品狼人久久久久影院| 熟妇人妻久久中文字幕| 亚洲人成无码www久久久|