]> git.mxchange.org Git - flightgear.git/commitdiff
Added a new TimedAnimation, using the type "timed" and the property
authordavid <david>
Wed, 6 Nov 2002 15:47:40 +0000 (15:47 +0000)
committerdavid <david>
Wed, 6 Nov 2002 15:47:40 +0000 (15:47 +0000)
duration-sec.  This animation may have any number of child objects,
and each one will be displayed for the requested duration before
moving on to the next one.

Added Animation::init for initialization after children have been
added to an animation.

Added a default implementation of Animation::update, and removed all
of the empty ones in derived classes.

Removed tabs from model.cxx.

src/Model/model.cxx
src/Model/model.hxx

index 026438332c3391a52c58f607f5b73abc517551fa..b32d054ee9c20ae103ba45633db5cc5daa5fddde 100644 (file)
@@ -142,7 +142,7 @@ set_translation (sgMat4 &matrix, double position_m, sgVec3 &axis)
  */
 static void
 make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot,
-                    double x_off, double y_off, double z_off)
+                     double x_off, double y_off, double z_off)
 {
   sgMat4 rot_matrix;
   sgMat4 pos_matrix;
@@ -164,7 +164,7 @@ read_interpolation_table (SGPropertyNode_ptr props)
     vector<SGPropertyNode_ptr> entries = table_node->getChildren("entry");
     for (unsigned int i = 0; i < entries.size(); i++)
       table->addEntry(entries[i]->getDoubleValue("ind", 0.0),
-                     entries[i]->getDoubleValue("dep", 0.0));
+                      entries[i]->getDoubleValue("dep", 0.0));
     return table;
   } else {
     return 0;
@@ -190,6 +190,8 @@ make_animation (ssgBranch * model,
     animation = new SelectAnimation(node);
   } else if (!strcmp("spin", type)) {
     animation = new SpinAnimation(node);
+  } else if (!strcmp("timed", type)) {
+    animation = new TimedAnimation(node);
   } else if (!strcmp("rotate", type)) {
     animation = new RotateAnimation(node);
   } else if (!strcmp("translate", type)) {
@@ -231,6 +233,7 @@ make_animation (ssgBranch * model,
       oldParent->removeKid(object);
   }
 
+  animation->init();
   branch->setUserData(animation);
   branch->setTravCallback(SSG_CALLBACK_PRETRAV, animation_callback);
 }
@@ -266,7 +269,7 @@ fgLoad3DModel (const string &path)
       modelpath.append(props.getStringValue("/path"));
     } else {
       if (model == 0)
-       model = new ssgBranch;
+        model = new ssgBranch;
     }
   }
 
@@ -284,12 +287,12 @@ fgLoad3DModel (const string &path)
   align->addKid(model);
   sgMat4 res_matrix;
   make_offsets_matrix(&res_matrix,
-                     props.getFloatValue("/offsets/heading-deg", 0.0),
-                     props.getFloatValue("/offsets/roll-deg", 0.0),
-                     props.getFloatValue("/offsets/pitch-deg", 0.0),
-                     props.getFloatValue("/offsets/x-m", 0.0),
-                     props.getFloatValue("/offsets/y-m", 0.0),
-                     props.getFloatValue("/offsets/z-m", 0.0));
+                      props.getFloatValue("/offsets/heading-deg", 0.0),
+                      props.getFloatValue("/offsets/roll-deg", 0.0),
+                      props.getFloatValue("/offsets/pitch-deg", 0.0),
+                      props.getFloatValue("/offsets/x-m", 0.0),
+                      props.getFloatValue("/offsets/y-m", 0.0),
+                      props.getFloatValue("/offsets/z-m", 0.0));
   align->setTransform(res_matrix);
 
                                 // Load animations
@@ -310,19 +313,19 @@ fgLoad3DModel (const string &path)
     model->addKid(panel);
   }
 
