Просмотр исходного кода

Added joystick helper methods to CoreInput (getJoystickButtonState and getJoystickAxisValue)

Ivan Safrin 12 лет назад
Родитель
Сommit
a943d7372f
2 измененных файлов с 34 добавлено и 0 удалено
  1. 16 0
      Core/Contents/Include/PolyCoreInput.h
  2. 18 0
      Core/Contents/Source/PolyCoreInput.cpp

+ 16 - 0
Core/Contents/Include/PolyCoreInput.h

@@ -97,6 +97,22 @@ namespace Polycode {
 		*/				
 		bool getKeyState(PolyKEY keyCode);		
 		
+		/** 
+		* Returns the state of the specified joystick button for the specified joystick index. If the joystick index is invalid, returns false
+		* @param joystickIndex Joystick index to check the state on
+		* @param button Joystick button to check the stat of.
+		* @return True if the button is pressed, false otherwise or if joystick index is invalid.
+		*/						
+		bool getJoystickButtonState(int joystickIndex, int button);
+		
+		/** 
+		* Returns the value of the specified joystick axis for the specified joystick index. If the joystick index is invalid, returns 0
+		* @param joystickIndex Joystick index to check the state on
+		* @param axis Joystick axis to get the value of.
+		* @return Value of the joystick axis (0 if joystickIndex is invalid)
+		*/						
+		Number getJoystickAxisValue(int joystickIndex, int axis);
+		
 		/** 
 		* Returns the current mouse position as delta from last frame.
 		* @return Mouse position as a 2d vector delta from last frame.

+ 18 - 0
Core/Contents/Source/PolyCoreInput.cpp

@@ -61,6 +61,24 @@ namespace Polycode {
 		return &joysticks[index];
 	}	
 	
+	bool CoreInput::getJoystickButtonState(int joystickIndex, int button) {
+		JoystickInfo *info = getJoystickInfoByIndex(joystickIndex);
+		if(info) {
+			return info->joystickButtonState[button];
+		} else {
+			return false;
+		}
+	}
+	
+	Number CoreInput::getJoystickAxisValue(int joystickIndex, int axis) {
+		JoystickInfo *info = getJoystickInfoByIndex(joystickIndex);
+		if(info) {
+			return info->joystickAxisState[axis];
+		} else {
+			return 0.0;
+		}	
+	}
+	
 	JoystickInfo *CoreInput::getJoystickInfoByID(unsigned int deviceID) {
 		for(int i=0;i<joysticks.size();i++) {
 			if(joysticks[i].deviceID == deviceID) {