Esempio n. 1
0
bool COLLADA_Viewer::onUpdate()
{
	float tolerrance = 0.15;
	static float buttonTime = 0;
	static float cameraTime = 0;
	bool result = FWGLApplication::onUpdate();

	if (mRunning==false)
	   return result;

	FWTimeVal curTime = FWTime::getCurrentTime();

	if ((float)curTime - buttonTime > 0.15)	// execute these control base on time elapse, not frame rate
	{
		buttonTime = curTime;
		if(mpPad->getRawBool(FWInput::Channel_Button_Select))
		{
		  _CrtRender.SetNextCamera();
		  return result;
		} else if(mpPad->getRawBool(FWInput::Channel_Button_L3))
		{
		   if (Browser.IsVisible())
			   Browser.SetVisible(false);
		   else
			   Browser.SetVisible(true);
		} else if(mpPad->getRawBool(FWInput::Channel_Button_R3))
		{
			if (togglewireframe) {
				togglewireframe = false;
			} else {
				togglewireframe = true;
			}
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Square)) 
		{
			if (togglelighting) {
				togglelighting = false;
			} else {
				togglelighting = true;
			}
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Cross)) 
		{
			mCurrentFile = Browser.GetThumbnail(Browser.GetSelection())->GetDocument();
			load_ok = _CrtRender.Load(mCurrentFile, NULL);
			return result;
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Up))
		{
		   Browser.SelectPrev();
		} else if(mpPad->getRawBool(FWInput::Channel_Button_Down))
		{
		   Browser.SelectNext();
		}
	}

	if ((float)curTime - cameraTime > 0.05)	// execute these control base on time elapse, not frame rate
	{
		cameraTime = curTime;
			   // Get the values from the analog sticks
	   float conditioned_X_0 = mpPad->getRawFloat(FWInput::Channel_XAxis_0);
	   float conditioned_Y_0 = mpPad->getRawFloat(FWInput::Channel_YAxis_0);
	   float conditioned_X_1 = mpPad->getRawFloat(FWInput::Channel_XAxis_1);
	   float conditioned_Y_1 = mpPad->getRawFloat(FWInput::Channel_YAxis_1);

	   if (-tolerrance < conditioned_X_0 && conditioned_X_0 < tolerrance) conditioned_X_0 = 0.0f;
	   if (-tolerrance < conditioned_Y_0 && conditioned_Y_0 < tolerrance) conditioned_Y_0 = 0.0f;
	   if (-tolerrance < conditioned_X_1 && conditioned_X_1 < tolerrance) conditioned_X_1 = 0.0f;
	   if (-tolerrance < conditioned_Y_1 && conditioned_Y_1 < tolerrance) conditioned_Y_1 = 0.0f;

	   conditioned_X_0 = mpInputX0 ? -mpInputX0->getFloatValue() : 0.f;
	   conditioned_Y_0 = mpInputY0 ? -mpInputY0->getFloatValue() : 0.f;
	   conditioned_X_1 = mpInputX1 ? -mpInputX1->getFloatValue() : 0.f;
	   conditioned_Y_1 = mpInputY1 ? -mpInputY1->getFloatValue() : 0.f;

	   float multiplier = 10.0f;
	   if (conditioned_X_0 != 0.0f || conditioned_Y_0 != 0.0f)
	   {
		  _CrtRender.ActiveInstanceCamera->MoveOrbit(conditioned_X_0 * multiplier, conditioned_Y_0 * multiplier);
	   }
	   if (conditioned_X_1 != 0.0f || conditioned_Y_1 != 0.0f)
	   {
		  _CrtRender.ActiveInstanceCamera->SetPanAndTilt(conditioned_X_1 * multiplier, conditioned_Y_1 * multiplier);
	   }
	}
	
	if(mpPad->getRawBool(FWInput::Channel_Button_L2))
	{  // zoom in
	  _CrtRender.ZoomIn(-0.005f);
	} else if(mpPad->getRawBool(FWInput::Channel_Button_L1))
	{  // zoom out
	  _CrtRender.ZoomIn(0.005f);
   	}
	
	if (togglewireframe) {
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	} else {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}

	if (togglelighting) {
		glEnable(GL_LIGHTING);
	} else {
		glDisable(GL_LIGHTING);
	}


#if defined SPU_BULLET || !defined (SN_TARGET_PS3)

   if (mpPad->getRawBool(FWInput::Channel_Button_Triangle))
   {

	   float fl_x, fl_y, fl_z, fl_g;
	   fl_x = mpPad->getRawFloat(FWInput::Channel_XAxis_2);
	   fl_y = mpPad->getRawFloat(FWInput::Channel_YAxis_2);
	   fl_z = mpPad->getRawFloat(FWInput::Channel_ZAxis_2);
	   fl_g = mpPad->getRawFloat(FWInput::Channel_Gyro);

	   SixAxis(fl_x, fl_y, fl_z, fl_g);
   } else {
	    _CrtRender.SetGravity(CrtVec3f(0.0f, -10.0f, 0.0f));
   }
