Add joystick button/axis support for view forward, aft, port, and starboard.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1535 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
b62473dc29
commit
2e5f7c95de
@ -63,7 +63,8 @@ enum {
|
||||
AXIS_YAW,
|
||||
AXIS_PRECISION,
|
||||
AXIS_THRUST,
|
||||
AXIS_VIEW,
|
||||
AXIS_VIEWX,
|
||||
AXIS_VIEWY,
|
||||
AXIS_end
|
||||
} axfn;
|
||||
|
||||
@ -93,13 +94,17 @@ enum {
|
||||
BUTTON_ESCAPE,
|
||||
BUTTON_CLOAK,
|
||||
BUTTON_PRECISION,
|
||||
BUTTON_VIEWFORWARD,
|
||||
BUTTON_VIEWAFT,
|
||||
BUTTON_VIEWPORT,
|
||||
BUTTON_VIEWSTARBOARD,
|
||||
BUTTON_end
|
||||
} butfn;
|
||||
|
||||
// Stick constants
|
||||
#define MAX_STICKS 2
|
||||
#define MAX_AXES 10
|
||||
#define MAX_BUTTONS 20
|
||||
#define MAX_AXES (AXIS_end)
|
||||
#define MAX_BUTTONS (BUTTON_end)
|
||||
#define STICK_NOFUNCTION -1
|
||||
#define STICK_AXISUNASSIGNED -10.0
|
||||
#define STICK_PRECISIONDIV 98304 // 3 times more precise
|
||||
@ -136,6 +141,7 @@ enum {
|
||||
|
||||
- (int) getNumSticks;
|
||||
- (NSPoint) getRollPitchAxis;
|
||||
- (NSPoint) getViewAxis;
|
||||
- (double) getAxisState:(int)function;
|
||||
- (const BOOL *) getAllButtonStates;
|
||||
|
||||
|
@ -72,6 +72,12 @@ JoystickHandler *sSharedStickHandler = nil;
|
||||
}
|
||||
|
||||
|
||||
- (NSPoint) getViewAxis
|
||||
{
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
|
||||
- (double) getAxisState:(int)function
|
||||
{
|
||||
return 0.0;
|
||||
|
@ -2047,29 +2047,50 @@ static NSTimeInterval time_last_frame;
|
||||
|
||||
MyOpenGLView *gameView = [UNIVERSE gameView];
|
||||
|
||||
NSPoint virtualView = NSZeroPoint;
|
||||
double view_threshold = 0.5;
|
||||
|
||||
if (!stickHandler)
|
||||
{
|
||||
stickHandler = [gameView getStickHandler];
|
||||
}
|
||||
|
||||
if ([stickHandler getNumSticks])
|
||||
{
|
||||
virtualView = [stickHandler getViewAxis];
|
||||
if (virtualView.y == STICK_AXISUNASSIGNED)
|
||||
virtualView.y = 0.0;
|
||||
if (virtualView.x == STICK_AXISUNASSIGNED)
|
||||
virtualView.x = 0.0;
|
||||
if (fabs(virtualView.y) >= fabs(virtualView.x))
|
||||
virtualView.x = 0.0; // forward/aft takes precedence
|
||||
}
|
||||
|
||||
const BOOL *joyButtonState = [stickHandler getAllButtonStates];
|
||||
|
||||
// view keys
|
||||
if (([gameView isDown:gvFunctionKey1])||([gameView isDown:gvNumberKey1]))
|
||||
if (([gameView isDown:gvFunctionKey1])||([gameView isDown:gvNumberKey1])||(virtualView.y < -view_threshold)||joyButtonState[BUTTON_VIEWFORWARD])
|
||||
{
|
||||
if ([UNIVERSE displayGUI])
|
||||
[self switchToMainView];
|
||||
[UNIVERSE setViewDirection:VIEW_FORWARD];
|
||||
currentWeaponFacing = VIEW_FORWARD;
|
||||
}
|
||||
if (([gameView isDown:gvFunctionKey2])||([gameView isDown:gvNumberKey2]))
|
||||
if (([gameView isDown:gvFunctionKey2])||([gameView isDown:gvNumberKey2])||(virtualView.y > view_threshold)||joyButtonState[BUTTON_VIEWAFT])
|
||||
{
|
||||
if ([UNIVERSE displayGUI])
|
||||
[self switchToMainView];
|
||||
[UNIVERSE setViewDirection:VIEW_AFT];
|
||||
currentWeaponFacing = VIEW_AFT;
|
||||
}
|
||||
if (([gameView isDown:gvFunctionKey3])||([gameView isDown:gvNumberKey3]))
|
||||
if (([gameView isDown:gvFunctionKey3])||([gameView isDown:gvNumberKey3])||(virtualView.x < -view_threshold)||joyButtonState[BUTTON_VIEWPORT])
|
||||
{
|
||||
if ([UNIVERSE displayGUI])
|
||||
[self switchToMainView];
|
||||
[UNIVERSE setViewDirection:VIEW_PORT];
|
||||
currentWeaponFacing = VIEW_PORT;
|
||||
}
|
||||
if (([gameView isDown:gvFunctionKey4])||([gameView isDown:gvNumberKey4]))
|
||||
if (([gameView isDown:gvFunctionKey4])||([gameView isDown:gvNumberKey4])||(virtualView.x > view_threshold)||joyButtonState[BUTTON_VIEWSTARBOARD])
|
||||
{
|
||||
if ([UNIVERSE displayGUI])
|
||||
[self switchToMainView];
|
||||
|
@ -166,7 +166,12 @@ MA 02110-1301, USA.
|
||||
[stickHandler saveStickSettings];
|
||||
|
||||
// Update the GUI (this will refresh the function list).
|
||||
[self setGuiToStickMapperScreen: 0];
|
||||
unsigned skip;
|
||||
if (selFunctionIdx < MAX_ROWS_FUNCTIONS)
|
||||
skip = 0;
|
||||
else
|
||||
skip = ((selFunctionIdx - 1) / (MAX_ROWS_FUNCTIONS - 2)) * (MAX_ROWS_FUNCTIONS - 2) + 1;
|
||||
[self setGuiToStickMapperScreen: skip];
|
||||
}
|
||||
|
||||
- (void) removeFunction: (int)idx
|
||||
@ -187,7 +192,13 @@ MA 02110-1301, USA.
|
||||
[stickHandler unsetAxisFunction: [axfunc intValue]];
|
||||
}
|
||||
[stickHandler saveStickSettings];
|
||||
[self setGuiToStickMapperScreen: 0];
|
||||
|
||||
unsigned skip;
|
||||
if (selFunctionIdx < MAX_ROWS_FUNCTIONS)
|
||||
skip = 0;
|
||||
else
|
||||
skip = ((selFunctionIdx - 1) / (MAX_ROWS_FUNCTIONS - 2)) * (MAX_ROWS_FUNCTIONS - 2) + 1;
|
||||
[self setGuiToStickMapperScreen: skip];
|
||||
}
|
||||
|
||||
- (void) displayFunctionList: (GuiDisplayGen *)gui
|
||||
@ -420,6 +431,26 @@ MA 02110-1301, USA.
|
||||
allowable: HW_BUTTON
|
||||
axisfn: STICK_NOFUNCTION
|
||||
butfn: BUTTON_PRECISION]];
|
||||
[funcList addObject:
|
||||
[self makeStickGuiDict: @"View Forward"
|
||||
allowable: HW_AXIS|HW_BUTTON
|
||||
axisfn: AXIS_VIEWY
|
||||
butfn: BUTTON_VIEWFORWARD]];
|
||||
[funcList addObject:
|
||||
[self makeStickGuiDict: @"View Aft"
|
||||
allowable: HW_AXIS|HW_BUTTON
|
||||
axisfn: AXIS_VIEWY
|
||||
butfn: BUTTON_VIEWAFT]];
|
||||
[funcList addObject:
|
||||
[self makeStickGuiDict: @"View Port"
|
||||
allowable: HW_AXIS|HW_BUTTON
|
||||
axisfn: AXIS_VIEWX
|
||||
butfn: BUTTON_VIEWPORT]];
|
||||
[funcList addObject:
|
||||
[self makeStickGuiDict: @"View Starboard"
|
||||
allowable: HW_AXIS|HW_BUTTON
|
||||
axisfn: AXIS_VIEWX
|
||||
butfn: BUTTON_VIEWSTARBOARD]];
|
||||
return funcList;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,8 @@ enum {
|
||||
AXIS_YAW,
|
||||
AXIS_PRECISION,
|
||||
AXIS_THRUST,
|
||||
AXIS_VIEW,
|
||||
AXIS_VIEWX,
|
||||
AXIS_VIEWY,
|
||||
AXIS_end
|
||||
} axfn;
|
||||
|
||||
@ -73,13 +74,17 @@ enum {
|
||||
BUTTON_ESCAPE,
|
||||
BUTTON_CLOAK,
|
||||
BUTTON_PRECISION,
|
||||
BUTTON_VIEWFORWARD,
|
||||
BUTTON_VIEWAFT,
|
||||
BUTTON_VIEWPORT,
|
||||
BUTTON_VIEWSTARBOARD,
|
||||
BUTTON_end
|
||||
} butfn;
|
||||
|
||||
// Stick constants
|
||||
#define MAX_STICKS 2
|
||||
#define MAX_AXES 10
|
||||
#define MAX_BUTTONS 20
|
||||
#define MAX_AXES (AXIS_end)
|
||||
#define MAX_BUTTONS (BUTTON_end)
|
||||
#define STICK_NOFUNCTION -1
|
||||
#define STICK_AXISUNASSIGNED -10.0
|
||||
#define STICK_PRECISIONDIV 98304 // 3 times more precise
|
||||
@ -141,6 +146,9 @@ enum {
|
||||
// Roll/pitch axis
|
||||
- (NSPoint) getRollPitchAxis;
|
||||
|
||||
// View axis
|
||||
- (NSPoint) getViewAxis;
|
||||
|
||||
// Setting button and axis functions
|
||||
- (void) setFunctionForAxis: (int)axis
|
||||
function: (int)function
|
||||
|
@ -97,6 +97,11 @@ MA 02110-1301, USA.
|
||||
return NSMakePoint(axstate[AXIS_ROLL], axstate[AXIS_PITCH]);
|
||||
}
|
||||
|
||||
- (NSPoint) getViewAxis
|
||||
{
|
||||
return NSMakePoint(axstate[AXIS_VIEWX], axstate[AXIS_VIEWY]);
|
||||
}
|
||||
|
||||
- (BOOL) getButtonState: (int)function
|
||||
{
|
||||
return butstate[function];
|
||||
@ -396,6 +401,9 @@ MA 02110-1301, USA.
|
||||
axstate[function]=axisvalue / STICK_NORMALDIV;
|
||||
}
|
||||
break;
|
||||
case AXIS_VIEWX:
|
||||
case AXIS_VIEWY:
|
||||
axstate[function]=axisvalue / STICK_NORMALDIV;
|
||||
default:
|
||||
// set the state with no modification.
|
||||
axstate[function]=axisvalue / 32768;
|
||||
|
Loading…
x
Reference in New Issue
Block a user