Ejemplo n.º 1
0
int main(int argc, char* argv[])
{
		
	CommandLineArgs args(argc,argv);

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}

	args.GetCmdLineArgument("enable_interop", useInterop);
	printf("useInterop=%d\n",useInterop);

	args.GetCmdLineArgument("enable_convexheightfield", useConvexHeightfield);
	printf("enable_convexheightfield=%d\n",useConvexHeightfield);

	args.GetCmdLineArgument("enable_gpusap", useSapGpuBroadphase);
	printf("enable_gpusap=%d\n",useSapGpuBroadphase);

	args.GetCmdLineArgument("pause_simulation", pauseSimulation);
	printf("pause_simulation=%d\n",pauseSimulation);
	args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X);
	args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y);
	args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z);

	args.GetCmdLineArgument("x_gap", X_GAP);
	args.GetCmdLineArgument("y_gap", Y_GAP);
	args.GetCmdLineArgument("z_gap", Z_GAP);
	printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
	printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP);
	
	args.GetCmdLineArgument("enable_static", keepStaticObjects);
	printf("enable_static=%d\n",keepStaticObjects);	

	
	char* tmpfile = 0;
	args.GetCmdLineArgument("load_bulletfile", tmpfile );
	if (tmpfile)
		fileName = tmpfile;

	printf("load_bulletfile=%s\n",fileName);

	
	printf("\n");
#ifdef _WIN32
	Win32OpenGLWindow* window = new Win32OpenGLWindow();
#else
    MacOpenGLWindow* window = new MacOpenGLWindow();
#endif
    
	window->init(1024,768);
#ifdef _WIN32
	GLenum err = glewInit();
#endif
    
	window->startRendering();
	window->endRendering();

	GLInstancingRenderer render;

	
		


	CLPhysicsDemo demo(window);
	
	
	demo.init(-1,-1,useInterop);

	render.InitShaders();

	if (useInterop)
		demo.setupInterop();

	createScene(render, demo, useConvexHeightfield,fileName);
		

	printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
	printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
	


	render.writeTransforms();


    
    window->startRendering();
    render.RenderScene();
    window->endRendering();
    
	while (!window->requestedExit())
	{
		CProfileManager::Reset();
		
		if (shootObject)
		{
			shootObject = false;
			
			btVector3 linVel;// = (m_cameraPosition-m_cameraTargetPosition).normalize()*-100;

			int x,y;
			window->getMouseCoordinates(x,y);
			render.getMouseDirection(&linVel[0],x,y);
			linVel.normalize();
			linVel*=100;

//			btVector3 startPos;
			demo.setObjectLinearVelocity(&linVel[0],0);
			float orn[4] = {0,0,0,1};
			float pos[4] = {m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2],1};
			
//			demo.setObjectTransform(pos,orn,0);
			render.writeSingleTransform(pos,orn,0);
//			createScene(render, demo);
//			printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
//			printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
//			render.writeTransforms();
		}
		if (!pauseSimulation )
			demo.stepSimulation();


		window->startRendering();
		render.RenderScene();
		window->endRendering();

		{
			BT_PROFILE("glFinish");
			glFinish();
		}

		CProfileManager::Increment_Frame_Counter();

		

		
		
		 if (printStats && !pauseSimulation)
		 {
			static int count = 3;
			count--;
			if (count<0)
			{
				count = 100;
				CProfileManager::dumpAll();
				printf("total broadphase pairs= %d\n", numPairsTotal);
				printf("numPairsOut (culled)  = %d\n", numPairsOut);
				//printStats  = false;
			} else
			{
//				printf(".");
			}
		 }
		

	}

	
	demo.cleanup();

	render.CleanupShaders();
	window->exit();
	delete window;
	
	
	
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
		
	CommandLineArgs args(argc,argv);

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}

	args.GetCmdLineArgument("enable_interop", useInterop);
	printf("useInterop=%d\n",useInterop);

	args.GetCmdLineArgument("enable_convexheightfield", useConvexHeightfield);
	printf("enable_convexheightfield=%d\n",useConvexHeightfield);

	args.GetCmdLineArgument("enable_gpusap", useSapGpuBroadphase);
	printf("enable_gpusap=%d\n",useSapGpuBroadphase);

	args.GetCmdLineArgument("pause_simulation", pauseSimulation);
	printf("pause_simulation=%d\n",pauseSimulation);
	args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X);
	args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y);
	args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z);

	args.GetCmdLineArgument("x_gap", X_GAP);
	args.GetCmdLineArgument("y_gap", Y_GAP);
	args.GetCmdLineArgument("z_gap", Z_GAP);
	printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
	printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP);
	
	args.GetCmdLineArgument("enable_static", keepStaticObjects);
	printf("enable_static=%d\n",keepStaticObjects);	

	int preferred_platform = -1;
	int preferred_device = -1;

	args.GetCmdLineArgument("cl_device", preferred_device);
	args.GetCmdLineArgument("cl_platform", preferred_platform);

	
	
	char* tmpfile = 0;
	args.GetCmdLineArgument("load_bulletfile", tmpfile );
	if (tmpfile)
		bulletFileName = tmpfile;

	printf("load_bulletfile=%s\n",bulletFileName);

	benchmark=args.CheckCmdLineFlag("benchmark");
	

	
	printf("\n");
