Page 5 of 6

Posted: Mon Mar 24, 2008 10:43 pm
by drumz
Updated code for analog joystick yaw control.

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

Posted: Tue Mar 25, 2008 10:21 pm
by another_commander
After having been confirmed as working by at least one Windows user, the analog joystick yaw control code by drumz is now in the trunk. Anyone with trunk access willing to test it, please have a go at it and let us know if it plays well enough for you.

Posted: Tue Mar 25, 2008 11:17 pm
by drumz
I found one other issue related to yaw control (this time not joystick specific). Currently, when the player switches to an "info" screen (F5-F8) while flying, the pitch and roll slowly decrease to 0. Yaw doesn't. This small patch makes yaw decrease to 0, like pitch and roll. This behavior can be tested with keyboard and/or joystick.

(This goes at the very end of the pollGuiArrowKeyControls function.)

Code: Select all

Index: src/Core/Entities/PlayerEntityControls.m
===================================================================
--- src/Core/Entities/PlayerEntityControls.m    (revision 1514)
+++ src/Core/Entities/PlayerEntityControls.m    (working copy)
@@ -1778,6 +1778,16 @@
                if (flightPitch < -delta_t)     [self increase_flight_pitch:delta_t];
                else    flightPitch = 0.0;
        }
+       if (flightYaw > 0.0)
+       {
+               if (flightYaw > delta_t)        [self decrease_flight_yaw:delta_t];
+               else    flightYaw = 0.0;
+       }
+       if (flightYaw < 0.0)
+       {
+               if (flightYaw < -delta_t)       [self increase_flight_yaw:delta_t];
+               else    flightYaw = 0.0;
+       }
 }

Edit: removed smiley.

Posted: Thu Apr 17, 2008 3:21 pm
by Commander Mysenses
Was ondering if joystick response could be modified? ATM I find that fine adjustments are a tad jumpy, it is helped somewhat by use of the sensitivity toggle, but it isn't the ideal solution. I was thinking a kind of logarithmic response scale, for roll,pitch and yaw would be nice. So that the initial deflections of the stick produce small movements, and further deflections gradually make increasingly large movements, up to the ships maximum roll/pitch rate at full deflection.

Does that make sense?
Is it possible?

Posted: Fri Apr 18, 2008 5:33 am
by drumz
Yeah, it makes sense. Basically you want the option of having different responses besides just linear. I don't think logarithmic is want you want, though.

I've a made a few plots of the cubic function
y = (1-c)*x^3 + c*x
where c varies between 0 (slope at the origin is 0 - maximum non-linearity) and 1 (purely linear).

blue: c=0
green: c=1/3
red: c=2/3
cyan: c=1
Image

The benefits of using a cubic function is there's one user-tunable variable to change the amount of linearity, plus being continuous and differentiable, and all that good stuff.

Currently I'm adding null zone, maximum range, and hysteresis, so I can add this into the mix without too much trouble.

Posted: Fri Apr 18, 2008 9:00 am
by Commander Mysenses
Give that man a Huzzah!

That's grrrrreat!
(as Tony might say)

Posted: Fri Apr 18, 2008 4:28 pm
by Captain Hesperus
Commander Mysenses wrote:
Give that man a Huzzah!

That's grrrrreat!
(as Tony might say)
Huzzah!

What's he done? :?

Captain Hesperus

Posted: Fri Apr 18, 2008 8:36 pm
by Cmdr. Maegil
He perfected a hyperdrive cruise control algorithm that also mixes drinks!

Posted: Sun May 04, 2008 8:19 am
by Commander Mysenses
drumz wrote:
Currently I'm adding null zone, maximum range, and hysteresis, so I can add this into the mix without too much trouble.

Any news?

Posted: Sun May 04, 2008 1:59 pm
by drumz
Not yet. School's been real busy lately. I'll get to it eventually, though.

slower yaw

Posted: Tue May 13, 2008 8:56 pm
by Dr Beeb
nijineko wrote:
i use the yaw constantly. especially helpful once i've got a vert/hor lock on a thargian carrier and then i just spin the ship sideways to bring all four lasers to bear in sequence til.... BOOM. =D works very nicely against targets that don't move all that fast for whatever reason. or at least don't leave the horizontal plane of your ship.

i played descent 1, 2, and 3 a whole lot before playing here, so i'm used to being able to thrust in any axis as well as spin along any axis. (but that takes up a whole lot of keymapping on the keyboard!) i'd vote for it, but fear that it's not *lite enough. ^^

I resisted the yaw buttons for a while after introduced but capitulated and found them useful for things like swinging a (port) mining laser around to blast a target and swinging it back out of the way again.

One idea for Oolite is to edit the shipdata to match moment of inertia/engine designs of each craft. For instance a Cobra Mk III is so wide and (restrictive drive design) that its max yaw rate could be as slow as a Boa! This would make yaw not useful in a Cobra Mk III for close combat (but makes long distance precision aiming easier with a keyboard) and rebalancing gameplay re thargian carrier destruction ...

Posted: Tue May 13, 2008 9:39 pm
by JensAyton
But the width also provides superior leverage. :-)

Posted: Fri May 16, 2008 2:49 am
by nijineko
hmmmm, i'm going to have to try to calibrate the joystick and see how that goes....

Posted: Mon Jul 07, 2008 7:03 pm
by Commander Mysenses
drumz wrote:
Currently I'm adding null zone, maximum range, and hysteresis, so I can add this into the mix without too much trouble.
Has RL allowed you to address this yet?

Posted: Wed Oct 22, 2008 1:47 pm
by drew
Yaw... :cry:

Don't like it, doesn't feel like Elite at all. Infact, I dislike it so much I'm going to put an oblique reference into Mutabilis to that effect.

Fair enough if people like it, but I won't be using it.

Cheers,

Drew.