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

            OpenSceneGraph控制模型

            一、簡介

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

            二、OSG模型控制

            OSG中,加入模型的默認(rèn)位置是屏幕中心,對模型的位置、方向控制是通過類osg::MatrixTransform來實(shí)現(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的子類,它有一個(gè)類osg::Matrix的成員變量_matrix來表示其子節(jié)點(diǎn)到其父節(jié)點(diǎn)的四階齊次坐標(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é)點(diǎn)類家族來實(shí)現(xiàn)幾何數(shù)據(jù)的變換。osg::Transform類繼承自osg::Group類,它可以有多個(gè)子節(jié)點(diǎn)。但是osg::Transform類是一個(gè)無法由程序?qū)嵗奶摶悺S脩魬?yīng)當(dāng)使用osg::MatrixTransformosg::PositionAttitudeTransform來替代它,這兩個(gè)類均繼承自osg::Transform類。根據(jù)用戶程序的需要,可以使用其中任意一個(gè)或者同時(shí)使用他們。關(guān)于類osg::Transformosg::MatrixTransform類的更多內(nèi)容,請參考《OpenSceneGraph快速入門》書中的組節(jié)點(diǎn)一章。

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

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

            編程實(shí)現(xiàn)模型控制程序,為了簡便起見,模型節(jié)點(diǎn)仍然從文件中得到。得到模型節(jié)點(diǎn)后,分別對其進(jìn)行移動、旋轉(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:  }

            運(yùn)行效果如下圖所示:

            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久久精品免费| 99精品国产免费久久久久久下载 | 亚洲av成人无码久久精品| 久久久无码人妻精品无码| 国产三级精品久久| 久久超碰97人人做人人爱| 久久国产香蕉一区精品| 久久精品国产亚洲av影院| 久久精品国产一区二区| 久久青青草原亚洲av无码app | 久久婷婷久久一区二区三区| 日本加勒比久久精品| 99麻豆久久久国产精品免费| 久久久久久亚洲精品影院| 久久久久久久99精品免费观看| 亚洲欧洲精品成人久久曰影片| 久久97精品久久久久久久不卡| 无码精品久久一区二区三区| 天天综合久久久网| 99re久久精品国产首页2020| 麻豆精品久久久久久久99蜜桃| 久久国产精品免费一区| 久久综合中文字幕| 久久久久久夜精品精品免费啦| 无码任你躁久久久久久老妇| 亚洲国产精品久久久久婷婷软件| 久久婷婷五月综合色高清| 精品久久久久久中文字幕大豆网| 午夜精品久久久久久影视777| 国产三级精品久久| 一级做a爱片久久毛片| 久久综合欧美成人| 久久―日本道色综合久久| 四虎国产精品免费久久久| 伊人色综合久久天天| 婷婷综合久久中文字幕| 亚洲欧美日韩精品久久| 国产激情久久久久影院小草| 久久成人精品|