Panda3D
physicalNode.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physicalNode.cxx
10  * @author charles
11  * @date 2000-08-01
12  */
13 
14 #include "physicalNode.h"
15 #include "physicsManager.h"
16 
17 // static stuff.
18 TypeHandle PhysicalNode::_type_handle;
19 
20 /**
21  * default constructor
22  */
24 PhysicalNode(const std::string &name) :
25  PandaNode(name)
26 {
27 }
28 
29 /**
30  * copy constructor
31  */
33 PhysicalNode(const PhysicalNode &copy) :
34  PandaNode(copy), _physicals(copy._physicals) {
35 }
36 
37 /**
38  * destructor
39  */
42  PhysicalsVector::iterator it;
43  for (it = _physicals.begin(); it != _physicals.end(); ++it) {
44  Physical *physical = *it;
45  nassertd(physical->_physical_node == this) continue;
46  physical->_physical_node = nullptr;
47  if (physical->_physics_manager != nullptr) {
48  physical->_physics_manager->remove_physical(physical);
49  }
50  }
51 }
52 
53 /**
54  * dynamic child copy
55  */
57 make_copy() const {
58  return new PhysicalNode(*this);
59 }
60 
61 /**
62  * append operation
63  */
64 void PhysicalNode::
66  pvector< PT(Physical) >::iterator last = _physicals.end() - 1;
67 
68  _physicals.insert(_physicals.end(),
69  other._physicals.begin(), other._physicals.end());
70 
71  for (; last != _physicals.end(); last++) {
72  (*last)->_physical_node = this;
73  }
74 }
75 
76 /**
77  * replace operation
78  */
79 void PhysicalNode::
80 set_physical(size_t index, Physical *physical) {
81  nassertv(index < _physicals.size());
82 
83  _physicals[index]->_physical_node = nullptr;
84  _physicals[index] = physical;
85  physical->_physical_node = this;
86 }
87 
88 /**
89  * insert operation
90  */
91 void PhysicalNode::
92 insert_physical(size_t index, Physical *physical) {
93  if (index > _physicals.size()) {
94  index = _physicals.size();
95  }
96 
97  _physicals.insert(_physicals.begin() + index, physical);
98  physical->_physical_node = this;
99 }
100 
101 /**
102  * remove operation
103  */
104 void PhysicalNode::
105 remove_physical(Physical *physical) {
106  pvector< PT(Physical) >::iterator found;
107  PT(Physical) ptp = physical;
108  found = find(_physicals.begin(), _physicals.end(), ptp);
109  if (found == _physicals.end()) {
110  return;
111  }
112  _physicals.erase(found);
113 
114  nassertv(ptp->_physical_node == this);
115  ptp->_physical_node = nullptr;
116 }
117 
118 /**
119  * remove operation
120  */
121 void PhysicalNode::
122 remove_physical(size_t index) {
123  nassertv(index <= _physicals.size());
124 
125  pvector< PT(Physical) >::iterator remove;
126  remove = _physicals.begin() + index;
127  (*remove)->_physical_node = nullptr;
128 
129  _physicals.erase(remove);
130 }
131 
132 /**
133  * Write a string representation of this instance to <out>.
134  */
135 void PhysicalNode::
136 write(std::ostream &out, int indent) const {
137  #ifndef NDEBUG //[
138  out.width(indent); out<<""; out<<"PhysicalNode:\n";
139  // PandaNode::write(out, indent+2);
140  #endif //] NDEBUG
141 }
void add_physicals_from(const PhysicalNode &other)
append operation
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PhysicalNode(const std::string &name)
default constructor
set_physical
replace operation
Definition: physicalNode.h:44
insert_physical
insert operation
Definition: physicalNode.h:44
void remove_physical(Physical *p)
takes a physical out of the object list
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:28
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
remove_physical
remove operation
Definition: physicalNode.h:44
Defines a set of physically modeled attributes.
Definition: physical.h:37
virtual PandaNode * make_copy() const
dynamic child copy
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual ~PhysicalNode()
destructor
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81