diff --git a/panda/src/physics/test_physics.cxx b/panda/src/physics/test_physics.cxx index 732b9a87db..90cad045cd 100644 --- a/panda/src/physics/test_physics.cxx +++ b/panda/src/physics/test_physics.cxx @@ -21,76 +21,71 @@ #include "physicsManager.h" #include "forces.h" -class Baseball : public Physical -{ - public: +class Baseball : public Physical { +public: + int ttl_balls; + int color; - int ttl_balls; - int color; - - Baseball(int tb = 1) : ttl_balls(tb), Physical(tb, true) {} + Baseball(int tb = 1) : ttl_balls(tb), Physical(tb, true) {} }; -int main(int, char **) -{ +int main(int, char **) { PhysicsManager physics_manager; Baseball b(8); - int i = 0; - // test the noise force - Baseball nf_b; - nf_b._phys_body->set_position(0.0f, 0.0f, 0.0f); - nf_b._phys_body->set_velocity(1.0f / 16.0f, 0.0f, 0.0f); - nf_b._phys_body->set_processflag(true); - nf_b._phys_body->set_mass(1.0f); - - NoiseForce nf(1.0, false); + nf_b.get_phys_body()->set_position(0.0f, 0.0f, 0.0f); + nf_b.get_phys_body()->set_velocity(1.0f / 16.0f, 0.0f, 0.0f); + nf_b.get_phys_body()->set_active(true); + nf_b.get_phys_body()->set_mass(1.0f); + LinearNoiseForce nf(1.0, false); physics_manager.attach_physical(&nf_b); - for (int monkey = 0; monkey < 16; monkey++) - { - cout << "ball: " << nf_b._phys_body->get_position() << endl; - cout << "nf: " << nf.get_vector(nf_b._phys_body) << endl; - - physics_manager.do_physics(1.0f / 16.0f); + int steps=16; + float delta_time=1.0f/(float)steps; + while (steps--) { + cout << "ball: " << nf_b.get_phys_body()->get_position() << endl; + cout << "nf: " << nf.get_vector(nf_b.get_phys_body()) << endl; + physics_manager.do_physics(delta_time); } physics_manager.remove_physical(&nf_b); // get on with life - b.add_force(new JitterForce(0.1f)); - - for (i = 0; i < b.ttl_balls; i++) - { - b._physics_objects[i]->set_position(i * 2.0f, float(i), 0.0f); - b._physics_objects[i]->set_velocity(5.0f, 0.0f, 30.0f); - b._physics_objects[i]->set_processflag(true); - b._physics_objects[i]->set_mass(1.0f); + b.add_linear_force(new LinearJitterForce(0.1f)); + + int i=0; + for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin(); + co != b.get_object_vector().end(); + ++i, ++co) { + (*co)->set_position(i * 2.0f, float(i), 0.0f); + (*co)->set_velocity(5.0f, 0.0f, 30.0f); + (*co)->set_active(true); + (*co)->set_mass(1.0f); } physics_manager.attach_physical(&b); - physics_manager.add_force(new VectorForce(0.0f, 0.0f, -9.8f, 1.0f, false)); + physics_manager.add_linear_force(new LinearVectorForce(0.0f, 0.0f, -9.8f, 1.0f, false)); cout << "Object vector:" << endl; - - for (i = 0; i < b.ttl_balls; i++) - { - cout << "vel: " << b._physics_objects[i]->get_velocity() << " "; - cout << "pos: " << b._physics_objects[i]->get_position() << endl; + for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin(); + co != b.get_object_vector().end(); + ++co) { + cout << "vel: " << (*co)->get_velocity() << " "; + cout << "pos: " << (*co)->get_position() << endl; } physics_manager.do_physics(1.0f); - cout << "Physics have been applied." << endl; - for (i = 0; i < b.ttl_balls; i++) - { - cout << "vel: " << b._physics_objects[i]->get_velocity() << " "; - cout << "pos: " << b._physics_objects[i]->get_position() << endl; + for (Physical::PhysicsObjectVector::const_iterator co=b.get_object_vector().begin(); + co != b.get_object_vector().end(); + ++co) { + cout << "vel: " << (*co)->get_velocity() << " "; + cout << "pos: " << (*co)->get_position() << endl; } }