00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "physicsManager.h"
00020 #include "actorNode.h"
00021
00022 #include <algorithm>
00023 #include "pvector.h"
00024
00025
00026
00027
00028
00029
00030
00031 PhysicsManager::
00032 PhysicsManager(void) {
00033 _linear_integrator.clear();
00034 _angular_integrator.clear();
00035 }
00036
00037
00038
00039
00040
00041
00042 PhysicsManager::
00043 ~PhysicsManager(void) {
00044 }
00045
00046
00047
00048
00049
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
00066
00067
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
00084
00085
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
00101
00102
00103
00104
00105 void PhysicsManager::
00106 do_physics(float dt) {
00107 pvector< Physical * >::iterator p_cur;
00108
00109
00110 p_cur = _physicals.begin();
00111
00112 for (; p_cur != _physicals.end(); p_cur++) {
00113 Physical *physical = *p_cur;
00114
00115
00116 if (_linear_integrator.is_null() == false) {
00117 _linear_integrator->integrate(physical, _linear_forces, dt);
00118 }
00119
00120
00121 if (_angular_integrator.is_null() == false) {
00122 _angular_integrator->integrate(physical, _angular_forces, dt);
00123 }
00124
00125
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 }