I switched the yaw over to using a double, instead of NSPoint.
I also didn't include the code that makes default yaw action half as large as pitch action.
Also, I fixed what I'm pretty sure was a bug in the code. abs(virtualStick.x) (and y) were changed to fabs(virtualStick.x) (and y).
Code: Select all
~/pkgs/oolite/svn/trunk$ svn diff
Index: src/SDL/JoystickHandler.h
===================================================================
--- src/SDL/JoystickHandler.h (revision 1510)
+++ src/SDL/JoystickHandler.h (working copy)
@@ -40,6 +40,7 @@
enum {
AXIS_ROLL,
AXIS_PITCH,
+ AXIS_YAW,
AXIS_PRECISION,
AXIS_THRUST,
AXIS_VIEW,
Index: src/SDL/JoystickHandler.m
===================================================================
--- src/SDL/JoystickHandler.m (revision 1510)
+++ src/SDL/JoystickHandler.m (working copy)
@@ -386,6 +386,7 @@
break;
case AXIS_ROLL:
case AXIS_PITCH:
+ case AXIS_YAW:
if(precisionMode)
{
axstate[function]=axisvalue / STICK_PRECISIONDIV;
@@ -444,11 +445,13 @@
{
axstate[AXIS_PITCH] /= STICK_PRECISIONFAC;
axstate[AXIS_ROLL] /= STICK_PRECISIONFAC;
+ axstate[AXIS_YAW] /= STICK_PRECISIONFAC;
}
else
{
axstate[AXIS_PITCH] *= STICK_PRECISIONFAC;
axstate[AXIS_ROLL] *= STICK_PRECISIONFAC;
+ axstate[AXIS_YAW] *= STICK_PRECISIONFAC;
}
}
}
Index: src/Cocoa/JoystickHandler.h
===================================================================
--- src/Cocoa/JoystickHandler.h (revision 1510)
+++ src/Cocoa/JoystickHandler.h (working copy)
@@ -60,6 +60,7 @@
enum {
AXIS_ROLL,
AXIS_PITCH,
+ AXIS_YAW,
AXIS_PRECISION,
AXIS_THRUST,
AXIS_VIEW,
Index: src/Core/Entities/PlayerEntityControls.m
===================================================================
--- src/Core/Entities/PlayerEntityControls.m (revision 1510)
+++ src/Core/Entities/PlayerEntityControls.m (working copy)
@@ -431,6 +431,7 @@
out the joystick if the player runs to the keyboard)
is reset */
keyboardRollPitchOverride = NO;
+ keyboardYawOverride = NO;
}
else
{
@@ -2141,6 +2142,7 @@
{
MyOpenGLView *gameView = [UNIVERSE gameView];
NSPoint virtualStick = NSZeroPoint;
+ double reqYaw = 0.0;
#define kDeadZone 0.02
// TODO: Rework who owns the stick.
@@ -2177,11 +2179,22 @@
// cancel keyboard override, stick has been waggled
keyboardRollPitchOverride=NO;
}
+ // handle yaw separately from pitch/roll
+ reqYaw = [stickHandler getAxisState: AXIS_YAW];
+ if(reqYaw == STICK_AXISUNASSIGNED)
+ {
+ reqYaw=0;
+ }
+ else if(reqYaw != 0)
+ {
+ // cancel keyboard override, stick has been waggled
+ keyboardYawOverride=NO;
+ }
}
double roll_dampner = ROLL_DAMPING_FACTOR * delta_t;
double pitch_dampner = PITCH_DAMPING_FACTOR * delta_t;
- double yaw_dampner = PITCH_DAMPING_FACTOR * delta_t;
+ double yaw_dampner = YAW_DAMPING_FACTOR * delta_t;
rolling = NO;
if (!mouse_control_on )
@@ -2216,7 +2229,7 @@
if (flightRoll < stick_roll)
flightRoll = stick_roll;
}
- rolling = (abs(virtualStick.x) > kDeadZone);
+ rolling = (fabs(virtualStick.x) > kDeadZone);
}
if (!rolling)
{
@@ -2265,7 +2278,7 @@
if (flightPitch < stick_pitch)
flightPitch = stick_pitch;
}
- pitching = (abs(virtualStick.x) > kDeadZone);
+ pitching = (fabs(virtualStick.y) > kDeadZone);
}
if (!pitching)
{
@@ -2286,16 +2299,37 @@
yawing = NO;
if ([gameView isDown:key_yaw_left])
{
+ keyboardYawOverride=YES;
if (flightYaw < 0.0) flightYaw = 0.0;
[self increase_flight_yaw:delta_t*yaw_delta];
yawing = YES;
}
else if ([gameView isDown:key_yaw_right])
{
+ keyboardYawOverride=YES;
if (flightYaw > 0.0) flightYaw = 0.0;
[self decrease_flight_yaw:delta_t*yaw_delta];
yawing = YES;
}
+ if(numSticks && !keyboardRollPitchOverride && !keyboardYawOverride)
+ {
+ // I think yaw is handled backwards in the code,
+ // which is why the negative sign is here.
+ double stick_yaw = max_flight_yaw * (-reqYaw);
+ if (flightYaw < stick_yaw)
+ {
+ [self increase_flight_yaw:delta_t*yaw_delta];
+ if (flightYaw > stick_yaw)
+ flightYaw = stick_yaw;
+ }
+ if (flightYaw > stick_yaw)
+ {
+ [self decrease_flight_yaw:delta_t*yaw_delta];
+ if (flightYaw < stick_yaw)
+ flightYaw = stick_yaw;
+ }
+ yawing = (fabs(reqYaw) > kDeadZone);
+ }
if (!yawing)
{
if (flightYaw > 0.0)
Index: src/Core/Entities/PlayerEntity.h
===================================================================
--- src/Core/Entities/PlayerEntity.h (revision 1510)
+++ src/Core/Entities/PlayerEntity.h (working copy)
@@ -125,6 +125,7 @@
#define ROLL_DAMPING_FACTOR 1.0
#define PITCH_DAMPING_FACTOR 1.0
+#define YAW_DAMPING_FACTOR 1.0
#define PLAYER_MAX_WEAPON_TEMP 256.0
#define PLAYER_MAX_FUEL 70
@@ -448,6 +449,7 @@
isSpeechOn: 1,
keyboardRollPitchOverride: 1,
+ keyboardYawOverride: 1,
waitingForStickCallback: 1;
// Note: joystick stuff does nothing under OS X.
Index: src/Core/Entities/PlayerEntity.m
===================================================================
--- src/Core/Entities/PlayerEntity.m (revision 1510)
+++ src/Core/Entities/PlayerEntity.m (working copy)
@@ -3452,6 +3452,7 @@
flightRoll = 0.0;
flightPitch = 0.0;
+ flightYaw = 0.0;
flightSpeed = 0.0;
hyperspeed_engaged = NO;
@@ -6377,6 +6378,7 @@
ADD_FLAG_IF_SET(mouse_control_on);
ADD_FLAG_IF_SET(isSpeechOn);
ADD_FLAG_IF_SET(keyboardRollPitchOverride);
+ ADD_FLAG_IF_SET(keyboardYawOverride);
ADD_FLAG_IF_SET(waitingForStickCallback);
flagsString = [flags count] ? [flags componentsJoinedByString:@", "] : @"none";
OOLog(@"dumpState.playerEntity", @"Flags: %@", flagsString);
Index: src/Core/Entities/PlayerEntityStickMapper.m
===================================================================
--- src/Core/Entities/PlayerEntityStickMapper.m (revision 1510)
+++ src/Core/Entities/PlayerEntityStickMapper.m (working copy)
@@ -289,6 +289,11 @@
axisfn: AXIS_PITCH
butfn: STICK_NOFUNCTION]];
[funcList addObject:
+ [self makeStickGuiDict: @"Yaw"
+ allowable: HW_AXIS
+ axisfn: AXIS_YAW
+ butfn: STICK_NOFUNCTION]];
+ [funcList addObject:
[self makeStickGuiDict: @"Increase thrust"
allowable: HW_AXIS|HW_BUTTON
axisfn: AXIS_THRUST