← Back to team overview

nrtb-core team mailing list archive

[Branch ~nrtb-core/nrtb/alpha] Rev 18: Merged base_object bug-fixes.

 

Merge authors:
  Rick Stovall <fpstovall>
Related merge proposals:
  https://code.launchpad.net/~fpstovall/nrtb/sprint-005/+merge/209358
  proposed by: Rick Stovall (fpstovall)
  review: Approve - Rick Stovall (fpstovall)
------------------------------------------------------------
revno: 18 [merge]
committer: Rick Stovall <fpstovall>
branch nick: alpha
timestamp: Sun 2014-03-16 17:21:28 -0400
message:
  Merged base_object bug-fixes.
modified:
  cpp/sim_engine/base_object/base_object.cpp
  cpp/sim_engine/base_object/base_object.h
  cpp/sim_engine/base_object/base_object_test.cpp


--
lp:nrtb
https://code.launchpad.net/~nrtb-core/nrtb/alpha

Your team NRTB Core is subscribed to branch lp:nrtb.
To unsubscribe from this branch go to https://code.launchpad.net/~nrtb-core/nrtb/alpha/+edit-subscription
=== modified file 'cpp/sim_engine/base_object/base_object.cpp'
--- cpp/sim_engine/base_object/base_object.cpp	2014-01-12 17:24:44 +0000
+++ cpp/sim_engine/base_object/base_object.cpp	2014-02-20 02:33:34 +0000
@@ -72,10 +72,15 @@
   float tmass = mass + mass_mod;
   triplet a = force / tmass;
   triplet ra = torque / (tmass * 0.5); // not accurate!!
-  velocity += (a * quanta) + (accel_mod * quanta);
-  rotation += (ra * quanta) + (torque_mod * quanta);
-  location += velocity * quanta;
-  attitude += rotation * quanta;
+  // compute quanta effective Vs
+  triplet ev = velocity + (((a + accel_mod)/2) * quanta);
+  triplet er = rotation + (((ra + torque_mod)/2) * quanta);
+  // compute final velocities for the quanta
+  velocity += (a  + accel_mod) * quanta;
+  rotation += (ra + torque_mod) * quanta;
+  // update position, attitude
+  location += ev * quanta;
+  attitude += er * quanta;
   // apply post-effectors
   bool killme (false);
   for (auto e : post_attribs)
@@ -84,11 +89,12 @@
   return killme;
 };
 
-bool base_object::check_collision(sphere s)
+bool base_object::check_collision(object_p o)
 {
-  float r = s.radius + bounding_sphere.radius;
-  return r <= 
-    s.center.range(bounding_sphere.center+location);
+  float r = o->bounding_sphere.radius + bounding_sphere.radius;
+  triplet adjusted = o->bounding_sphere.center;
+  adjusted += o->location;
+  return (r >= adjusted.range(bounding_sphere.center+location));
 };
 
 void base_object::add_pre(abs_effector* e)

=== modified file 'cpp/sim_engine/base_object/base_object.h'
--- cpp/sim_engine/base_object/base_object.h	2014-01-05 00:33:52 +0000
+++ cpp/sim_engine/base_object/base_object.h	2014-01-25 18:55:09 +0000
@@ -76,9 +76,12 @@
   virtual void add_post(abs_effector * e);
   virtual abs_effector & get_post(unsigned long long i);
   // sim methods
+  // returns true if a collision is detected.
+  virtual bool check_collision(object_p o);
+  // the following return true if the object is destroyed.
   virtual bool tick(int time);
   virtual bool apply(int time, float quanta);
-  virtual bool check_collision(sphere s);
+  virtual bool apply_collision(object_p o) = 0;
 protected:
   effector_list pre_attribs;
   effector_list post_attribs;    

=== modified file 'cpp/sim_engine/base_object/base_object_test.cpp'
--- cpp/sim_engine/base_object/base_object_test.cpp	2014-01-12 17:13:10 +0000
+++ cpp/sim_engine/base_object/base_object_test.cpp	2014-02-20 02:33:34 +0000
@@ -72,14 +72,22 @@
   };  
 };
 
+class my_object : public base_object
+{
+  bool apply_collision(object_p o) 
+  {
+    return false;
+  };
+};
+
 int main()
 {
   bool failed = false;
-  cout << "=========== sim messages test ============="
+  cout << "========== base_object test ============="
     << endl;
 
   cout << "Object setup:" << endl;
-  base_object rocket_ball;
+  my_object rocket_ball;
   rocket_ball.mass = 100;
   rocket_ball.bounding_sphere.center = triplet(0);
   rocket_ball.bounding_sphere.radius = 0.5;
@@ -123,8 +131,44 @@
   cout << "Impact:" << time*0.02<< " sec." << endl;
   cout << rocket_ball.as_str() << endl;
   failed = failed or (time != 80);
-
-  cout << "=========== sim_messages test complete ============="
+  
+  cout << "\n** Flight Test: " << (failed ? "Failed" : "Passed") << endl;
+  
+  // collision tests.
+  my_object fixed = rocket_ball;
+  fixed.location = 0;
+  object_p mobile(new my_object);
+  mobile->bounding_sphere = fixed.bounding_sphere;
+  stringstream results;
+  
+  // check at various distances.
+  mobile->location = triplet(0,2,0);
+  bool t = fixed.check_collision(mobile);
+  results << fixed.location.range(mobile->location)
+    << "=" << t << ",";
+  
+  mobile->location = triplet(0,1.01,0);
+  t = fixed.check_collision(mobile);
+  results << fixed.location.range(mobile->location)
+    << "=" << t << ",";
+
+  mobile->location = triplet(0,1,0);
+  t = fixed.check_collision(mobile);
+  results << fixed.location.range(mobile->location)
+    << "=" << t << ",";
+
+  mobile->location = triplet(0);
+  t = fixed.check_collision(mobile);
+  results << fixed.location.range(mobile->location)
+    << "=" << t;
+  
+  bool c = results.str() != "2=0,1.01=0,1=1,0=1";
+  cout << results.str() << endl;
+  cout << "** Collision Test: " << (c ? "Failed" : "Passed") << endl;
+  
+  failed = failed or c;
+  
+  cout << "=========== base_object test complete ============="
     << endl;
   
   return failed;