#ifdef _WIN32
	Win32OpenGLWindow* window = new Win32OpenGLWindow();
#else
    MacOpenGLWindow* window = new MacOpenGLWindow();
#endif
	btgWindowConstructionInfo wci;
	window->createWindow(wci);    

#ifdef _WIN32
	GLenum err = glewInit();
#endif
    
	window->startRendering();
	window->endRendering();

	GLInstancingRenderer render(MAX_CONVEX_BODIES_CL);

	
		


	CLPhysicsDemo demo(render.getMaxShapeCapacity(), MAX_CONVEX_BODIES_CL);
	
	
	demo.init(preferred_device,preferred_platform,useInterop);
	

	render.InitShaders();

	if (useInterop)
	{
#ifdef _WIN32
		g_interopBuffer = new btOpenCLGLInteropBuffer(g_cxMainContext,g_cqCommandQue,render.getInternalData()->m_vbo);
	clFinish(g_cqCommandQue);
#endif
	}

	createScene(render, demo, useConvexHeightfield,bulletFileName);
		

	printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
	printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
	
	FILE* f = 0;
	
	if (benchmark)
	{
		char fileName[1024];
		
#ifdef _WIN32
			SYSTEMTIME time;
			GetLocalTime(&time);
			char buf[1024];
			DWORD dwCompNameLen = 1024;
			if (0 != GetComputerName(buf, &dwCompNameLen)) 
			{
				printf("%s", buf);
			} else	
			{
				printf("unknown", buf);
			}
			sprintf(fileName,"%s_%s_%s_time_%d-%d-%d_date_%d-%d-%d.csv",g_deviceName,buf,"gpu_rigidbody_pipeline2",time.wHour,time.wMinute,time.wSecond,time.wDay,time.wMonth,time.wYear);
			
			printf("Open file %s\n", fileName);
#else
		char fileName[1024];
		sprintf(fileName,"%s_%s_%d_%d_%d.txt",g_deviceName,"gpu_rigidbody_pipeline2",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
		printf("Open file %s\n", fileName);
#endif //_WIN32

		f=fopen(fileName,"w");
		//if (f)
		//	fprintf(f,"%s (%dx%dx%d=%d),\n",  g_deviceName,NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z, NUM_OBJECTS_X*NUM_OBJECTS_Y*NUM_OBJECTS_Z);
	}


	render.writeTransforms();


    
    window->startRendering();
    render.RenderScene();
    window->endRendering();

	window->setMouseMoveCallback(btDefaultMouseMoveCallback);
	window->setMouseButtonCallback(btDefaultMouseButtonCallback);
	window->setWheelCallback(btDefaultWheelCallback);
	window->setKeyboardCallback(btDefaultKeyboardCallback);
    
	while (!window->requestedExit())
	{
		CProfileManager::Reset();
		
		if (shootObject)
		{
			shootObject = false;
			
			btVector3 linVel;// = (m_cameraPosition-m_cameraTargetPosition).normalize()*-100;

			int x,y;
			window->getMouseCoordinates(x,y);
			render.getMouseDirection(&linVel[0],x,y);
			linVel.normalize();
			linVel*=100;

//			btVector3 startPos;
			demo.setObjectLinearVelocity(&linVel[0],0);
			float orn[4] = {0,0,0,1};
			float pos[4];
			render.getCameraPosition(pos);
			
//			demo.setObjectTransform(pos,orn,0);
			render.writeSingleInstanceTransformToGPU(pos,orn,0);
//			createScene(render, demo);
//			printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
//			printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
//			render.writeTransforms();
		}
		if (!pauseSimulation )
		{
			GL2CL(demo,render);
			demo.stepSimulation();

			{
				BT_PROFILE("copyTransformsToBVO");
			
				copyTransformsToBVO(gFpIO, demo.getBodiesGpu());
			}

			CL2GL(demo);
		}


		window->startRendering();
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		render.RenderScene();
		window->endRendering();

		{
			BT_PROFILE("glFinish");
			glFinish();
		}

		CProfileManager::Increment_Frame_Counter();

		

		if (benchmark && f)
		{
			static int count=0;
			
			if (count>2 && count<102)
			{
				DumpSimulationTime(f);
			}
			if (count>=102)
				window->setRequestExit();
			count++;
		}

		
		
		 if (printStats && !pauseSimulation)
		 {
			static int count = 10;
			count--;
			if (count<=0)
			{
				count = 100;

				CProfileManager::dumpAll();
				printf("total broadphase pairs= %d\n", numPairsTotal);
				printf("numPairsOut (culled)  = %d\n", numPairsOut);
				
			} else
			{
//				printf(".");
			}
		 }
		

	}

	
	demo.cleanup();

#ifdef _WIN32
	delete g_interopBuffer;
#endif

	render.CleanupShaders();
	
	window->closeWindow();
	delete window;
	
	
	
	return 0;
}