Changeset 8268
- Timestamp:
- 05/01/08 00:31:08
- Files:
-
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9a_ManualTraversal/9a_ManualTraversal.cpp (modified) (1 diff)
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9b_NodeVisitor/9b_NodeVisitor.cpp (modified) (1 diff)
- OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9c_IntersectionVisitor/9c_IntersectionVisitor.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9a_ManualTraversal/9a_ManualTraversal.cpp
r8116 r8268 6 6 int main( int argc, char **argv ) 7 7 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 8 // The scene graph can be manually 9 // traversed by using dynamic_cast 10 // to get the Group type and then 11 // iterate through the children 12 // then use recursion to traverse 13 // through the children that are groups. 14 // 15 16 // load the data we wish to traverse 17 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("Earth/earth.ive"); 18 19 // 1. Your task is to implement this manual 20 // traversal code and print out the 21 // class types and node nodes of the 22 // node in the scene graph as your travese it. 23 // 24 // 2. Discuss what changes you would need to 25 // make to this code to handle Group subclasses, 26 // effects of node masks and node states. 27 // 28 // 3. Discuss what changes you would need to 29 // make to handle scene graph node types that 30 // unknown to your application. 31 // 32 // 4. Discuss how you might insert custom operations 33 // on nodes encoutered while traversing - such as 34 // a find name node algorithm, 35 36 37 // Now over to you, write a manual traversers that 38 // prints out the scene graph as per item. 9 39 10 40 return 0; OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9b_NodeVisitor/9b_NodeVisitor.cpp
r8116 r8268 6 6 int main( int argc, char **argv ) 7 7 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 8 // load the data we wish to traverse 9 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("Earth/earth.ive"); 10 11 // 1. Following on from 9a_ManualTraversal 12 // write a custom NodeVisitor that out 13 // class node types encounted as one 14 // traveses through all nodes in a scene graph 15 16 // 2. Modify the vistor so that it only 17 // traverses active children 18 19 // 3. Modify the visitor so that is capable of finding 20 // nodes with specific Node name. 21 22 // 4. Discuss how the custom NodeVisitor will 23 // cope with Node types that are unknown to it. 24 // 25 // 5. Discuss how one can implement apply(..) methods 26 // for classes not listed in the NodeVisitor base class. 9 27 10 28 return 0; OpenSceneGraph-TrainingMaterials/trunk/Sources/Exercises/09_traversers/9c_IntersectionVisitor/9c_IntersectionVisitor.cpp
r8147 r8268 1 1 #include <osg/ArgumentParser> 2 2 #include <osgDB/ReadFile> 3 #include <osgViewer/Viewer> 4 3 5 4 6 #include <iostream> … … 6 8 int main( int argc, char **argv ) 7 9 { 8 std::cout<<"TODO "<<argv[0]<<std::endl; 10 11 // This purpose of this exercise is to 12 // explore the use of osgUtil::IntersectionVisitor 13 // and scene graph modification 14 15 16 // scene graph to intersect 17 osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("cow.osg"); 18 19 if (!node) 20 { 21 std::cout<<"No file loaded."<<std::endl; 22 return 1; 23 } 9 24 10 return 0; 25 // 1. First write code to make a single intersection 26 // through the center of the loaded model using 27 // a line segment that passes through from negative 28 // y position to positive y direction relative to the 29 // center of the model, and covering the full extents 30 // of the model. 31 // 32 // Report the full X Y Z position of all intersections 33 // in both object coordinates and world coordinates 34 35 36 37 // 2. Add into the scene osg::ShapeDrawables, one for each 38 // each intersection and each of these drawables with 39 // a osg::Sphere centered at the intersection point and 40 // with radius 1/50th of the size of the overal model 41 // radius. 42 43 osg::ref_ptr<osg::Group> group = new osg::Group; 44 45 group->addChild(node.get()); 46 47 // need to add ShapeDrawables here... 48 49 osgViewer::Viewer viewer; 50 51 viewer.setSceneData(group.get()); 52 53 return viewer.run(); 11 54 }