-                               // Load sub-models
+                                // Load sub-models
   vector<SGPropertyNode_ptr> model_nodes = props.getChildren("model");
   for (i = 0; i < model_nodes.size(); i++) {
     SGPropertyNode_ptr node = model_nodes[i];
     ssgTransform * align = new ssgTransform;
     sgMat4 res_matrix;
     make_offsets_matrix(&res_matrix,
-                       node->getFloatValue("offsets/heading-deg", 0.0),
-                       node->getFloatValue("offsets/roll-deg", 0.0),
-                       node->getFloatValue("offsets/pitch-deg", 0.0),
-                       node->getFloatValue("offsets/x-m", 0.0),
-                       node->getFloatValue("offsets/y-m", 0.0),
-                       node->getFloatValue("offsets/z-m", 0.0));
+                        node->getFloatValue("offsets/heading-deg", 0.0),
+                        node->getFloatValue("offsets/roll-deg", 0.0),
+                        node->getFloatValue("offsets/pitch-deg", 0.0),
+                        node->getFloatValue("offsets/x-m", 0.0),
+                        node->getFloatValue("offsets/y-m", 0.0),
+                        node->getFloatValue("offsets/z-m", 0.0));
     align->setTransform(res_matrix);
 
     ssgBranch * kid = fgLoad3DModel(node->getStringValue("path"));
@@ -349,6 +352,16 @@ Animation::~Animation ()
 {
 }
 
+void
+Animation::init ()
+{
+}
+
+void
+Animation::update ()
+{
+}
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -364,11 +377,6 @@ NullAnimation::~NullAnimation ()
 {
 }
 
-void
-NullAnimation::update ()
-{
-}
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -388,11 +396,6 @@ RangeAnimation::~RangeAnimation ()
 {
 }
 
-void
-RangeAnimation::update ()
-{
-}
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -408,11 +411,6 @@ BillboardAnimation::~BillboardAnimation ()
 {
 }
 
-void
-BillboardAnimation::update ()
-{
-}
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -486,6 +484,38 @@ SpinAnimation::update ()
 }
 
 
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of TimedAnimation
+////////////////////////////////////////////////////////////////////////
+
+TimedAnimation::TimedAnimation (SGPropertyNode_ptr props)
+  : Animation(props, new ssgSelector),
+    _duration_sec(props->getDoubleValue("duration-sec", 1.0)),
+    _last_time_sec(0),
+    _step(-1)
+{
+}
+
+TimedAnimation::~TimedAnimation ()
+{
+}
+
+void
+TimedAnimation::update ()
+{
+    float sim_time_sec = globals->get_sim_time_sec();
+    if ((sim_time_sec - _last_time_sec) >= _duration_sec) {
+        _last_time_sec = sim_time_sec;
+        if (_step >= getBranch()->getNumKids())
+            _step = 0;
+        else
+            _step++;
+        ((ssgSelector *)getBranch())->selectStep(_step);
+    }
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of RotateAnimation
@@ -690,7 +720,7 @@ FGModelPlacement::setHeadingDeg (double heading_deg)
 
 void
 FGModelPlacement::setOrientation (double roll_deg, double pitch_deg,
-                                 double heading_deg)
+                                  double heading_deg)
 {
   _roll_deg = roll_deg;
   _pitch_deg = pitch_deg;
index 18e320e1ebbb0fa7227186ef971936dc5b3dd1d7..861075b50945901cbee17132960e7640c4f36c7a 100644 (file)
@@ -75,10 +75,15 @@ public:
    */
   virtual ssgBranch * getBranch () { return _branch; }
 
+  /**
+   * Initialize the animation, after children have been added.
+   */
+  virtual void init ();
+
   /**
    * Update the animation.
    */
-  virtual void update () = 0;
+  virtual void update ();
 
 protected:
 
@@ -95,7 +100,6 @@ class NullAnimation : public Animation
 public:
   NullAnimation (SGPropertyNode_ptr props);
   virtual ~NullAnimation ();
-  virtual void update ();
 };
 
 
@@ -107,7 +111,6 @@ class RangeAnimation : public Animation
 public:
   RangeAnimation (SGPropertyNode_ptr props);
   virtual ~RangeAnimation ();
-  virtual void update ();
 };
 
 
@@ -119,7 +122,6 @@ class BillboardAnimation : public Animation
 public:
   BillboardAnimation (SGPropertyNode_ptr props);
   virtual ~BillboardAnimation ();
-  virtual void update ();
 };
 
 
@@ -159,6 +161,22 @@ private:
 };
 
 
+/**
+ * Animation to draw objects for a specific amount of time each.
+ */
+class TimedAnimation : public Animation
+{
+public:
+    TimedAnimation (SGPropertyNode_ptr props);
+    virtual ~TimedAnimation ();
+    virtual void update ();
+private:
+    double _duration_sec;
+    double _last_time_sec;
+    int _step;
+};
+
+
 /**
  * Animation to rotate an object around a center point.
  *