Exemple #1
0
static void update(float deltaTime)
{
	float dt = deltaTime*10.f;
	float angX,angY,r;
	render_get_view_angle(angX,angY,r);

	ctrl_update();
	
	if(ctrl_button_pressed(BTN_UP)) {
		angX -= 0.05f*dt;
		if(angX < -1.4f) angX = -1.4f;
		if(angX > -0.01f) angX = -0.01f;
	}

	if(ctrl_button_pressed(BTN_DOWN)) {
		angX += 0.05f*dt;
		if(angX < -1.4f) angX = -1.4f;
		if(angX > 0.0f) 
			angX = 0.0f;
	}

	if(ctrl_button_pressed(BTN_LEFT)) {
		angY -= 0.05f*dt;
	}

	if(ctrl_button_pressed(BTN_RIGHT)) {
		angY += 0.05f*dt;
	}

	if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
		r *= (1.f+0.1f*dt);
		if(r > 500.0f) r = 500.0f;
	}

	if(ctrl_button_pressed(BTN_ZOOM_IN)) {
		r *= (1.f-0.1f*dt);
		if(r < 1.0f) r = 1.0f;
	}

	if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
		physics_create_scene(sceneId);
	}

	if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
		physics_create_scene(++sceneId);
	}

	if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
		simulating = !simulating;
	}

	if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
		simulating = true;
	}
	else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
		simulating = false;
	}

	render_set_view_angle(angX,angY,r);
}
Exemple #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);

	PfxPerfCounter counter;
	counter.countBegin("dt");

	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 {
			counter.countEnd();
			float dt = counter.getCountTime(0)/1000.f;

			update(dt);

			if(simulating) 
				stepSimulation(dt);

			counter.resetCount();
			counter.countBegin("dt");

			render();

			perf_sync();
		}
	}

	shutdown();

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

	releaseWindow();
	return (msg.wParam);
}
Exemple #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;
}
Exemple #4
0
///////////////////////////////////////////////////////////////////////////////
// sceneChange
//
/// This function is used to change the physics scene on Android devices
///////////////////////////////////////////////////////////////////////////////
void sceneChange()
{
	physics_create_scene(sceneId++);
}
Exemple #5
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("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;
}
Exemple #6
0
void update(void)
{
	float angX,angY,r;
	render_get_view_angle(angX,angY,r);

	ctrl_update();
	
	if(ctrl_button_pressed(BTN_UP)) {
		angX -= 0.05f;
		if(angX < -1.4f) angX = -1.4f;
		if(angX > -0.01f) angX = -0.01f;
	}

	if(ctrl_button_pressed(BTN_DOWN)) {
		angX += 0.05f;
		if(angX < -1.4f) angX = -1.4f;
		if(angX > -0.01f) angX = -0.01f;
	}

	if(ctrl_button_pressed(BTN_LEFT)) {
		angY -= 0.05f;
	}

	if(ctrl_button_pressed(BTN_RIGHT)) {
		angY += 0.05f;
	}

	if(ctrl_button_pressed(BTN_ZOOM_OUT)) {
		r *= 1.1f;
		if(r > 500.0f) r = 500.0f;
	}

	if(ctrl_button_pressed(BTN_ZOOM_IN)) {
		r *= 0.9f;
		if(r < 1.0f) r = 1.0f;
	}

	if(ctrl_button_pressed(BTN_SCENE_RESET) == BTN_STAT_DOWN) {
		physics_create_scene(sceneId);
	}

	if(ctrl_button_pressed(BTN_SCENE_NEXT) == BTN_STAT_DOWN) {
		physics_create_scene(++sceneId);
	}

	if(ctrl_button_pressed(BTN_SIMULATION) == BTN_STAT_DOWN) {
		simulating = !simulating;
	}

	if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_DOWN) {
		simulating = true;
	}
	else if(ctrl_button_pressed(BTN_STEP) == BTN_STAT_UP || ctrl_button_pressed(BTN_STEP) == BTN_STAT_KEEP) {
		simulating = false;
	}

	int w,h;
	render_get_screent_size(w,h);
	ctrl_set_screen_size(w,h);

	static PfxVector3 pickPos(0.0f);

	if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_DOWN) {
		int sx,sy;
		ctrl_get_cursor_position(sx,sy);
		PfxVector3 wp1((float)sx,(float)sy,0.0f);
		PfxVector3 wp2((float)sx,(float)sy,1.0f);
		wp1 = render_get_world_position(wp1);
		wp2 = render_get_world_position(wp2);
		pickPos = physics_pick_start(wp1,wp2);
	}
	else if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_KEEP) {
		int sx,sy;
		ctrl_get_cursor_position(sx,sy);
		PfxVector3 sp = render_get_screen_position(pickPos);
		PfxVector3 wp((float)sx,(float)sy,sp[2]);
		wp = render_get_world_position(wp);
		physics_pick_update(wp);
	}
	else if(ctrl_button_pressed(BTN_PICK) == BTN_STAT_UP) {
		physics_pick_end();
	}

	render_set_view_angle(angX,angY,r);
}