Brief Introduction
The Nehe course of this lesson mainly wants us to introduce the method of pickup (Selection) in OpenGL to exchange with the objects in the scene. In OSG, there is no way to encapsulate the pickup in OpenGL, but it is a more efficient way to perform the intersection with the model in the scene, The reason for processing this OSG can be referred to in OSG in this maillist:new to OSG, some questions (selection buffer, parametric curves) implementation
In the Nehe course of the key to achieve in this lesson in the selection function, it implements the selection in OpenGL way, in our OSG to select the intersection of the code is relatively simple:
Implementation of several Osgutil offers: This lesson uses the Osgutil::linesegmentintersector to detect the intersection between a specified segment and a scene shape
Case (Osgga::guieventadapter::P ush): {int choose = 0;
Osg::node *node;
Osgutil::linesegmentintersector::intersections intersections; if (Viewer->computeintersections (ea,intersections)) {osgutil::linesegmentintersector::intersection intersect
Ion = *intersections.begin ();
Osg::nodepath &nodepath = Intersection.nodepath; node = (nodepath.size () >= 1)?
Nodepath[nodepath.size () -1]:0;
const char *name = Node->getname (). C_STR ();
Choose = Atoi (name); } if (!object[choose].hit)//If the object hasn ' t already Been hit {object[choose].hit=true; Mark the Object as being Hit score+=1; Increase Score kills+=1;
Increase level kills if (kills>level*5)//New level yet? {miss=0; Misses Reset back to Zero kills=0; Reset level kills Level+=1; Increase level if (level>30)// Higher Than 30? level=30;
Set level to (Are A God?) }
}
}
Other parts of the code involve a large number of callback updates and location calculations that are cumbersome, but they are covered in previous courses, and the reader can refer to the contents of the Nehe course.