trying to update -- not finished yet.

This commit is contained in:
Dave Schuyler 2003-06-11 04:55:51 +00:00
parent 4cca0ea212
commit 73e7f692d5

View File

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