nrtb-core team mailing list archive
-
nrtb-core team
-
Mailing list archive
-
Message #00582
[Merge] lp:~fpstovall/nrtb/fps-bugsfix-005 into lp:~fpstovall/nrtb/sprint-005
Rick Stovall has proposed merging lp:~fpstovall/nrtb/fps-bugsfix-005 into lp:~fpstovall/nrtb/sprint-005.
Requested reviews:
NRTB Core (nrtb-core): code
Related bugs:
Bug #1272383 in New Real Time Battle: "Clean up force application code."
https://bugs.launchpad.net/nrtb/+bug/1272383
Bug #1272427 in New Real Time Battle: "Missing an abstract collision hook in base_object"
https://bugs.launchpad.net/nrtb/+bug/1272427
Bug #1272733 in New Real Time Battle: "base_object::check_collision() should take an object pointer."
https://bugs.launchpad.net/nrtb/+bug/1272733
For more details, see:
https://code.launchpad.net/~fpstovall/nrtb/fps-bugsfix-005/+merge/203219
Three bug fixes to the base_object class which are needed for proper simulation operation.
--
https://code.launchpad.net/~fpstovall/nrtb/fps-bugsfix-005/+merge/203219
Your team NRTB Core is requested to review the proposed merge of lp:~fpstovall/nrtb/fps-bugsfix-005 into lp:~fpstovall/nrtb/sprint-005.
=== 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-01-25 21:00:16 +0000
@@ -72,8 +72,8 @@
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);
+ velocity += (a + accel_mod) * quanta;
+ rotation += (ra + torque_mod) * quanta;
location += velocity * quanta;
attitude += rotation * quanta;
// apply post-effectors
@@ -84,11 +84,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 21:00:16 +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-01-25 21:00:16 +0000
@@ -72,6 +72,14 @@
};
};
+class my_object : public base_object
+{
+ bool apply_collision(object_p o)
+ {
+ return false;
+ };
+};
+
int main()
{
bool failed = false;
@@ -79,7 +87,7 @@
<< 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,7 +131,43 @@
cout << "Impact:" << time*0.02<< " sec." << endl;
cout << rocket_ball.as_str() << endl;
failed = failed or (time != 80);
-
+
+ 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 << "=========== sim_messages test complete ============="
<< endl;