#endif
	static const int CONS_PUTS_INTERVAL = 50;

	if (frames % CONS_PUTS_INTERVAL == 0){
	}

	char title[1024];
	const char * selectedfile = Browser.GetThumbnail(Browser.GetSelection())->GetDocument();
	sprintf(title, "%s %s", "COLLADA Viewer", mCurrentFile);
	cellDbgFontPuts(0.1f, 0.1f, 1.0f, 0xffffffff, title);
	cellDbgFontPuts(0.1f, 0.9f, 1.0f, 0xffffffff, selectedfile);

	Browser.onUpdate();
	return result; 
}
Esempio n. 2
0
LRESULT CALLBACK WndProc(	HWND	hWnd,			
							UINT	uMsg,			
							WPARAM	wParam,			
							LPARAM	lParam)			
{	

	switch (uMsg)									
	{
		case WM_ACTIVATE:							
		{
			if (!HIWORD(wParam))					
			{
				active=TRUE;						
			}
			else
			{
				active=FALSE;						
			}

			return 0;								
		}

		case WM_SYSCOMMAND:							
		{
			switch (wParam)							
			{
				case SC_SCREENSAVE:					
				case SC_MONITORPOWER:				
				return 0;							
			}
			break;									
		}

		case WM_CLOSE:								
		{
			PostQuitMessage(0);						
			return 0;								
		}

		case WM_KEYDOWN:						
		{
			// We only want to know which keys are down, so if this was an auto-repeat, ignore it
			if(!(HIWORD(lParam) & KF_REPEAT))
			{
				// Remember which keys are being held down
				keys[wParam] = TRUE;
			}
			return 0;							
		}

		case WM_KEYUP:							
		{
			keys[wParam] = FALSE;				
			return 0;							
		}

		case WM_SIZE:							
		{
			ResizeGLScreen(LOWORD(lParam),HIWORD(lParam));
			return 0;								
		}
		case WM_MOUSEWHEEL:
		{
			if (_CrtRender.ActiveInstanceCamera)
			{
				float gcWheelDelta = (short) HIWORD(wParam);
				_CrtRender.ZoomIn((CrtFloat) (-gcWheelDelta * MouseWheelSpeed));

				return 0;
			}
		}
		case WM_MBUTTONDOWN:
		{
			// Change camera
			_CrtRender.SetNextCamera();
			return 0;
		}
		case WM_MOUSEMOVE:
		{
			// UI code to move camera in response to mouse movement.
			static float lastx = 0, lasty = 0;
			static int	 lastLeft = 0, lastRight = 0, lastMiddle = 0;
			// Retrieve mouse screen position and button state
			float x=(float) (short)LOWORD(lParam);
			float y=(float) (short)HIWORD(lParam);
//			bool controlButtonDown=((wParam & MK_CONTROL)  !=0);
			bool leftButtonDown=((wParam & MK_LBUTTON)  !=0);
			bool middleButtonDown=((wParam & MK_MBUTTON)  !=0);			
			bool rightButtonDown=((wParam & MK_RBUTTON) !=0);
			// Handle rotations if left button was pressed
			if(leftButtonDown)
			{
				if(lastLeft && _CrtRender.ActiveInstanceCamera)
				{
					_CrtRender.ActiveInstanceCamera->SetPanAndTilt((lastx - x) * MouseRotateSpeed, (lasty - y) * MouseRotateSpeed);
					lastx = x;
					lasty = y;
				}
				else
				{
					// Remember where the mouse was when it first went down.
					lastLeft = true;
					lastx = x;
					lasty = y;
					return 0;
				}
			}
			else
			{
				lastLeft = false;
			}
			if (middleButtonDown)
			{
				if(lastMiddle && _CrtRender.ActiveInstanceCamera)
				{
					_CrtRender.ActiveInstanceCamera->MoveOrbit((lastx - x) * MouseTranslateSpeed, - (lasty - y) * MouseTranslateSpeed);
					lastx = x;
					lasty = y;
				}
				else
				{
					// Remember where the mouse was when it first went down.
					lastMiddle = true;
					lastx = x;
					lasty = y;
					return 0;
				}
			}
			if(rightButtonDown)
			{
				// Was the mouse previously down?
				if(lastRight && _CrtRender.ActiveInstanceCamera)
				{
					_CrtRender.ActiveInstanceCamera->MoveOrbit((lastx - x) * MouseTranslateSpeed, - (lasty - y) * MouseTranslateSpeed);
					lastx = x;
					lasty = y;
				}
				else
				{
					// Remember that the button was down, and where it went down
					lastRight = true;
					lastx = x;
					lasty = y;
					return 0;
				}
			}
			else
			{
				lastRight = false;
			}
			return 0;
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}