From: frohlich Date: Sun, 1 Mar 2009 16:40:32 +0000 (+0000) Subject: Move the velocity computations for aimodels into AIShip. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3afc7e0690e5faf922d4c4288d462e15f37b66bb;p=flightgear.git Move the velocity computations for aimodels into AIShip. You should now be able to step on any ship with your model. Modified Files: src/AIModel/AICarrier.cxx src/AIModel/AIShip.cxx src/AIModel/AIShip.hxx --- diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index ff0d5441f..79653fc86 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -270,28 +269,10 @@ void FGAICarrier::setTACANChannelID(const string& id) { } void FGAICarrier::update(double dt) { - // For computation of rotation speeds we just use finite differences here. - // That is perfectly valid since this thing is not driven by accelerations - // but by just apply discrete changes at its velocity variables. - // Update the velocity information stored in those nodes. - // Transform that one to the horizontal local coordinate system. - SGQuatd ec2hl = SGQuatd::fromLonLat(pos); - // The orientation of the carrier wrt the horizontal local frame - SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); - // and postrotate the orientation of the AIModel wrt the horizontal - // local frame - SGQuatd ec2body = ec2hl*hl2body; - // The cartesian position of the carrier in the wgs84 world - SGVec3d cartPos = SGVec3d::fromGeod(pos); - - // Compute the velocity in m/s in the body frame - aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0)); - // Now update the position and heading. This will compute new hdg and // roll values required for the rotation speed computation. FGAIShip::update(dt); - //automatic turn into wind with a target wind of 25 kts otd if(turn_to_launch_hdg){ TurnToLaunch(); @@ -301,28 +282,19 @@ void FGAICarrier::update(double dt) { TurnToBase(); } - // Only change these values if we are able to compute them safely - if (SGLimits::min() < dt) { - // Now here is the finite difference ... - - // Transform that one to the horizontal local coordinate system. - SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos); - // compute the new orientation - SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); - // The rotation difference - SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew; - SGVec3d dOrAngleAxis; - dOr.getAngleAxis(dOrAngleAxis); - // divided by the time difference provides a rotation speed vector - dOrAngleAxis /= dt; - - aip.setBodyAngularVelocity(dOrAngleAxis); - } - UpdateWind(dt); UpdateElevator(dt, transition_time); UpdateJBD(dt, jbd_transition_time); - // For the flols reuse some computations done above ... + + // Transform that one to the horizontal local coordinate system. + SGQuatd ec2hl = SGQuatd::fromLonLat(pos); + // The orientation of the carrier wrt the horizontal local frame + SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); + // and postrotate the orientation of the AIModel wrt the horizontal + // local frame + SGQuatd ec2body = ec2hl*hl2body; + // The cartesian position of the carrier in the wgs84 world + SGVec3d cartPos = SGVec3d::fromGeod(pos); // The position of the eyepoint - at least near that ... SGVec3d eyePos(globals->get_current_view()->get_view_pos()); @@ -405,7 +377,6 @@ void FGAICarrier::initModel(osg::Node *node) // mark some objects solid, mark the wires ... FGCarrierVisitor carrierVisitor(this, wire_objects, catapult_objects); model->accept(carrierVisitor); - model->setNodeMask(model->getNodeMask() | SG_NODEMASK_TERRAIN_BIT); } void FGAICarrier::bind() { diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index f7f0852ed..45413dea4 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include "AIShip.hxx" @@ -115,6 +116,10 @@ bool FGAIShip::init(bool search_in_AI_path) { return FGAIBase::init(search_in_AI_path); } +void FGAIShip::initModel(osg::Node *node) { + FGAIBase::initModel(node); + model->setNodeMask(model->getNodeMask() | SG_NODEMASK_TERRAIN_BIT); +} void FGAIShip::bind() { FGAIBase::bind(); @@ -182,9 +187,44 @@ void FGAIShip::unbind() { } void FGAIShip::update(double dt) { + // For computation of rotation speeds we just use finite differences here. + // That is perfectly valid since this thing is not driven by accelerations + // but by just apply discrete changes at its velocity variables. + // Update the velocity information stored in those nodes. + // Transform that one to the horizontal local coordinate system. + SGQuatd ec2hl = SGQuatd::fromLonLat(pos); + // The orientation of the carrier wrt the horizontal local frame + SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); + // and postrotate the orientation of the AIModel wrt the horizontal + // local frame + SGQuatd ec2body = ec2hl*hl2body; + // The cartesian position of the carrier in the wgs84 world + SGVec3d cartPos = SGVec3d::fromGeod(pos); + + // Compute the velocity in m/s in the body frame + aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0)); + FGAIBase::update(dt); Run(dt); Transform(); + + // Only change these values if we are able to compute them safely + if (SGLimits::min() < dt) { + // Now here is the finite difference ... + + // Transform that one to the horizontal local coordinate system. + SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos); + // compute the new orientation + SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); + // The rotation difference + SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew; + SGVec3d dOrAngleAxis; + dOr.getAngleAxis(dOrAngleAxis); + // divided by the time difference provides a rotation speed vector + dOrAngleAxis /= dt; + + aip.setBodyAngularVelocity(dOrAngleAxis); + } } void FGAIShip::Run(double dt) { diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index f4a622310..491c02489 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -37,6 +37,7 @@ public: virtual void readFromScenario(SGPropertyNode* scFileNode); virtual bool init(bool search_in_AI_path=false); + virtual void initModel(osg::Node *node); virtual void bind(); virtual void unbind(); virtual void update(double dt);