Example #1
0
void finishBullet() {
	//delete collision shapes
	for (int j=0;j<collisionShapes.size();j++)
	{
		btCollisionShape* shape = collisionShapes[j];
		collisionShapes[j] = 0;
		delete shape;
	}

	//delete dynamics world
	delete dynamicsWorld;

	//delete solver
	delete solver;

	//delete broadphase
	delete overlappingPairCache;

	//delete dispatcher
	delete dispatcher;

	delete collisionConfiguration;

	//next line is optional: it will be cleared by the destructor when the array goes out of scope
	collisionShapes.clear();

}
Example #2
0
/// removes all objects and shapes from the world
void TerrainDemo::clearWorld(void)
{
	//remove the rigidbodies from the dynamics world and delete them
	int i;
	for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
	{
		btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body = btRigidBody::upcast(obj);
		if (body && body->getMotionState())
		{
			delete body->getMotionState();
		}
		m_dynamicsWorld->removeCollisionObject( obj );
		delete obj;
	}

	//delete collision shapes
	for (int j=0;j<m_collisionShapes.size();j++)
	{
		btCollisionShape* shape = m_collisionShapes[j];
		delete shape;
	}
	m_collisionShapes.clear();

	// delete raw heightfield data
	delete m_rawHeightfieldData;
	m_rawHeightfieldData = NULL;
}
void ExitBulletPhysics()
{
	//cleanup in the reverse order of creation/initialization

	for (int i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0; i--) //remove the rigidbodies from the dynamics world and delete them
	{
		btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body = btRigidBody::upcast(obj);
		if(body && body->getMotionState())
			delete body->getMotionState();

		m_dynamicsWorld->removeCollisionObject(obj);
		delete obj;
	}


	for (int j=0; j<m_collisionShapes.size(); j++) //delete collision shapes
	{
		btCollisionShape* shape = m_collisionShapes[j];
		delete shape;
	}

	m_collisionShapes.clear();
	delete m_dynamicsWorld;
	delete m_solver;
	delete m_broadphase;
	delete m_dispatcher;
	delete m_collisionConfiguration;
}
Example #4
0
ImportUrdfSetup::ImportUrdfSetup(struct GUIHelperInterface* helper, int option, const char* fileName)
	:CommonMultiBodyBase(helper)
{
	m_data = new ImportUrdfInternalData;

	if (option==1)
	{
		m_useMultiBody = true;
	} else
	{
		m_useMultiBody = false;
	}

	static int count = 0;
	if (fileName)
	{
		setFileName(fileName);
	} else
	{
		gFileNameArray.clear();
		


		//load additional urdf file names from file

		FILE* f = fopen("urdf_files.txt","r");
		if (f)
		{
			int result;
			//warning: we don't avoid string buffer overflow in this basic example in fscanf
			char fileName[1024];
			do
			{
				result = fscanf(f,"%s",fileName);
                b3Printf("urdf_files.txt entry %s",fileName);
				if (result==1)
				{
					gFileNameArray.push_back(fileName);
				}
			} while (result==1);

			fclose(f);
		}
		
		if (gFileNameArray.size()==0)
		{
			gFileNameArray.push_back("r2d2.urdf");

		}

		int numFileNames = gFileNameArray.size();

		if (count>=numFileNames)
		{
			count=0;
		}
		sprintf(m_fileName,"%s",gFileNameArray[count++].c_str());
	}
}
Example #5
0
 virtual void flushLines()
 {
     int sz = m_linePoints.size();
     if (sz)
     {
         float debugColor[4];
         debugColor[0] = m_currentLineColor.x();
         debugColor[1] = m_currentLineColor.y();
         debugColor[2] = m_currentLineColor.z();
         debugColor[3] = 1.f;
         m_glApp->m_renderer->drawLines(&m_linePoints[0].x,debugColor,
                                        m_linePoints.size(),sizeof(MyDebugVec3),
                                        &m_lineIndices[0],
                                        m_lineIndices.size(),
                                        1);
         m_linePoints.clear();
         m_lineIndices.clear();
     }
 }
