Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/physics/test_physics.cxx

Go to the documentation of this file.
00001 // Filename: test_physics.cxx
00002 // Created by:  charles (13Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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   // test the noise force
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   // get on with life
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 

Generated on Fri May 2 00:43:05 2003 for Panda by doxygen1.3