Panda3D
|
00001 // Filename: physicalNode.cxx 00002 // Created by: charles (01Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "physicalNode.h" 00016 00017 // static stuff. 00018 TypeHandle PhysicalNode::_type_handle; 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function : PhysicalNode 00022 // Access : public 00023 // Description : default constructor 00024 //////////////////////////////////////////////////////////////////// 00025 PhysicalNode:: 00026 PhysicalNode(const string &name) : 00027 PandaNode(name) 00028 { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function : PhysicalNode 00033 // Access : protected 00034 // Description : copy constructor 00035 //////////////////////////////////////////////////////////////////// 00036 PhysicalNode:: 00037 PhysicalNode(const PhysicalNode ©) : 00038 PandaNode(copy), _physicals(copy._physicals) { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function : ~PhysicalNode 00043 // Access : protected, virtual 00044 // Description : destructor 00045 //////////////////////////////////////////////////////////////////// 00046 PhysicalNode:: 00047 ~PhysicalNode() { 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function : make_copy 00052 // Access : public, virtual 00053 // Description : dynamic child copy 00054 //////////////////////////////////////////////////////////////////// 00055 PandaNode *PhysicalNode:: 00056 make_copy() const { 00057 return new PhysicalNode(*this); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function : add_physicals_from 00062 // Access : public 00063 // Description : append operation 00064 //////////////////////////////////////////////////////////////////// 00065 void PhysicalNode:: 00066 add_physicals_from(const PhysicalNode &other) { 00067 pvector< PT(Physical) >::iterator last = _physicals.end() - 1; 00068 00069 _physicals.insert(_physicals.end(), 00070 other._physicals.begin(), other._physicals.end()); 00071 00072 NodePath node_path(this); 00073 for (; last != _physicals.end(); last++) { 00074 (*last)->_physical_node = this; 00075 (*last)->_physical_node_path = node_path; 00076 } 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function : remove_physical 00081 // Access : public 00082 // Description : remove operation 00083 //////////////////////////////////////////////////////////////////// 00084 void PhysicalNode:: 00085 remove_physical(Physical *physical) { 00086 pvector< PT(Physical) >::iterator found; 00087 PT(Physical) ptp = physical; 00088 found = find(_physicals.begin(), _physicals.end(), ptp); 00089 if (found == _physicals.end()) 00090 return; 00091 _physicals.erase(found); 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function : remove_physical 00096 // Access : public 00097 // Description : remove operation 00098 //////////////////////////////////////////////////////////////////// 00099 void PhysicalNode:: 00100 remove_physical(int index) { 00101 nassertv(index >= 0 && index <= (int)_physicals.size()); 00102 00103 pvector< PT(Physical) >::iterator remove; 00104 remove = _physicals.begin() + index; 00105 (*remove)->_physical_node = (PhysicalNode *) NULL; 00106 (*remove)->_physical_node_path = NodePath(); 00107 00108 _physicals.erase(remove); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function : write 00113 // Access : Public 00114 // Description : Write a string representation of this instance to 00115 // <out>. 00116 //////////////////////////////////////////////////////////////////// 00117 void PhysicalNode:: 00118 write(ostream &out, unsigned int indent) const { 00119 #ifndef NDEBUG //[ 00120 out.width(indent); out<<""; out<<"PhysicalNode:\n"; 00121 //PandaNode::write(out, indent+2); 00122 #endif //] NDEBUG 00123 }