00001 // Filename: forceNode.cxx 00002 // Created by: charles (02Aug00) 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 "forceNode.h" 00020 #include "config_physics.h" 00021 00022 TypeHandle ForceNode::_type_handle; 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function : ForceNode 00026 // Access : public 00027 // Description : default constructor 00028 //////////////////////////////////////////////////////////////////// 00029 ForceNode:: 00030 ForceNode(const string &name) : 00031 PandaNode(name) 00032 { 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function : ForceNode 00037 // Access : protected 00038 // Description : copy constructor 00039 //////////////////////////////////////////////////////////////////// 00040 ForceNode:: 00041 ForceNode(const ForceNode ©) : 00042 PandaNode(copy), _forces(copy._forces) { 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function : ~ForceNode 00047 // Access : public, virtual 00048 // Description : destructor 00049 //////////////////////////////////////////////////////////////////// 00050 ForceNode:: 00051 ~ForceNode(void) { 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function : make_copy 00056 // Access : public, virtual 00057 // Description : dynamic child copy 00058 //////////////////////////////////////////////////////////////////// 00059 PandaNode *ForceNode:: 00060 make_copy(void) const { 00061 return new ForceNode(*this); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function : add_forces_from 00066 // Access : public 00067 // Description : append operation 00068 //////////////////////////////////////////////////////////////////// 00069 void ForceNode:: 00070 add_forces_from(const ForceNode &other) { 00071 pvector< PT(BaseForce) >::iterator last = _forces.end() - 1; 00072 00073 _forces.insert(_forces.end(), 00074 other._forces.begin(), other._forces.end()); 00075 00076 for (; last != _forces.end(); last++) 00077 (*last)->_force_node = this; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function : remove_force 00082 // Access : public 00083 // Description : remove operation 00084 //////////////////////////////////////////////////////////////////// 00085 void ForceNode:: 00086 remove_force(BaseForce *f) { 00087 pvector< PT(BaseForce) >::iterator found; 00088 PT(BaseForce) ptbf = f; 00089 found = find(_forces.begin(), _forces.end(), ptbf); 00090 if (found == _forces.end()) 00091 return; 00092 _forces.erase(found); 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function : remove_force 00097 // Access : public 00098 // Description : remove operation 00099 //////////////////////////////////////////////////////////////////// 00100 void ForceNode:: 00101 remove_force(int index) { 00102 nassertv(index >= 0 && index <= (int)_forces.size()); 00103 00104 pvector< PT(BaseForce) >::iterator remove; 00105 remove = _forces.begin() + index; 00106 (*remove)->_force_node = (ForceNode *) NULL; 00107 00108 _forces.erase(remove); 00109 }