Example #6
0
void	Planar2D::exitPhysics()
{


    //cleanup in the reverse order of creation/initialization

    //remove the rigidbodies from the dynamics world and delete them
    int i;
    if (m_dynamicsWorld)
        for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ; i--)
        {
            btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
            btRigidBody* body = btRigidBody::upcast(obj);
            if (body && body->getMotionState())
            {
                delete body->getMotionState();
            }
            m_dynamicsWorld->removeCollisionObject( obj );
            delete obj;
        }

    //delete collision shapes
    for (int j=0; j<m_collisionShapes.size(); j++)
    {
        btCollisionShape* shape = m_collisionShapes[j];
        delete shape;
    }
    m_collisionShapes.clear();

    delete m_dynamicsWorld;

    delete m_solver;

    delete m_broadphase;

    delete m_dispatcher;

    delete m_collisionConfiguration;

    delete m_convexAlgo2d;
    delete m_pdSolver;
    delete m_simplexSolver;
    delete m_box2dbox2dAlgo;

    m_dynamicsWorld = 0;
    m_solver = 0;
    m_broadphase = 0;
    m_dispatcher = 0;
    m_collisionConfiguration = 0;
    m_convexAlgo2d=0;
    m_pdSolver = 0;
    m_simplexSolver = 0;
    m_box2dbox2dAlgo = 0;
}
Example #7
0
void remove_physics(){
	if(plane)
		delete plane;
	if(m_shootBoxShape)
		delete m_shootBoxShape;
	if(m_fluidSolverCPU)
		delete m_fluidSolverCPU;
	if(m_emitter)
		delete m_emitter;
	if(m_fluidWorld)
		delete m_fluidWorld;
	if(m_collisionConfiguration)
		delete m_collisionConfiguration;
	if(m_solver)
		delete m_solver;
	if(m_dispatcher)
		delete m_dispatcher;
	if(m_broadphase)
		delete m_broadphase;
	m_fluids.clear();
	m_collisionShapes.clear();
	m_demos.clear();
}
OpenGLExampleBrowser::~OpenGLExampleBrowser()
{
	deleteDemo();
	for (int i = 0; i < m_internalData->m_nodes.size(); i++)
	{
		delete m_internalData->m_nodes[i];
	}
	delete m_internalData->m_handler2;
	for (int i = 0; i < m_internalData->m_handlers.size(); i++)
	{
		delete m_internalData->m_handlers[i];
	}
	m_internalData->m_handlers.clear();
	m_internalData->m_nodes.clear();
	delete s_parameterInterface;
	s_parameterInterface = 0;
	delete s_app->m_2dCanvasInterface;
	s_app->m_2dCanvasInterface = 0;

#ifndef BT_NO_PROFILE
	destroyProfileWindow(m_internalData->m_profWindow);
#endif

	m_internalData->m_gui->exit();
	



	delete m_internalData->m_gui;
	delete m_internalData->m_gwenRenderer;
	delete m_internalData->m_myTexLoader;




	
	delete m_internalData->m_app;
	s_app = 0;
	
	



	delete m_internalData;
    
	gFileImporterByExtension.clear();
	gAllExamples = 0;

	
}
    virtual void    exitPhysics()
    {
        b3Printf("exitPhysics, stopping threads");
       	bool blockingWait =false;
       	 int arg0,arg1;
       	   
        args.m_cs->lock();
        //terminate all threads
        args.m_cs->setSharedParam(1,MAGIC_RESET_NUMBER);
        args.m_cs->unlock();
       	   
        if (blockingWait)
        {
            for (int i=0;i<m_numThreads;i++)
            {
                m_threadSupport->waitForResponse(&arg0,&arg1);
                printf("finished waiting for response: %d %d\n", arg0,arg1);
            }
        } else
        {
            int numActiveThreads = m_numThreads;
            while (numActiveThreads)
            {
                if (m_threadSupport->isTaskCompleted(&arg0,&arg1,0))
                {
                    numActiveThreads--;
                    printf("numActiveThreads = %d\n",numActiveThreads);

                } else
                {
    //				printf("polling..");
                }
            };
        }
        
        delete m_threadSupport;
        
        b3Printf("Threads stopped");
        for (int i=0;i<m_jobs.size();i++)
        {
         delete m_jobs[i];
        }
        m_jobs.clear();
        	
    }
