diff --git a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp index 389f69322..841f87c8a 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp @@ -228,7 +228,15 @@ double FGPropeller::Calculate(double EnginePower) // Induced velocity in the propeller disk area. This formula is obtained // from momentum theory - see B. W. McCormick, "Aerodynamics, Aeronautics, // and Flight Mechanics" 1st edition, eqn. 6.15 (propeller analysis chapter). - Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area))); + // Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area))) + // Since Thrust and Vel can both be negative we need to adjust this formula + // To handle sign (direction) separately from magnitude. + double Vel2sum = Vel*abs(Vel) + 2.0*Thrust/(rho*Area); + + if( Vel2sum > 0.0) + Vinduced = 0.5 * (-Vel + sqrt(Vel2sum)); + else + Vinduced = 0.5 * (-Vel - sqrt(-Vel2sum)); // P-factor is simulated by a shift of the acting location of the thrust. // The shift is a multiple of the angle between the propeller shaft axis diff --git a/src/Input/FGMacOSXEventInput.cxx b/src/Input/FGMacOSXEventInput.cxx index 28c3094cc..5c0fe4505 100644 --- a/src/Input/FGMacOSXEventInput.cxx +++ b/src/Input/FGMacOSXEventInput.cxx @@ -39,10 +39,12 @@ using std::string; value; }) #define GetHIDElementStringValue(element, key) ({ \ - const char *buf = ""; \ + const char *ref = ""; \ + const char *buf = ref; \ CFStringRef refType = (CFStringRef)CFDictionaryGetValue(element, CFSTR(key)); \ if (refType) { \ buf = CFStringGetCStringPtr(refType, CFStringGetSystemEncoding()); \ + if (!buf) buf = ref; \ } \ buf; }) @@ -126,19 +128,19 @@ struct HIDTypes HID_USAGE_TABLE[] = { {GD_USAGE(kHIDUsage_GD_Vbrz), kHIDUsageAxis, "z-rel-vector"}, {GD_USAGE(kHIDUsage_GD_Vno), kHIDUsageAxis, "no-vector"}, - {GD_USAGE(kHIDUsage_GD_SystemPowerDown), kHIDUsageOSC, "button-system-power-down"}, - {GD_USAGE(kHIDUsage_GD_SystemSleep), kHIDUsageOSC, "button-system-sleep"}, - {GD_USAGE(kHIDUsage_GD_SystemWakeUp), kHIDUsageOSC, "button-system-wake-up"}, - {GD_USAGE(kHIDUsage_GD_SystemContextMenu), kHIDUsageOSC, "button-system-context-menu"}, - {GD_USAGE(kHIDUsage_GD_SystemMainMenu), kHIDUsageOSC, "button-system-main-menu"}, - {GD_USAGE(kHIDUsage_GD_SystemAppMenu), kHIDUsageOSC, "button-system-app-menu"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuHelp), kHIDUsageOSC, "button-system-menu-help"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuExit), kHIDUsageOSC, "button-system-menu-exit"}, - {GD_USAGE(kHIDUsage_GD_SystemMenu), kHIDUsageOSC, "button-system-menu"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuRight), kHIDUsageRTC, "button-system-menu-right"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuLeft), kHIDUsageRTC, "button-system-menu-left"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuUp), kHIDUsageRTC, "button-system-menu-up"}, - {GD_USAGE(kHIDUsage_GD_SystemMenuDown), kHIDUsageRTC, "button-system-menu-down"}, + {GD_USAGE(kHIDUsage_GD_SystemPowerDown), kHIDUsageOSC, "system-power-down"}, + {GD_USAGE(kHIDUsage_GD_SystemSleep), kHIDUsageOSC, "system-sleep"}, + {GD_USAGE(kHIDUsage_GD_SystemWakeUp), kHIDUsageOSC, "system-wake-up"}, + {GD_USAGE(kHIDUsage_GD_SystemContextMenu), kHIDUsageOSC, "system-context-menu"}, + {GD_USAGE(kHIDUsage_GD_SystemMainMenu), kHIDUsageOSC, "system-main-menu"}, + {GD_USAGE(kHIDUsage_GD_SystemAppMenu), kHIDUsageOSC, "system-app-menu"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuHelp), kHIDUsageOSC, "system-menu-help"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuExit), kHIDUsageOSC, "system-menu-exit"}, + {GD_USAGE(kHIDUsage_GD_SystemMenu), kHIDUsageOSC, "system-menu"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuRight), kHIDUsageRTC, "system-menu-right"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuLeft), kHIDUsageRTC, "system-menu-left"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuUp), kHIDUsageRTC, "system-menu-up"}, + {GD_USAGE(kHIDUsage_GD_SystemMenuDown), kHIDUsageRTC, "system-menu-down"}, {GD_USAGE(kHIDUsage_GD_DPadUp), kHIDUsageOOC, "dpad-up"}, {GD_USAGE(kHIDUsage_GD_DPadDown), kHIDUsageOOC, "dpad-down"}, {GD_USAGE(kHIDUsage_GD_DPadRight), kHIDUsageOOC, "dpad-right"}, @@ -151,7 +153,7 @@ struct HIDTypes HID_USAGE_TABLE[] = { {GAME_USAGE(kHIDUsage_Game_MoveForwardOrBackward), kHIDUsageAxis, "y-move"}, {GAME_USAGE(kHIDUsage_Game_MoveUpOrDown), kHIDUsageAxis, "z-move"}, {GAME_USAGE(kHIDUsage_Game_LeanRightOrLeft), kHIDUsageAxis, "x-lean"}, - {GAME_USAGE(kHIDUsage_Game_LeanForwardOrBackward), kHIDUsageAxis, "z-lean"}, + {GAME_USAGE(kHIDUsage_Game_LeanForwardOrBackward), kHIDUsageAxis, "y-lean"}, // General Control Devices Page {GDC_USAGE(0x20), kHIDUsageDV, "battery-strength"}, @@ -382,7 +384,7 @@ ButtonElement::ButtonElement(CFDictionaryRef element, long page, long usage) : { if (name == "") { stringstream ss; - ss << (page == kHIDPage_KeyboardOrKeypad ? "keyboard-" : "button-") << usage; + ss << (page == kHIDPage_KeyboardOrKeypad ? "keyboard-" : "button-") << usage - 1; ss >> name; } } @@ -498,7 +500,7 @@ void HIDElementFactory::parseElement(CFDictionaryRef element, FGMacOSXInputDevic // FIXME: Any other elegant way for counting the same usage on a device? // This is mainly needed for feature / hat elements to avoid assigning the sane event name. elementCount[inputDevice][USAGE_KEY(page, usage)] += 1; - + switch (usageType) { case kHIDUsageAxis: inputDevice->addElement(new AxisElement(element, page, usage)); @@ -519,7 +521,7 @@ void HIDElementFactory::parseElement(CFDictionaryRef element, FGMacOSXInputDevic break; default: - if (page == kHIDPage_Button || type == kIOHIDElementTypeInput_Button && usage > 0) { + if ((page == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) && usage > 0) { // FIXME: most of KeyboardOrKeypad elements should be treated as Selector type, not as Button... inputDevice->addElement(new ButtonElement(element, page, usage)); } else if (page == kHIDPage_LEDs && usage > 0) { diff --git a/src/Input/fgjs.cxx b/src/Input/fgjs.cxx index 9a873ed51..9c4e66487 100644 --- a/src/Input/fgjs.cxx +++ b/src/Input/fgjs.cxx @@ -58,6 +58,10 @@ using std::string; #include "jsinput.h" +#ifdef __APPLE__ +# include +#endif + using simgear::PropertyList; bool confirmAnswer() { @@ -342,25 +346,23 @@ string getFGRoot ( int argc, char **argv ) { root = "../data"; #elif defined( _WIN32 ) root = "..\\data"; -#elif defined(OSX_BUNDLE) - /* the following code looks for the base package directly inside - the application bundle. This can be changed fairly easily by - fiddling with the code below. And yes, I know it's ugly and verbose. +#elif defined(__APPLE__) + /* + The following code looks for the base package inside the application + bundle, in the standard Contents/Resources location. */ - CFBundleRef appBundle = CFBundleGetMainBundle(); - CFURLRef appUrl = CFBundleCopyBundleURL(appBundle); - CFRelease(appBundle); - // look for a 'data' subdir directly inside the bundle : is there - // a better place? maybe in Resources? I don't know ... - CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, appUrl, CFSTR("data"), true); + CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); + + // look for a 'data' subdir + CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true); // now convert down to a path, and the a c-string CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle); root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding()); // tidy up. - CFRelease(appBundle); + CFRelease(resourcesUrl); CFRelease(dataDir); CFRelease(path); #else