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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
0
CameraPtr Camera::init()
{
   // Create a transform to contain the location and orientation of the camera.
   mTransform = OSG::Transform::create();

   OSG::NodePtr beacon = OSG::Node::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor be(beacon, OSG::Node::CoreFieldMask);
#endif
   beacon->setCore(mTransform);

   mLeftTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor lte(mLeftTexture);
   mLeftTexture->setEnvMode(GL_MODULATE);
#else
   mLeftTexEnv = OSG::TextureEnvChunk::create();
   mLeftTexEnv->setEnvMode(GL_MODULATE);
#endif

   mRightTexture = tex_chunk_t::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor rte(mRightTexture);
   mRightTexture->setEnvMode(GL_MODULATE);
#else
   mRightTexEnv = OSG::TextureEnvChunk::create();
   mRightTexEnv->setEnvMode(GL_MODULATE);
#endif

   mCurrentTexture = mLeftTexture;
#if OSG_MAJOR_VERSION >= 2
   mCurrentTexEnv = mLeftTexEnv;
#endif

   // setup camera
   mCamera = OSG::PerspectiveCamera::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor ce(mCamera);
#endif
   mCamera->setFov(
#if OSG_MAJOR_VERSION < 2
      OSG::osgdegree2rad(60.0)
#else
      OSG::osgDegree2Rad(60.0)
#endif
   );
   mCamera->setNear(0.01);
   mCamera->setFar(10000);
   mCamera->setBeacon(beacon);

   mLeftImage = OSG::Image::create();
   mRightImage = OSG::Image::create();

   OSG::ImagePtr img;

   // Set up FBO textures.
   img = mLeftImage;
   mLeftTexture->setMinFilter(GL_LINEAR);
   mLeftTexture->setMagFilter(GL_LINEAR);
   mLeftTexture->setTarget(GL_TEXTURE_2D);
   mLeftTexture->setInternalFormat(GL_RGBA8);
   mLeftTexture->setImage(img);

   img = mRightImage;
   mRightTexture->setMinFilter(GL_LINEAR);
   mRightTexture->setMagFilter(GL_LINEAR);
   mRightTexture->setTarget(GL_TEXTURE_2D);
   mRightTexture->setInternalFormat(GL_RGBA8);
   mRightTexture->setImage(img);

   mCurrentImage = mLeftImage;

   return shared_from_this();
}
Ejemplo n.º 7
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;
}