Example #10
0
    static void Deinit() {
        int i;
        for (i = dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
		{
			btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
			btRigidBody* body = btRigidBody::upcast(obj);
			if (body && body->getMotionState())
			{
				delete body->getMotionState();
			}
			dynamicsWorld->removeCollisionObject( obj );
			delete obj;
		}
        
		for (int j=0;j<collisionShapes.size();j++) {
			btCollisionShape* shape = collisionShapes[j];
			collisionShapes[j] = 0;
			delete shape;
		}
        collisionShapes.clear();
        
    }
Example #11
0
ImportMJCFSetup::ImportMJCFSetup(struct GUIHelperInterface* helper, int option, const char* fileName)
	: CommonMultiBodyBase(helper),
	  m_grav(-10),
	  m_upAxis(2)
{
	m_data = new ImportMJCFInternalData;

	m_useMultiBody = true;

	static int count = 0;
	if (fileName)
	{
		setFileName(fileName);
	}
	else
	{
		gMCFJFileNameArray.clear();

		//load additional MJCF file names from file

		FILE* f = fopen("mjcf_files.txt", "r");
		if (f)
		{
			int result;
			//warning: we don't avoid string buffer overflow in this basic example in fscanf
			char fileName[1024];
			do
			{
				result = fscanf(f, "%s", fileName);
				b3Printf("mjcf_files.txt entry %s", fileName);
				if (result == 1)
				{
					gMCFJFileNameArray.push_back(fileName);
				}
			} while (result == 1);

			fclose(f);
		}

		if (gMCFJFileNameArray.size() == 0)
		{
			gMCFJFileNameArray.push_back("mjcf/humanoid.xml");

			gMCFJFileNameArray.push_back("MPL/MPL.xml");

			gMCFJFileNameArray.push_back("mjcf/inverted_pendulum.xml");
			gMCFJFileNameArray.push_back("mjcf/ant.xml");
			gMCFJFileNameArray.push_back("mjcf/hello_mjcf.xml");

			gMCFJFileNameArray.push_back("mjcf/cylinder.xml");
			gMCFJFileNameArray.push_back("mjcf/cylinder_fromtoX.xml");
			gMCFJFileNameArray.push_back("mjcf/cylinder_fromtoY.xml");
			gMCFJFileNameArray.push_back("mjcf/cylinder_fromtoZ.xml");

			gMCFJFileNameArray.push_back("mjcf/capsule.xml");
			gMCFJFileNameArray.push_back("mjcf/capsule_fromtoX.xml");
			gMCFJFileNameArray.push_back("mjcf/capsule_fromtoY.xml");
			gMCFJFileNameArray.push_back("mjcf/capsule_fromtoZ.xml");

			gMCFJFileNameArray.push_back("mjcf/hopper.xml");
			gMCFJFileNameArray.push_back("mjcf/swimmer.xml");
			gMCFJFileNameArray.push_back("mjcf/reacher.xml");
		}

		int numFileNames = gMCFJFileNameArray.size();

		if (count >= numFileNames)
		{
			count = 0;
		}
		sprintf(m_fileName, "%s", gMCFJFileNameArray[count++].c_str());
	}
}
Example #12
0
void ForkLiftDemo::exitPhysics()
{
		//cleanup in the reverse order of creation/initialization

	//remove the rigidbodies from the dynamics world and delete them
	int i;
	for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
	{
		btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body = btRigidBody::upcast(obj);
		if (body && body->getMotionState())
		{

			while (body->getNumConstraintRefs())
			{
				btTypedConstraint* constraint = body->getConstraintRef(0);
				m_dynamicsWorld->removeConstraint(constraint);
				delete constraint;
			}
			delete body->getMotionState();
			m_dynamicsWorld->removeRigidBody(body);
		} else
		{
			m_dynamicsWorld->removeCollisionObject( obj );
		}
		delete obj;
	}

	//delete collision shapes
	for (int j=0;j<m_collisionShapes.size();j++)
	{
		btCollisionShape* shape = m_collisionShapes[j];
		delete shape;
	}
	m_collisionShapes.clear();

	delete m_indexVertexArrays;
	delete m_vertices;

	//delete dynamics world
	delete m_dynamicsWorld;
	m_dynamicsWorld=0;

	delete m_vehicleRayCaster;
	m_vehicleRayCaster = 0;

	delete m_vehicle;
	m_vehicle=0;
	
	delete m_wheelShape;
	m_wheelShape=0;

	//delete solver
	delete m_constraintSolver;
	m_constraintSolver=0;

	//delete broadphase
	delete m_overlappingPairCache;
	m_overlappingPairCache=0;

	//delete dispatcher
	delete m_dispatcher;
	m_dispatcher=0;

	delete m_collisionConfiguration;
	m_collisionConfiguration=0;

}
Example #13
0
			void shutdown()
			{
				// remove all constraints from objects
				for (int i = constraints.size()-1; i >= 0; --i)
				{
					MEMORY2_DELETE(*physics_allocator, constraints[i]);
				}
				constraints.clear();



				for( int i = dynamics_world->getNumCollisionObjects()-1; i >= 0; --i )
				{
					btCollisionObject * obj = dynamics_world->getCollisionObjectArray()[i];
					btRigidBody * body = btRigidBody::upcast(obj);
					if ( body && body->getMotionState() )
					{
						delete body->getMotionState();
					}
					dynamics_world->removeCollisionObject( obj );
					delete obj;
				}

				//delete collision shapes
//				LOGV("total collision shapes: %ld\n", (unsigned int)collision_shapes.size());
				for ( int j = 0; j < collision_shapes.size(); j++ )
				{
					btCollisionShape* shape = collision_shapes[j];
					if (shape)
					{
						collision_shapes[j] = 0;
						delete shape;
					}
				}

				dynamics_world->setDebugDrawer(0);
				MEMORY2_DELETE(*physics_allocator, debug_renderer);

				//delete dynamics world
				delete dynamics_world;

				//delete solver
				delete constraint_solver;

				//delete broadphase
				//delete mPairCache;
				delete broadphase;

				//delete dispatcher
				delete dispatcher;

				// delete the collision configuration
				delete collision_config;

				//next line is optional: it will be cleared by the destructor when the array goes out of scope
				collision_shapes.clear();


				// cleanup controllers
				//		delete _controller;
			}