Esempio n. 1
0
void benchExit( void )
{
	if ( No_timing )
		puts("# dist:  num. colls.:");
	else
		puts("# dist:  coll. time (msec):   num. colls.:");

	for ( unsigned int i = 0; i < Ndistances; i ++ )
		if ( No_timing )
			printf("%3.3f  %6u\n", timing[i].dist, timing[i].ncols );
		else
			printf("%3.3f  %10.4f  %6u\n",
				   timing[i].dist, timing[i].time, timing[i].ncols );

	printf("# num collisions = %u\n", ncollisions );

	unsigned int nfaces = 0;
	for ( osg::FaceIterator fi = fixed_geom->beginFaces();
		  fi != fixed_geom->endFaces(); ++ fi )
	{
		nfaces ++ ;
	}
	printf("# num faces = %u\n", nfaces );

	if ( No_timing  == false )
		printf("# build time = %f (msec)\n", build_time / 2.0 );
}
OSG::NodePtr makePolygon(double pntData[][3], int numPoints) {

  OSG::GeometryPtr geoPtr  = OSG::Geometry::create();
  OSG::NodePtr     nodePtr = OSG::Node::create();

  GeoPositions3fPtr    pnts    = GeoPositions3f::create();
  GeoNormals3fPtr      norms   = GeoNormals3f::create();
  GeoTexCoords2fPtr    tex     = GeoTexCoords2f::create();
  GeoIndicesUI32Ptr    indices = GeoIndicesUI32::create();   
  GeoPLengthsUI32Ptr   lens    = GeoPLengthsUI32::create();  
  GeoPTypesUI8Ptr      types   = GeoPTypesUI8::create();     

  //Set up the properties according to the geometry defined above
  beginEditCP(pnts);
  beginEditCP(norms);
  
  for(int i = 0; i < numPoints; i++) 
    {
      pnts->push_back(Pnt3f(pntData[i][0],
                            pntData[i][1], 
                            pntData[i][2]));

      indices->push_back(2*i);

      norms->push_back(Vec3f(0.0, 0.0, pntData[i][2]));
      indices->push_back(2*i + 1);
    }

  endEditCP(pnts);
  endEditCP(norms);

  beginEditCP(types);
  beginEditCP(lens);
  types->push_back(GL_POLYGON);
  lens->push_back(numPoints);
  endEditCP(types);
  endEditCP(lens);

  beginEditCP(geoPtr);
  
  geoPtr->setMaterial(getDefaultMaterial());
  geoPtr->setPositions(pnts);
  geoPtr->setNormals(norms);
  geoPtr->setIndices(indices);
  
  geoPtr->editMFIndexMapping()->push_back(Geometry::MapPosition | 
                                          Geometry::MapNormal);
  
  geoPtr->setTypes(types);
  geoPtr->setLengths(lens);
  
  endEditCP(geoPtr);

  nodePtr->setCore(geoPtr);
  return nodePtr;
}
// This implementation is adapted from
// OSG::SimpleSceneManager::highlightChanged() in OpenSG 1.4.0.
void OpenSGNavGrab::initHighlight()
{
   if ( mHighlightMaterial == OSG::NullFC )
   {
      mHighlightMaterial = OSG::SimpleMaterial::create();

#if OSG_MAJOR_VERSION < 2
      CPEdit(mHighlightMaterial, OSG::SimpleMaterial::LitFieldMask);
#endif

      mHighlightMaterial->setLit(false);
   }

   if ( mHighlightNode == OSG::NullFC )
   {
#if OSG_MAJOR_VERSION < 2
      OSG::GeoPTypesPtr type       = OSG::GeoPTypesUI8::create();
      OSG::GeoPLengthsPtr lens     = OSG::GeoPLengthsUI32::create();
#else
      OSG::GeoPTypesUI8Ptr type    = OSG::GeoPTypesUI8::create();
      OSG::GeoPLengthsUI32Ptr lens = OSG::GeoPLengthsUI32::create();
#endif
      OSG::GeoIndicesUI32Ptr index = OSG::GeoIndicesUI32::create();
      mHighlightPoints             = OSG::GeoPositions3f::create();
      OSG::GeometryPtr geo         = OSG::Geometry::create();
      mHighlightNode               = OSG::Node::create();

#if OSG_MAJOR_VERSION < 2
      CPEditAll(type);
      CPEditAll(lens);
      CPEditAll(index);
      CPEditAll(mHighlightPoints);
      CPEditAll(geo);
      CPEdit(mHighlightNode, OSG::Node::CoreFieldMask);
#endif

      type->push_back(GL_LINE_STRIP);
      type->push_back(GL_LINES);

      lens->push_back(10);
      lens->push_back(6);

#if OSG_MAJOR_VERSION < 2
      OSG::GeoIndicesUI32::StoredFieldType* index_field =
         index->getFieldPtr();
#else
      OSG::GeoIndicesUI32::StoredFieldType* index_field =
         index->editFieldPtr();
#endif

      index_field->push_back(0);
      index_field->push_back(1);
      index_field->push_back(3);
      index_field->push_back(2);
      index_field->push_back(0);
      index_field->push_back(4);
      index_field->push_back(5);
      index_field->push_back(7);
      index_field->push_back(6);
      index_field->push_back(4);

      index_field->push_back(1);
      index_field->push_back(5);
      index_field->push_back(2);
      index_field->push_back(6);
      index_field->push_back(3);
      index_field->push_back(7);

      mHighlightPoints->push_back(OSG::Pnt3f(-1, -1, -1));
      mHighlightPoints->push_back(OSG::Pnt3f( 1, -1, -1));
      mHighlightPoints->push_back(OSG::Pnt3f(-1,  1, -1));
      mHighlightPoints->push_back(OSG::Pnt3f( 1,  1, -1));
      mHighlightPoints->push_back(OSG::Pnt3f(-1, -1,  1));
      mHighlightPoints->push_back(OSG::Pnt3f( 1, -1,  1));
      mHighlightPoints->push_back(OSG::Pnt3f(-1,  1,  1));
      mHighlightPoints->push_back(OSG::Pnt3f( 1,  1,  1));

      geo->setTypes(type);
      geo->setLengths(lens);
      geo->setIndices(index);
      geo->setPositions(mHighlightPoints);
      geo->setMaterial(mHighlightMaterial);

      mHighlightNode->setCore(geo);
   }
}