Ejemplo n.º 1
0
void testObj::setActive( osg::NodePtr parent, bool active )
{
	if ( _isActive && ! active )
	{
		osg::addRefCP( node );
		parent->subChild( node );
	}
	else if ( ! _isActive && active )
 		parent->addChild( node );
	_isActive = active;
}
Ejemplo n.º 2
0
osg::NodePtr InventorLoader::traverseGraph( SoNode* OIVNode,
                                            osg::NodePtr OSGNode )
{
    ////////////////////////////////////////////////////////////////////////////
  FDEBUG(("   InventorLoader::traverseGraph( %x )\n",
                          OIVNode));
    ////////////////////////////////////////////////////////////////////////////


    /////////////////
    // Material node
    /////////////////

    if( OIVNode->isOfType( SoMaterial::getClassTypeId() ) )
    {
        // Convert current material
        osg::SimpleMaterialPtr _Material;
        _Material = convertMaterial( ( SoMaterial* ) OIVNode );

        if( mMergeMaterial )
        {
            // Check if that material was already encountered
            TMaterialSet::iterator _Iter;
            for(_Iter = mMaterialSet.begin();
                _Iter != mMaterialSet.end();
                ++_Iter )
            {
                if( compareMaterial( *_Iter, _Material, mMergeTolerance ) )
                    break;
            }

            if( _Iter != mMaterialSet.end() )
            {
                mCurrentState.Material = *_Iter;

                // Delete the converted material from above as it isn't used.
                subRefCP( _Material );
            }
            else
            {
                mMaterialSet.insert( _Material );
                mCurrentState.Material = _Material;
            }
        }
        else
        {
            mCurrentState.Material = _Material;
        }

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    ///////////////////
    // Coordinate node
    ///////////////////

    if( OIVNode->isOfType( SoCoordinate3::getClassTypeId() ) )
    {
        // Save current coordinates
        mCurrentState.Positions = convertCoordinates((SoCoordinate3*)OIVNode);

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    //////////////////////
    // Normalbinding node
    //////////////////////

    if( OIVNode->isOfType( SoNormalBinding::getClassTypeId() ) )
    {
        // Save current normalbinding
        SoNormalBinding* _Binding = ( SoNormalBinding* ) OIVNode;
        mCurrentState.NormalBinding = _Binding->value.getValue();

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    ///////////////
    // Normal node
    ///////////////

    if( OIVNode->isOfType( SoNormal::getClassTypeId() ) )
    {
        // Save current normals
        mCurrentState.Normals = convertNormals( ( SoNormal* ) OIVNode );

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    ///////////////////////
    // Transformation node
    ///////////////////////

    if( OIVNode->isOfType( SoTransform::getClassTypeId() ) )
    {
        osg::NodePtr _OSGTransform = convertTransformation( OIVNode );

        // Add the transformation to the current OSG node
        beginEditCP ( OSGNode, Node::ChildrenFieldMask );
        {
            OSGNode->addChild( _OSGTransform );
        }
        endEditCP   ( OSGNode, Node::ChildrenFieldMask );

        // Return the new transform node as the current OSG node
        return _OSGTransform;
    }

    ///////////////////////
    // MatrixTransformation node
    ///////////////////////

    if( OIVNode->isOfType( SoMatrixTransform::getClassTypeId() ) )
    {
        osg::NodePtr _OSGTransform = convertMatrixTransformation( OIVNode );

        // Add the transformation to the current OSG node
        beginEditCP ( OSGNode, Node::ChildrenFieldMask );
        {
            OSGNode->addChild( _OSGTransform );
        }
        endEditCP   ( OSGNode, Node::ChildrenFieldMask );

        // Return the new transform node as the current OSG node
        return _OSGTransform;
    }


    ////////////////////
    // Indexed face set
    ////////////////////

    if( OIVNode->isOfType( SoIndexedFaceSet::getClassTypeId() ) )
    {
        osg::NodePtr _OSGGeometry = convertIFSGeometry( OIVNode );

        // Add the geometry to the current OSG node
        beginEditCP ( OSGNode, Node::ChildrenFieldMask );
        {
            OSGNode->addChild( _OSGGeometry );
        }
        endEditCP   ( OSGNode, Node::ChildrenFieldMask );

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }

    ////////////////////
    // Face set
    ////////////////////

    if( OIVNode->isOfType( SoFaceSet::getClassTypeId() ) )
    {
        osg::NodePtr _OSGGeometry = convertFSGeometry( OIVNode );

        // Add the geometry to the current OSG node
        beginEditCP ( OSGNode, Node::ChildrenFieldMask );
        {
            OSGNode->addChild( _OSGGeometry );
        }
        endEditCP   ( OSGNode, Node::ChildrenFieldMask );

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    //////////////////
    // Separator node
    //////////////////

    if( OIVNode->isOfType( SoSeparator::getClassTypeId() ) )
    {
        SoGroup* _OIVGroup = ( SoGroup* ) OIVNode;
        osg::NodePtr _OSGGroup = getGroupNode( OIVNode );
        osg::NodePtr _CurrentNode = _OSGGroup;

        // Add the group to the current OSG node
        beginEditCP ( OSGNode, Node::ChildrenFieldMask );
        {
            OSGNode->addChild( _OSGGroup );
        }
        endEditCP   ( OSGNode, Node::ChildrenFieldMask );

        // Save the current state
        TState _TmpState = mCurrentState;

        // Traverse children
        for( int i=0; i < _OIVGroup->getNumChildren(); ++i )
        {
            SoNode* _OIVChild = _OIVGroup->getChild( i );
            _CurrentNode = traverseGraph( _OIVChild, _CurrentNode );
        }

        // Restore the state
        mCurrentState = _TmpState;

        // Check if the new group node has only one child
        // --> then it's redundant and can be discarded
        checkForRedundancy( _OSGGroup );

        // Return the old OSG node as the current OSG node
        return OSGNode;
    }


    //////////////
    // Group node
    //////////////

    else if( OIVNode->isOfType( SoGroup::getClassTypeId() ) )
    {
        osg::NodePtr _CurrentNode = OSGNode;
        SoGroup* _OIVGroup = ( SoGroup* ) OIVNode;

        // Traverse children
        for( int i=0; i < _OIVGroup->getNumChildren(); ++i )
        {
            SoNode* _OIVChild = _OIVGroup->getChild( i );
            _CurrentNode = traverseGraph( _OIVChild, _CurrentNode );
        }

        // Return the end of the group as current OSG node
        return _CurrentNode;
    }

    FWARNING (( "Unhandled Inventor node: %s\n",
                OIVNode->getTypeId().getName().getString() ));

    return OSGNode;
}
Ejemplo n.º 3
0
// No arguments: batch convert all vt* files
// switch argument: batch convert all vt* files into one osb file with a switch
// file argument: convert only the specified file
int main (int argc, char const* argv[])
{
	vector<string> filenames;
	bool useSwitch = false;
	if (argc == 2)
	{
		if (string(argv[1]).find("switch") != string::npos)
			useSwitch = true;
		else
			filenames.push_back(string(argv[1]));
	}

	if (useSwitch || filenames.empty())
	{
		const boost::regex e(".+\\.vt[a-z]");
		directory_iterator end;
		for (directory_iterator it("./"); it != end; ++it)
		{
			string curFile = it->path().filename().string();
			if (regex_match(curFile, e))
				filenames.push_back(curFile);
		}
	}

	OSG::osgInit(0, NULL);

	vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
	OSG::NodePtr switchNode = OSG::Node::create();
	OSG::SwitchPtr switchCore = OSG::Switch::create();
	beginEditCP(switchCore);
	switchCore->setChoice(0);
	endEditCP(switchCore);
	beginEditCP(switchNode);
	switchNode->setCore(switchCore);
	endEditCP(switchNode);

	for (vector<string>::const_iterator it = filenames.begin(); it != filenames.end(); ++it)
	{
		string filename(*it);
		cout << "Opening file " << filename << " ... " << endl << flush;
		string fileExt = getFileExt(filename);

		vtkXMLDataReader* reader = NULL;
		vtkGenericDataObjectReader* oldStyleReader = NULL;
		if (fileExt.find("vti") != string::npos)
		{
			reader = vtkXMLImageDataReader::New();
			vtkSmartPointer<vtkImageDataGeometryFilter> geoFilter =
			        vtkSmartPointer<vtkImageDataGeometryFilter>::New();
			geoFilter->SetInputConnection(reader->GetOutputPort());
			mapper->SetInputConnection(geoFilter->GetOutputPort());
		}
		if (fileExt.find("vtr") != string::npos)
		{
			reader = vtkXMLRectilinearGridReader::New();
			vtkSmartPointer<vtkGeometryFilter> geoFilter =
			        vtkSmartPointer<vtkGeometryFilter>::New();
			geoFilter->SetInputConnection(reader->GetOutputPort());
			mapper->SetInputConnection(geoFilter->GetOutputPort());
		}
		else if (fileExt.find("vts") != string::npos)
		{
			reader = vtkXMLStructuredGridReader::New();
			vtkSmartPointer<vtkGeometryFilter> geoFilter =
			        vtkSmartPointer<vtkGeometryFilter>::New();
			geoFilter->SetInputConnection(reader->GetOutputPort());
			mapper->SetInputConnection(geoFilter->GetOutputPort());
		}
		else if (fileExt.find("vtp") != string::npos)
		{
			reader = vtkXMLPolyDataReader::New();
			mapper->SetInputConnection(reader->GetOutputPort());
		}
		else if (fileExt.find("vtu") != string::npos)
		{
			reader = vtkXMLUnstructuredGridReader::New();
			vtkSmartPointer<vtkGeometryFilter> geoFilter =
			        vtkSmartPointer<vtkGeometryFilter>::New();
			geoFilter->SetInputConnection(reader->GetOutputPort());
			mapper->SetInputConnection(geoFilter->GetOutputPort());
		}
		else if (fileExt.find("vtk") != string::npos)
		{
			oldStyleReader = vtkGenericDataObjectReader::New();
			oldStyleReader->SetFileName(filename.c_str());
			oldStyleReader->Update();
			if(oldStyleReader->IsFilePolyData())
				mapper->SetInputConnection(oldStyleReader->GetOutputPort());
			else
			{
				vtkSmartPointer<vtkGeometryFilter> geoFilter =
				        vtkSmartPointer<vtkGeometryFilter>::New();
				geoFilter->SetInputConnection(oldStyleReader->GetOutputPort());
				mapper->SetInputConnection(geoFilter->GetOutputPort());
			}
		}
		else
		{
			cout << "Not a valid vtk file ending (vti, vtr, vts, vtp, vtu, vtk)" <<
			endl;
			return 1;
		}

		if (fileExt.find("vtk") == string::npos)
		{
			reader->SetFileName(filename.c_str());
			reader->Update();
		}

		vtkActor* actor = vtkActor::New();
		actor->SetMapper(mapper);

		vtkOsgConverter converter(actor);
		converter.SetVerbose(true);
		//converter->SetMapper(mapper);
		converter.WriteAnActor();
		OSG::NodePtr node = converter.GetOsgNode();
		replaceExt(filename, "osb");
		if (useSwitch)
		{
			beginEditCP(switchNode);
			switchNode->addChild(node);
			endEditCP(switchNode);
		}
		else
			OSG::SceneFileHandler::the().write(node, filename.c_str());

		if (reader)
			reader->Delete();
		if (oldStyleReader)
			oldStyleReader->Delete();
	}
	if (useSwitch)
	{
		string filename(filenames[0]);
		replaceExt(filename, "osb");
		OSG::SceneFileHandler::the().write(switchNode, filename.c_str());
	}
	//mapper->Delete(); // TODO crashes

	OSG::osgExit();

	cout << "File conversion finished" << endl;

	return 0;
}
void testRefCount(void)
{
#if 0
    OSG::NodePtr pNode = OSG::Node::create();

    OSG::NodePtr pNode1 = OSG::Node::create();

    fprintf(stderr, "1\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif

    pNode->addChild(pNode1);

    fprintf(stderr, "2\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif

    fprintf(stderr, "3\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif

    applyToAspect(1, false);
    applyToAspect(2);

    fprintf(stderr, "4\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif
    
    fprintf(stderr, "5\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif

    applyToAspect(1, false);

    fprintf(stderr, "6\n");

//XX
#if 0
    pNode.dump();
    pNode1.dump();
#endif

    applyToAspect(2);

    fprintf(stderr, "7\n");
#endif
}
Ejemplo n.º 5
0
int main( int argc, char *argv[] )
{
	// parse command line options
	parsecommandline( argc, argv );


	// OSG init
	osg::osgLog().setLogLevel(osg::LOG_WARNING);
	osg::osgInit(argc, argv);

	// disable display lists
	osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
	osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
    if ( pGeoProto != osg::NullFC )
        pGeoProto->setDlistCache(false);

	// create the graph
	osg::NodePtr node;

	// root
	root = osg::Node::create();
	beginEditCP(root);
	root->setCore( osg::Group::create() );

	// beacon for camera and light
	osg::NodePtr beacon;
	beacon = osg::Node::create();
	beginEditCP(beacon);
	beacon->setCore( osg::Group::create() );
	endEditCP(beacon);

	// light
	light_node = osg::Node::create();
	osg::DirectionalLightPtr light = osg::DirectionalLight::create();
	beginEditCP( light_node );
	light_node->setCore( light );
	endEditCP( light_node );
	root->addChild( light_node );
	beginEditCP(light);
	light->setAmbient( .3, .3, .3, 1 );
	light->setDiffuse( 1, 1, 1, 1 );
	light->setDirection(0,0,1);
	light->setBeacon( beacon );
	endEditCP(light);

	// transformation, parent of beacon
	node = osg::Node::create();
	cam_trans = osg::Transform::create();
	beginEditCP(node);
	node->setCore( cam_trans );
	node->addChild( beacon );
	endEditCP(node);
	root->addChild( node );

	// finish scene graph
	endEditCP(root);

	// Camera
	osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
	cam->setBeacon( beacon );
	cam->setFov( 50 );
	cam->setNear( 0.1 );
	cam->setFar( 10000 );

	// Background
	osg::SolidBackgroundPtr background = osg::SolidBackground::create();

	// Viewport
	osg::ViewportPtr vp = osg::Viewport::create();
	vp->setCamera( cam );
	vp->setBackground( background );
	vp->setRoot( root );
	vp->setSize( 0,0, 1,1 );

	if ( with_window )
	{
		// GLUT init
		glutInitWindowSize( 400, 400 );		// before glutInit so user can
		glutInitWindowPosition( 100, 100 );	// override with comannd line args
		glutInit(&argc, argv);
		glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
		int winid = glutCreateWindow("Polygon Intersection Check Test");
		glutKeyboardFunc(key);
		glutVisibilityFunc(vis);
		glutReshapeFunc(reshape);
		glutDisplayFunc(display);
		glutMouseFunc(mouse);
		glutMotionFunc(motion);

		glutIdleFunc(display);

		glEnable( GL_DEPTH_TEST );
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );

		// Window
		osg::GLUTWindowPtr gwin;
		GLint glvp[4];
		glGetIntegerv( GL_VIEWPORT, glvp );
		gwin = osg::GLUTWindow::create();
		gwin->setId(winid);
		gwin->setSize( glvp[2], glvp[3] );
		win = gwin;
		win->addPort( vp );

		// Action
		render_action = osg::DrawAction::create();
		// trackball
		Vec3f min(-1,-1,-1), max(1,1,1);
		// root->updateVolume();
		// const osg::BoxVolume &vol = dynamic_cast<const osg::BoxVolume &>(root->getVolume());
		// // in the long term, the abstract volume will be able to provide min/max
		// vol.getBounds( min, max );
		trackball.setMode( osg::Trackball::OSGObject );
		float d = max[2] + (max[2]-min[2])*1.5;
		trackball.setStartPosition( 0, 0, d, true );
		trackball.setSum( true );
		trackball.setTranslationMode( osg::Trackball::OSGFree );

		// run...
		glutMainLoop();
	}
	else
	{
		// run in batch mode
		int phase = 0;
		do
			testcase( &phase );
		while ( phase > 0 );
	}

	return 0;
}
Ejemplo n.º 6
0
	void SimulationEngine::createChildVisualEntity(osg::NodePtr parentNode, 
		/*osg::TransformPtr trans,*/ const opal::ShapeData* data, const std::string& name, 
		const std::string& materialName)
	{
		// Create an Ogre SceneNode for the Entity.		
		osg::Matrix m;
		
		opal::Point3r offsetPos = data->offset.getPosition();
		//Ogre::Vector3 translationOffset(offsetPos[0], offsetPos[1], 
			//offsetPos[2]);
		opal::Quaternion offsetQuat = data->offset.getQuaternion();
		//Ogre::Quaternion rotationOffset;
		//rotationOffset.x = offsetQuat.x;
		//rotationOffset.y = offsetQuat.y;
		//rotationOffset.z = offsetQuat.z;
		//rotationOffset.w = offsetQuat.w;
		
		//Ogre::SceneNode* newChildNode = NULL;
		//Ogre::Entity* e = NULL;
		
		// OSG covention: we need one new node and transformation
		osg::NodePtr newChildNode; //= osg::Node::create();
		osg::TransformPtr newTransCore = osg::Transform::create();	
		
		osg::beginEditCP(newTransCore);
			m.setIdentity();
				
   			m.setTranslate(
   						(osg::Real32)offsetPos[0], 
   						(osg::Real32)offsetPos[1], 
						(osg::Real32)offsetPos[2]);
			
  			m.setRotate(
  						osg::Quaternion(
  							osg::Vec3f(
  								(osg::Real32)offsetQuat[1],
  								(osg::Real32)offsetQuat[2],
  								(osg::Real32)offsetQuat[3]), 
  							(osg::Real32)offsetQuat[0]));
  				
            newTransCore->setMatrix(m);
       	osg::endEditCP(newTransCore);
		
		switch(data->getType())
		{
			case opal::BOX_SHAPE:
			{				
				//newChildNode = parentNode->createChildSceneNode(name, 
					//translationOffset, rotationOffset);	

				// Scale the object according to the given dimensions.
				opal::Vec3r boxDim = static_cast<const opal::BoxShapeData*>
					(data)->dimensions;
					
				//Ogre::Vector3 dimensions(boxDim[0], boxDim[1], boxDim[2]);
				//newChildNode->scale(dimensions[0], dimensions[1], 
					//dimensions[2]);
					
				//create the geometry which we will assign a texture to
				newChildNode = osg::makeBox((osg::Real32)boxDim[0],
											(osg::Real32)boxDim[1],
											(osg::Real32)boxDim[2],1,1,1);

				// Create an Ogre Entity using a cube mesh.  This mesh must be 
				// stored as a box with dimensions 1x1x1.
				//e = mOgreSceneMgr->createEntity(name, "cube.mesh");
				//e->setMaterialName(materialName);

				// Keep the normals normalized even after scaling.
				//e->setNormaliseNormals(true);

				// Attach the Entity to the SceneNode.
				//newChildNode->attachObject(e);
				
				//osg::beginEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
				osg::beginEditCP(parentNode);
    				parentNode->setCore(newTransCore);
    				parentNode->addChild(newChildNode);
    			osg::endEditCP(parentNode);
				//osg::endEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);				
				  				
				break;
			}

			case opal::SPHERE_SHAPE:
			{
				//newChildNode = parentNode->createChildSceneNode(name, 
					//translationOffset, rotationOffset);

				// Scale the object according to the given dimensions.
				//Ogre::Real radius = static_cast<const opal::SphereShapeData*>
					//(data)->radius;
				//newChildNode->scale(radius, radius, radius);
				
				opal::real radius = static_cast<const opal::SphereShapeData*>
					(data)->radius;
					
				newChildNode = osg::makeSphere(3, (osg::Real32)radius);

				// Create an Ogre Entity using a sphere mesh.  This mesh must be 
				// stored as a sphere with radius 1.
				//e = mOgreSceneMgr->createEntity(name, "sphere.mesh");
				//e->setMaterialName(materialName);

				// Keep the normals normalized even after scaling.
				//e->setNormaliseNormals(true);

				// Attach the Entity to the SceneNode.
				//newChildNode->attachObject(e);
				
				//osg::beginEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
				osg::beginEditCP(parentNode);
    				parentNode->setCore(newTransCore);
    				parentNode->addChild(newChildNode);
    			osg::endEditCP(parentNode);
				//osg::endEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);				
								
				break;
			}
		
			case opal::CAPSULE_SHAPE:
			{
				osg::NodePtr capsule =  osg::Node::create();
        		osg::NodePtr topcap  =  osg::Node::create();
       			osg::NodePtr botcap  =  osg::Node::create();  
        		     
				// Create an Ogre SceneNode for the cylinder Entity.
				std::string subObjectName = "cylinder" + name;
				//newChildNode = parentNode->createChildSceneNode(
					//subObjectName, translationOffset, rotationOffset);

				// Scale the object according to the given dimensions.  This 
				// will also scale the transforms for the child nodes, but 
				// we disable the "inherit scale" option for child nodes 
				// here so the shapes themselves don't get scaled.
				//Ogre::Real radius = static_cast<const opal::CapsuleShapeData*>
					//(data)->radius;
				opal::real radius = static_cast<const opal::CapsuleShapeData*>
					(data)->radius;
				//Ogre::Real length = static_cast<const opal::CapsuleShapeData*>
					//(data)->length;
				opal::real length = static_cast<const opal::CapsuleShapeData*>
					(data)->length;
				//newChildNode->scale(radius, radius, length);

				osg::NodePtr cyl = osg::makeCylinder((osg::Real32)length,
													 (osg::Real32)radius,
													 40,true,false,false); 
				
				// This mesh must be stored as a cylinder with length 1 and 
				// radius 1.
				//e = mOgreSceneMgr->createEntity(subObjectName, "cylinder.mesh");
				//e->setMaterialName(materialName);
				//e->setNormaliseNormals(true);
				//newChildNode->attachObject(e);

				// The spheres must use separate scene nodes that are offset 
				// from the cylinder's scene node.

				// This mesh must be stored as a sphere with radius 1.
				subObjectName = "sphere0" + name;
				//Ogre::SceneNode* sphereNode = newChildNode->createChildSceneNode(
					//subObjectName);
				//sphereNode->setInheritScale(false);
				//sphereNode->translate(0, 0, -0.5);
				//sphereNode->scale(radius, radius, radius);
				//e = mOgreSceneMgr->createEntity(subObjectName, "sphere.mesh");
				//e->setMaterialName(materialName);
				//e->setNormaliseNormals(true);
				//sphereNode->attachObject(e);
				
				osg::NodePtr topGeo = osg::makeSphere(3,(osg::Real32)radius);     
				//one geometry and one transform node        
        		osg::TransformPtr topTr = osg::Transform::create();
        		osg::Matrix _m;
  				//osg::beginEditCP(tChimney, osg::Transform::MatrixFieldMask);
  				osg::beginEditCP(topTr);
      				_m.setIdentity();
      				_m.setTranslate(0,(osg::Real32)length/2.0,0);
      				topTr->setMatrix(_m);
      			osg::endEditCP(topTr);
  				//osg::endEditCP(tChimney, osg::Transform::MatrixFieldMask);

  				//osg::beginEditCP(chimneyTrans, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
  				osg::beginEditCP(topcap);
      				topcap->setCore(topTr);
      				topcap->addChild(topGeo);
      			osg::endEditCP(topcap);
  				//osg::endEditCP(chimneyTrans, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
  		   		
				subObjectName = "sphere1" + name;
				//sphereNode = newChildNode->createChildSceneNode(subObjectName);
				//sphereNode->setInheritScale(false);
				//sphereNode->translate(0, 0, 0.5);
				//sphereNode->scale(radius, radius, radius);
				//e = mOgreSceneMgr->createEntity(subObjectName, "sphere.mesh");
				//e->setMaterialName(materialName);
				//e->setNormaliseNormals(true);
				//sphereNode->attachObject(e);
				
				osg::NodePtr botGeo = osg::makeSphere(3,(osg::Real32)radius);
				osg::TransformPtr botTr = osg::Transform::create();
  				osg::Matrix _n;
  				//osg::beginEditCP(tChimney, osg::Transform::MatrixFieldMask);
  				osg::beginEditCP(botTr);
      				_n.setIdentity();
      				_n.setTranslate(0,-(osg::Real32)length/2.0,0);
      				botTr->setMatrix(_n);
      			osg::endEditCP(botTr);
  				//osg::endEditCP(tChimney, osg::Transform::MatrixFieldMask);

  				//osg::beginEditCP(chimneyTrans, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
  				osg::beginEditCP(botcap);
      				botcap->setCore(botTr);
      				botcap->addChild(botGeo);
      			osg::endEditCP(botcap);
  				//osg::endEditCP(chimneyTrans, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
  		
  				// Finally Compose everything to a Capsule!!
        		osg::beginEditCP(capsule);
        			capsule->setCore(osg::Group::create());
    				capsule->addChild(cyl);
    				capsule->addChild(topcap);
    				capsule->addChild(botcap);
    			osg::endEditCP(capsule);
    			
    			// OK send to new scene noe
    			newChildNode = capsule;
    			
    			//osg::beginEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);
				osg::beginEditCP(parentNode);
    				parentNode->setCore(newTransCore);
    				parentNode->addChild(newChildNode);
    			osg::endEditCP(parentNode);
				//osg::endEditCP(parentNode, osg::Node::CoreFieldMask | osg::Node::ChildrenFieldMask);				
			
				break;
			}
		
			default:
				assert(false);
				break;
		}
	}
Ejemplo n.º 7
0
int main( int argc, char *argv[] )
{

	// OSG init
	osg::osgLog().setLogLevel(osg::LOG_WARNING);
	osg::osgInit(argc, argv);

	// parse command line options
	parsecommandline( argc, argv );

	// disable display lists
	osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
	osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
    if ( pGeoProto != osg::NullFC )
        pGeoProto->setDlistCache(false);

	// create the graph
	osg::NodePtr node;

	// root
	root = osg::Node::create();
	beginEditCP(root);
	root->setCore( osg::Group::create() );

	// beacon for camera and light
	osg::NodePtr beacon;
	beacon = osg::Node::create();
	beginEditCP(beacon);
	beacon->setCore( osg::Group::create() );
	endEditCP(beacon);

	// light
	light_node = osg::Node::create();
	osg::DirectionalLightPtr light = osg::DirectionalLight::create();
	beginEditCP( light_node );
	light_node->setCore( light );
	root->addChild( light_node );
	beginEditCP(light);
	light->setAmbient( .3, .3, .3, 1 );
	light->setDiffuse( 1, 1, 1, 1 );
	light->setDirection(0,0,1);
	light->setBeacon( beacon );
	endEditCP(light);

	// transformation, parent of beacon
	node = osg::Node::create();
	cam_trans = osg::Transform::create();
	beginEditCP(node);
	node->setCore( cam_trans );
	node->addChild( beacon );
	endEditCP(node);
	root->addChild( node );

	// Camera
	osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
	cam->setBeacon( beacon );
	cam->setFov( 50 );
	cam->setNear( 0.1 );
	cam->setFar( 10000 );

	// Background
	osg::SolidBackgroundPtr background = osg::SolidBackground::create();
	if ( White_background )
	{
		beginEditCP( background );
		background->setColor(osg::Color3f(1,1,1));
		endEditCP( background );
	}

	// Viewport
	osg::ViewportPtr vp = osg::Viewport::create();
	vp->setCamera( cam );
	vp->setBackground( background );
	vp->setRoot( root );
	vp->setSize( 0,0, 1,1 );

	if ( With_window )
	{
		// GLUT init
		glutInitWindowSize( 400, 400 );		// before glutInit so user can
		glutInitWindowPosition( 100, 100 );	// override with comannd line args
		glutInit(&argc, argv);
		glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
		int winid = glutCreateWindow("Collision Benchmark");
		glutKeyboardFunc(key);
		glutVisibilityFunc(vis);
		glutReshapeFunc(reshape);
		glutDisplayFunc(display);
		glutMouseFunc(mouse);
		glutMotionFunc(motion);

		glutIdleFunc(display);

		glEnable( GL_DEPTH_TEST );
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

		// Window
		osg::GLUTWindowPtr gwin;
		GLint glvp[4];
		glGetIntegerv( GL_VIEWPORT, glvp );
		gwin = osg::GLUTWindow::create();
		gwin->setId(winid);
		gwin->setSize( glvp[2], glvp[3] );
		win = gwin;
		win->addPort( vp );

		// Action
		render_action = osg::DrawAction::create();

		// trackball
			Vec3f min(-2.5,-2.5,-2.5), max(2.5,2.5,2.5);
		trackball.setMode( osg::Trackball::OSGObject );
			float d = max[2] + (max[2]-min[2]);
		trackball.setStartPosition( 0, 0, d, true );
		trackball.setSum( true );
		trackball.setTranslationMode( osg::Trackball::OSGFree );
	}

	// create moving objects
	if ( geom_type != OBJ_FILE )
		createGeom( geom_type, Complexity, &fixed_node, &fixed_geom );
	// else: has been loaded from file
	light_node->addChild( fixed_node );

	if ( geom_type != OBJ_FILE )
		createGeom( geom_type, Complexity, &moving_node, &moving_geom );


	//#define DOPTREE_NUM_ORI 16

	double pi = 3.141592653589793f;
	vector<Vec3f> translates;
	vector<Vec3f> rotation_xyzs;
	vector<float> rotates;
	//string config("");
	if(configFile.length() == 0)
	{
		printf("config file is null, use -r configFileName\n");
		return 0;
	}

	ifstream fin(configFile.data());
    string line;
    int i = 0;
    int angle;
    float x,y,z;
    while(std::getline(fin, line))
    {
        stringstream ss;
        ss << line;
        if(i & 0x1) // tranls
        {
            ss >> x >> y >> z;
            translates.push_back(Vec3f(x,y,z));
            
        }else //angle rot
        {
Ejemplo n.º 8
0
NodePtr createScoreBoards()
{
	GeometryPtr geo;
	NodePtr bg;
	SimpleMaterialPtr m;
	ScoreBoard1 = new TextStuff() ;
	ScoreBoard2 = new TextStuff() ;

	// First get the global group node
    OSG::NodePtr scoreBoardsNodePtr = OSG::Node::create();
    scoreBoardsNodePtr->setCore(OSG::Group::create());

    // Setup text 1
    ScoreBoard1->initialize();
    ScoreBoard1->updateFace();
    ScoreBoard1->updateScore(0,0);
    // Setup text 2
    ScoreBoard2->initialize();
    ScoreBoard2->updateFace();
    ScoreBoard2->updateScore(0,0);

	////////// 1 /////////
	// make its transform
	TransformPtr trans1;
    NodePtr trans_node1 = makeCoredNode<Transform>(&trans1);
    beginEditCP(trans1);
		trans1->getMatrix().setTransform(Vec3f(0,4,-10.5),Quaternion( Vec3f(0,1,0),deg2rad(0)));
    endEditCP(trans1);

	// make geometry
	bg = makePlane(9.3, 1, 8,2);
	 m= SimpleMaterial::create();
    beginEditCP(m);
    {		
        m->setAmbient      (Color3f(0,0,0));
        m->setDiffuse      (Color3f(0.0,0.0,0.0));
    }
    endEditCP  (m);  
	geo = GeometryPtr::dcast(bg->getCore());  
    beginEditCP(geo);
		geo->setMaterial(m);
    beginEditCP(geo);

	beginEditCP(bg);
	bg->addChild(ScoreBoard1->mRootNode);
	endEditCP(bg);

	beginEditCP(trans_node1);
		trans_node1->addChild(bg);
	endEditCP(trans_node1);

	////////// 2 /////////
	// make its transform
	TransformPtr trans2;
    NodePtr trans_node2 = makeCoredNode<Transform>(&trans2);
    beginEditCP(trans2);
		trans2->getMatrix().setTransform(Vec3f(0,4,10.5),Quaternion( Vec3f(0,1,0),deg2rad(180)));
    endEditCP(trans2);

	// make geometry
	bg = makePlane(9.3, 1, 8,2);
	m = SimpleMaterial::create();
    beginEditCP(m);
    {		
        m->setAmbient      (Color3f(0,0,0));
        m->setDiffuse      (Color3f(0.0,0.0,0.0));
    }
    endEditCP  (m);  
	geo = GeometryPtr::dcast(bg->getCore());  
    beginEditCP(geo);
		geo->setMaterial(m);
    beginEditCP(geo);

	beginEditCP(bg);
	bg->addChild(ScoreBoard2->mRootNode);
	endEditCP(bg);

	beginEditCP(trans_node2);
		trans_node2->addChild(bg);
	endEditCP(trans_node2);


	beginEditCP(scoreBoardsNodePtr);
		scoreBoardsNodePtr->addChild(trans_node1);
		scoreBoardsNodePtr->addChild(trans_node2);
	endEditCP(scoreBoardsNodePtr);
  

    return scoreBoardsNodePtr;
}