]> git.mxchange.org Git - flightgear.git/commitdiff
Move the velocity computations for aimodels into AIShip.
authorfrohlich <frohlich>
Sun, 1 Mar 2009 16:40:32 +0000 (16:40 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 5 Mar 2009 09:52:03 +0000 (10:52 +0100)
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

src/AIModel/AICarrier.cxx
src/AIModel/AIShip.cxx
src/AIModel/AIShip.hxx

index ff0d5441ff46d6db15054f593288cace1da66cc8..79653fc8617f3f51c6ca09bdd367a1fbe54da031 100644 (file)
@@ -34,7 +34,6 @@
 #include <simgear/sg_inlines.h>
 #include <simgear/math/SGMath.hxx>
 #include <simgear/math/sg_geodesy.hxx>
-#include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/scene/util/SGSceneUserData.hxx>
 #include <simgear/scene/bvh/BVHGroup.hxx>
 #include <simgear/scene/bvh/BVHLineGeometry.hxx>
@@ -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<double>::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() {
index f7f0852ed340ee38590435c4e67d5024ba425f6b..45413dea44f27bd38c8f6c49f889fc825e278ac7 100644 (file)
@@ -32,6 +32,7 @@
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/timing/sg_time.hxx>
 #include <simgear/math/sg_random.h>
+#include <simgear/scene/util/SGNodeMasks.hxx>
 
 #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<double>::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) {
index f4a622310c6b5ef3d09a08132245809adc8daea9..491c024897eecdf3348f7ea871eb217b35889819 100644 (file)
@@ -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);