From 08390be391c38054d874ffb44cb7e64c64136201 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 25 Jun 2021 16:51:40 +0100 Subject: [PATCH] src/AIModel/: use Simgear's unit conversion constants, e.g. SG_KT_TO_FPS. --- src/AIModel/AIMultiplayer.cxx | 7 ++----- src/AIModel/AIShip.cxx | 11 +++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/AIModel/AIMultiplayer.cxx b/src/AIModel/AIMultiplayer.cxx index a8d13286a..3995a6859 100644 --- a/src/AIModel/AIMultiplayer.cxx +++ b/src/AIModel/AIMultiplayer.cxx @@ -713,14 +713,11 @@ void FGAIMultiplayer::update(double dt) _vBodyNode->setValue(ecLinearVel[1] * SG_METER_TO_FEET); _wBodyNode->setValue(ecLinearVel[2] * SG_METER_TO_FEET); - double knots2si = 1852.0/3600; // Knots to metres/sec. - double ft2si = 12 * 2.54 / 100; // Feet to metres - if (ecLinearVel[0] == 0) { // MP packets for carriers have zero ecLinearVel, but do specify // velocities/speed-kts. double speed_kts = props->getDoubleValue("velocities/speed-kts"); - double speed_fps = speed_kts * knots2si / ft2si; + double speed_fps = speed_kts * SG_KT_TO_FPS; _uBodyNode->setDoubleValue(speed_fps); } @@ -767,7 +764,7 @@ void FGAIMultiplayer::update(double dt) // doesn't slip when carrier changes course. Also would be good to // handle vbody and wbody?] // - m_node_ai_latch_speed_kts->setDoubleValue(_uBodyNode->getDoubleValue() * ft2si / knots2si); + m_node_ai_latch_speed_kts->setDoubleValue(_uBodyNode->getDoubleValue() * SG_FPS_TO_KT); } assert(m_node_ai_latch == props->getNode("ai-latch")); diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index 9cc805219..d7b4d837c 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -240,16 +240,13 @@ void FGAIShip::update(double dt) { // Compute the velocity in m/s in the body frame // is in knots. - double knots2si = 1852.0/3600; - aip.setBodyLinearVelocity(SGVec3d(speed * knots2si, 0, 0)); + aip.setBodyLinearVelocity(SGVec3d(speed * SG_KT_TO_MPS, 0, 0)); // Update speed_fps so that velocities/uBody-fps will be set. // is in knots. // { - double knots2si = 1852.0/3600; // Knots to metres/sec. - double ft2si = 12 * 2.54 / 100; // Feet to metres - speed_fps = speed * knots2si / ft2si; + speed_fps = speed * SG_KT_TO_FPS; } FGAIBase::update(dt); Run(dt); @@ -331,9 +328,7 @@ void FGAIShip::Run(double dt) { z-back. */ SGQuatd q(-0.5, -0.5, 0.5, 0.5); - double knots2si = 1852.0/3600; - - SGVec3d offset(0, 0, -speed * knots2si * dt); + SGVec3d offset(0, 0, -speed * SG_KT_TO_MPS * dt); position += (ec2body * q).backTransform(offset); pos = SGGeod::fromCart(position);