• <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 閱讀(3775) 評論(2)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            OpenSceneGraph控制模型

            一、簡介

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

            二、OSG模型控制

            OSG中,加入模型的默認位置是屏幕中心,對模型的位置、方向控制是通過類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é)點的四階齊次坐標變換。

            聲明類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)當使用osg::MatrixTransformosg::PositionAttitudeTransform來替代它,這兩個類均繼承自osg::Transform類。根據(jù)用戶程序的需要,可以使用其中任意一個或者同時使用他們。關(guān)于類osg::Transformosg::MatrixTransform類的更多內(nèi)容,請參考《OpenSceneGraph快速入門》書中的組節(jié)點一章。

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

            OSG中,因為矩陣變換類osg::MatrixTransform繼承自osg::Group,所以矩陣變換類可以當作一個特殊節(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
            久久久老熟女一区二区三区| 伊人精品久久久久7777| 久久亚洲春色中文字幕久久久| av色综合久久天堂av色综合在| 久久精品麻豆日日躁夜夜躁| 久久香蕉国产线看观看精品yw| 久久精品国产精品亚洲精品| 一本久久精品一区二区| 久久天天躁狠狠躁夜夜网站| 91精品国产91久久久久久青草| 婷婷五月深深久久精品| 亚洲国产香蕉人人爽成AV片久久| 中文字幕精品久久久久人妻| 国产精品禁18久久久夂久| 久久天天躁狠狠躁夜夜avapp| 久久成人精品| 久久久久免费精品国产| 久久久国产精品亚洲一区| 精品国产一区二区三区久久蜜臀| 亚洲国产日韩欧美久久| 成人精品一区二区久久久| 精品久久久久久中文字幕| 天堂无码久久综合东京热| 国产成人99久久亚洲综合精品 | 久久久久久久国产免费看| 久久97精品久久久久久久不卡| 日韩精品无码久久一区二区三| 久久亚洲高清观看| 国产精品一区二区久久| 中文字幕人妻色偷偷久久| 香蕉aa三级久久毛片| 久久国产精品波多野结衣AV| 久久亚洲综合色一区二区三区| 久久国产精品77777| 亚洲精品国产美女久久久| 麻豆av久久av盛宴av| 亚洲∧v久久久无码精品| 性高朝久久久久久久久久| 久久久青草青青国产亚洲免观| 婷婷久久综合九色综合九七| 久久精品无码免费不卡|