//For stateTwo,turn FOG OFF and set to OVERRIDE //Descendants in this sub-tree will not be able to change FOG unless //they set the FOG attribute value to PROTECTED stateTwoFogON_OVRD->setAttribute(fog,osg:StateAttribute:ON): stateTwoFogON_OVRD->setMode(GL_FOG, osg:StateAttribute:ON osg:StateAttribute:OVERRIDE); /For stateThree,try to turn FOG OFF. Since the attribute is not PROTECTED,and //the parents set this attribute value to OVERRIDE,the parent's value will be used. //(i.e.FOG will remain ON.) stateThreeFogOFF->setMode(GL FOG,osg:StateAttribute:OFF); /For stateFour,set the mode to PROTECTED,thus overriding the parent setting stateFourFogOFF PROT->setMode(GL FOG, osg:StateAttribute:OFF osg:StateAttribute:PROTECTED); /apply the StateSets above to appropriates nodes in the scene graph. root->setStateSet(stateRootBlend); mtOne->setStateSet(stateOneDecal); mtTwo->setStateSet(stateTwoFogON_OVRD); mtThree->setStateSet(stateThreeFogOFF); mtSix->setStateSet(stateFiveDustTexture); mtFour->setStateSet(stateFourFogOFF PROT); 5.从文件中加载模型并放入到场景中 5.1本章目标 加载几何模型并加入到场景中,调整其中一个模型在场景中的位置并通过安装仿真循环观察场 景。 5.2加载几何模型并加入到场景中 如果你下载了当前版本的Open Scene Graph,那么你就可以将在有相应插件的任何文件格式。 包括以下的几何文件格式:3dc,3ds,flt,geo,iv,ive,lwo,md2,obj,osg和以下这些图像文件格式: bmp,gif,jpeg,rgb,tga,tife Open Scene Graph安装包里包含了很多open scene graph格式(.osg)的几何文件。我们会 加载其中一个,还有一个MPI Open Flight(.flt)文件。为了便于找到模型,建立一个models文 12
12 // For stateTwo, turn FOG OFF and set to OVERRIDE. //Descendants in this sub-tree will not be able to change FOG unless //they set the FOG attribute value to PROTECTED stateTwoFogON_OVRD->setAttribute(fog, osg::StateAttribute::ON); stateTwoFogON_OVRD->setMode(GL_FOG, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); // For stateThree, try to turn FOG OFF. Since the attribute is not PROTECTED, and // the parents set this attribute value to OVERRIDE, the parent's value will be used. // (i.e. FOG will remain ON.) stateThreeFogOFF->setMode(GL_FOG, osg::StateAttribute::OFF); // For stateFour, set the mode to PROTECTED, thus overriding the parent setting stateFourFogOFF_PROT->setMode(GL_FOG, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); // apply the StateSets above to appropriates nodes in the scene graph. root->setStateSet(stateRootBlend); mtOne->setStateSet(stateOneDecal); mtTwo->setStateSet(stateTwoFogON_OVRD); mtThree->setStateSet(stateThreeFogOFF); mtSix->setStateSet(stateFiveDustTexture); mtFour->setStateSet(stateFourFogOFF_PROT); 5.从文件中加载模型并放入到场景中 5.1 本章目标 加载几何模型并加入到场景中,调整其中一个模型在场景中的位置并通过安装仿真循环观察场 景。 5.2 加载几何模型并加入到场景中 如果你下载了当前版本的 Open Scene Graph,那么你就可以将在有相应插件的任何文件格式。 包括以下的几何文件格式:3dc,3ds,flt,geo,iv,ive,lwo,md2,obj,osg 和以下这些图像文件格式: bmp,gif,jpeg,rgb,tga,tif。 Open Scene Graph 安装包里包含了很多 open scene graph 格式(.osg)的几何文件。我们会 加载其中一个,还有一个 MPI Open Flight(.flt)文件。为了便于找到模型,建立一个 models 文
件夹,并用OSG DATA PATH系统变量指向它。(通常为 C:\Projects\OpenSceneGraph\OpenSceneGraph-Data\)。解压此文件到那个文件夹下。 几何模型使用scene graph的节点表示。因此,为了加载并操作一个几何模型文件,我们需要声明 一个句柄(或指针)指向osg:Node类型实例。(在一些要求的#include后)。 #include <osg/Node> #include <osgDB/ReadFile> osg:Node*cessnaNode NULL; osg:Node*tankNode NULL; cessnaNode osgDB:readNodeFile("cessna.osg"); tankNode osgDB:readNodeFile("Models/T72-tank/t72-tank des.flt"); 这就是加载数据库需要做的事。下一步我们把它作为scene graph的一部分加入。将模型加载到 transform节点的子节点上,这样我们就可以重新定位它了。 /Declare a node which will serve as the root node /for the scene graph.Since we will be adding nodes /as'children'of this node we need to make it a 'group' /instance. /The'node'class represents the most generic version of nodes. /This includes nodes that do not have children (leaf nodes. /The 'group'class is a specialized version of the node class. /It adds functions associated with adding and manipulating //children. osg:Group*root new osg:Group(); root->addChild(cessnaNode); /Declare transform,initialize with defaults. osg:PositionAttitudeTransform*tankXform new osg:PositionAttitudeTransform(); /Use the 'addChild'method of the osg:Group class to /add the transform as a child of the root node and the /tank node as a child of the transform. root->addChild(tankXform); tankXform->addChild(tankNode); /Declare and initialize a Vec3 instance to change the 3
13 件夹,并用 OSG_DATA_PATH 系统变量指向它。(通常为 C:\Projects\OpenSceneGraph\OpenSceneGraph-Data\)。解压此文件到那个文件夹下。 几何模型使用 scene graph 的节点表示。因此,为了加载并操作一个几何模型文件,我们需要声明 一个句柄(或指针)指向 osg::Node 类型实例。(在一些要求的#include 后)。 #include <osg/Node> #include <osgDB/ReadFile> ... osg::Node* cessnaNode = NULL; osg::Node* tankNode = NULL; ... cessnaNode = osgDB::readNodeFile("cessna.osg"); tankNode = osgDB::readNodeFile("Models/T72-tank/t72-tank_des.flt"); 这就是加载数据库需要做的事。下一步我们把它作为 scene graph 的一部分加入。将模型加载到 transform 节点的子节点上,这样我们就可以重新定位它了。 // Declare a node which will serve as the root node // for the scene graph. Since we will be adding nodes // as 'children' of this node we need to make it a 'group' // instance. // The 'node' class represents the most generic version of nodes. // This includes nodes that do not have children (leaf nodes.) // The 'group' class is a specialized version of the node class. // It adds functions associated with adding and manipulating // children. osg::Group* root = new osg::Group(); root->addChild(cessnaNode); // Declare transform, initialize with defaults. osg::PositionAttitudeTransform* tankXform = new osg::PositionAttitudeTransform(); // Use the 'addChild' method of the osg::Group class to // add the transform as a child of the root node and the // tank node as a child of the transform. root->addChild(tankXform); tankXform->addChild(tankNode); // Declare and initialize a Vec3 instance to change the