//----------------------------------------------------------------------------
//  Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsSimulate
//
/// Implementation of JNI function to update the simulation and view parameters,
/// perform one simulation step, and redraw the scene.
///
/// @param  env     Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsSimulate( JNIEnv*  env )
{
	update();
	physics_simulate();
	render();
	perf_sync();
}
예제 #2
0
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
		MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return 0;
	}
	
	init();
	
	physics_create_scene(sceneId);
	
	SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
	
	MSG msg;
	while(s_isRunning) {
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
			if(msg.message==WM_QUIT) {
				s_isRunning = false;
			}
			else {
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else {
			update();
			if(simulating) physics_simulate();
			render();

			perf_sync();
		}
	}

	shutdown();

	SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);

	releaseWindow();
	return (msg.wParam);
}
예제 #3
0
int main(void)
{
	init();

	physics_create_scene(sceneId);
	
	printf("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);

	while (s_isRunning) {
		update();
		if(simulating) physics_simulate();
		render();

		perf_sync();
	}

	shutdown();

	printf("## %s: FINISHED ##\n", SAMPLE_NAME);

	return 0;
}
예제 #4
0
파일: main.cpp 프로젝트: madsbh/experiments
void stepSimulation(float dt)
{
	int maxSubSteps = 10;
	int numSimulationSubSteps = 0;
	if (maxSubSteps)
	{
		//fixed timestep with interpolation
		sLocalTime += dt;
		if (sLocalTime >= sFixedTimeStep)
		{
			numSimulationSubSteps = int( sLocalTime / sFixedTimeStep);
			sLocalTime -= numSimulationSubSteps * sFixedTimeStep;
		}
		if (numSimulationSubSteps)
		{
			//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
			int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps;
			for (int i=0;i<clampedSimulationSteps;i++)
			{
				physics_simulate();
			}
		} 
	}
}
예제 #5
0
파일: main.cpp 프로젝트: madsbh/experiments
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("pause_simulation", pauseSimulation);
	printf("pause_simulation=%d\n",pauseSimulation);
	

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

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

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

	int maxObjectCapacity=128*1024;

	GLInstancingRenderer render(maxObjectCapacity);
	render.setCameraDistance(30);
	
		
	render.InitShaders();


//	createSceneProgrammatically(render);
    

	render.writeTransforms();

    window->runMainLoop();

	physics_init();

	physics_create_scene(2);

	create_graphics_from_physics_objects(render);
	
	window->setMouseCallback(btDefaultMouseCallback);
	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;
			
			float orn[4] = {0,0,0,1};
			float pos[4];
			render.getCameraPosition(pos);
			
//			demo.setObjectTransform(pos,orn,0);
//			render.writeSingleTransformInstanceToCPU(pos,orn,0);
//			createScene(render, demo);
//			printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
//			printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
//			render.writeTransforms();
		}


	//	float deltaTime = 1.f/60.f;

        if (!pauseSimulation)
            physics_simulate();
//		stepSimulation(deltaTime);

		{
			BT_PROFILE("sync_graphics_to_physics_objects");
			sync_graphics_to_physics_objects(render);
		}

		{
			BT_PROFILE("render.writeTransforms");
			render.writeTransforms();
		}

		{
			BT_PROFILE("window->startRendering");
			window->startRendering();
		}
		{
			BT_PROFILE("render.RenderScene");
			render.RenderScene();
		}
		{
			BT_PROFILE("window->endRendering");
			window->endRendering();
		}

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

		CProfileManager::Increment_Frame_Counter();

		static bool printStats  = true;

		
		
		 if (printStats && !pauseSimulation)
		 {
			static int count = 0;
			count--;
			if (count<0)
			{
				count = 100;
				CProfileManager::dumpAll();
				//printStats  = false;
			} else
			{
//				printf(".");
			}
		 }
		

	}

	

	render.CleanupShaders();
	window->exit();
	delete window;
	
	
	
	return 0;
}
//----------------------------------------------------------------------------
//  Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsPhysStep
//
/// Implementation of JNI function to perform one simulation step.
///
/// @param  env     Pointer to JNI environment
//----------------------------------------------------------------------------
void
Java_pfx_renderingsupport_PhysicsEffectsRenderer_nativePhysicsEffectsPhysStep( JNIEnv*  env )
{
	physics_simulate();
}