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

panda/src/physics/physicsManager.cxx

Go to the documentation of this file.
00001 // Filename: physicsManager.cxx
00002 // Created by:  charles (14Jun00)
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 "physicsManager.h"
00020 #include "actorNode.h"
00021 
00022 #include <algorithm>
00023 #include "pvector.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function : PhysicsManager
00027 //       Access : Public
00028 //  Description : Default Constructor.  NOTE: EulerIntegrator is
00029 //                the standard default.
00030 ////////////////////////////////////////////////////////////////////
00031 PhysicsManager::
00032 PhysicsManager(void) {
00033   _linear_integrator.clear();
00034   _angular_integrator.clear();
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function : ~PhysicsManager
00039 //       Access : Public
00040 //  Description : Simple Destructor
00041 ////////////////////////////////////////////////////////////////////
00042 PhysicsManager::
00043 ~PhysicsManager(void) {
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function : remove_linear_force
00048 //       Access : Public
00049 //  Description : takes a linear force out of the physics list
00050 ////////////////////////////////////////////////////////////////////
00051 void PhysicsManager::
00052 remove_linear_force(LinearForce *f) {
00053   pvector< PT(LinearForce) >::iterator found;
00054 
00055   PT(LinearForce) ptbf = f;
00056   found = find(_linear_forces.begin(), _linear_forces.end(), ptbf);
00057 
00058   if (found == _linear_forces.end())
00059     return;
00060 
00061   _linear_forces.erase(found);
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function : remove_angular_force
00066 //       Access : Public
00067 //  Description : takes an angular force out of the physics list
00068 ////////////////////////////////////////////////////////////////////
00069 void PhysicsManager::
00070 remove_angular_force(AngularForce *f) {
00071   pvector< PT(AngularForce) >::iterator found;
00072 
00073   PT(BaseForce) ptbf = f;
00074   found = find(_angular_forces.begin(), _angular_forces.end(), ptbf);
00075 
00076   if (found == _angular_forces.end())
00077     return;
00078 
00079   _angular_forces.erase(found);
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function : remove_physical
00084 //       Access : Public
00085 //  Description : takes a physical out of the object list
00086 ////////////////////////////////////////////////////////////////////
00087 void PhysicsManager::
00088 remove_physical(Physical *p) {
00089   pvector< Physical * >::iterator found;
00090 
00091   found = find(_physicals.begin(), _physicals.end(), p);
00092   if (found == _physicals.end())
00093     return;
00094 
00095   p->_physics_manager = (PhysicsManager *) NULL;
00096   _physicals.erase(found);
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function : DoPhysics
00101 //       Access : Public
00102 //  Description : This is the main high-level API call.  Performs
00103 //                integration on every attached Physical.
00104 ////////////////////////////////////////////////////////////////////
00105 void PhysicsManager::
00106 do_physics(float dt) {
00107   pvector< Physical * >::iterator p_cur;
00108 
00109   // now, run through each physics object in the set.
00110   p_cur = _physicals.begin();
00111 
00112   for (; p_cur != _physicals.end(); p_cur++) {
00113     Physical *physical = *p_cur;
00114 
00115     // do linear
00116     if (_linear_integrator.is_null() == false) {
00117       _linear_integrator->integrate(physical, _linear_forces, dt);
00118     }
00119 
00120     // do angular
00121     if (_angular_integrator.is_null() == false) {
00122       _angular_integrator->integrate(physical, _angular_forces, dt);
00123     }
00124 
00125     // if it's an actor node, tell it to update itself.
00126     PhysicalNode *pn = physical->get_physical_node();
00127     if (pn->is_of_type(ActorNode::get_class_type())) {
00128       ActorNode *an = (ActorNode *) pn;
00129       an->update_transform();
00130     }
00131   }
00132 }

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