00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include "physical.h"
00021 #include "physicsManager.h"
00022 #include "forces.h"
00023
00024 class Baseball : public Physical
00025 {
00026 public:
00027
00028 int ttl_balls;
00029 int color;
00030
00031 Baseball(int tb = 1) : ttl_balls(tb), Physical(tb, true) {}
00032 };
00033
00034 int main(int, char **)
00035 {
00036 PhysicsManager physics_manager;
00037 Baseball b(8);
00038
00039 int i = 0;
00040
00041
00042
00043 Baseball nf_b;
00044 nf_b._phys_body->set_position(0.0f, 0.0f, 0.0f);
00045 nf_b._phys_body->set_velocity(1.0f / 16.0f, 0.0f, 0.0f);
00046 nf_b._phys_body->set_processflag(true);
00047 nf_b._phys_body->set_mass(1.0f);
00048
00049 NoiseForce nf(1.0, false);
00050
00051 physics_manager.attach_physical(&nf_b);
00052
00053 for (int monkey = 0; monkey < 16; monkey++)
00054 {
00055 cout << "ball: " << nf_b._phys_body->get_position() << endl;
00056 cout << "nf: " << nf.get_vector(nf_b._phys_body) << endl;
00057
00058 physics_manager.do_physics(1.0f / 16.0f);
00059 }
00060
00061 physics_manager.remove_physical(&nf_b);
00062
00063
00064
00065 b.add_force(new JitterForce(0.1f));
00066
00067 for (i = 0; i < b.ttl_balls; i++)
00068 {
00069 b._physics_objects[i]->set_position(i * 2.0f, float(i), 0.0f);
00070 b._physics_objects[i]->set_velocity(5.0f, 0.0f, 30.0f);
00071 b._physics_objects[i]->set_processflag(true);
00072 b._physics_objects[i]->set_mass(1.0f);
00073 }
00074
00075 physics_manager.attach_physical(&b);
00076 physics_manager.add_force(new VectorForce(0.0f, 0.0f, -9.8f, 1.0f, false));
00077
00078 cout << "Object vector:" << endl;
00079
00080 for (i = 0; i < b.ttl_balls; i++)
00081 {
00082 cout << "vel: " << b._physics_objects[i]->get_velocity() << " ";
00083 cout << "pos: " << b._physics_objects[i]->get_position() << endl;
00084 }
00085
00086 physics_manager.do_physics(1.0f);
00087
00088 cout << "Physics have been applied." << endl;
00089
00090 for (i = 0; i < b.ttl_balls; i++)
00091 {
00092 cout << "vel: " << b._physics_objects[i]->get_velocity() << " ";
00093 cout << "pos: " << b._physics_objects[i]->get_position() << endl;
00094 }
00095 }
00096