Panda3D
forceNode.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 forceNode.cxx
10  * @author charles
11  * @date 2000-08-02
12  */
13 
14 #include "forceNode.h"
15 #include "config_physics.h"
16 
17 TypeHandle ForceNode::_type_handle;
18 
19 /**
20  * default constructor
21  */
23 ForceNode(const std::string &name) :
24  PandaNode(name) {
25 }
26 
27 /**
28  * copy constructor
29  */
31 ForceNode(const ForceNode &copy) :
32  PandaNode(copy), _forces(copy._forces) {
33 }
34 
35 /**
36  * destructor
37  */
40 }
41 
42 /**
43  * dynamic child copy
44  */
46 make_copy() const {
47  return new ForceNode(*this);
48 }
49 
50 /**
51  * append operation
52  */
53 void ForceNode::
54 add_forces_from(const ForceNode &other) {
55  pvector< PT(BaseForce) >::iterator last = _forces.end() - 1;
56 
57  _forces.insert(_forces.end(),
58  other._forces.begin(), other._forces.end());
59 
60  NodePath node_path(this);
61  for (; last != _forces.end(); last++) {
62  (*last)->_force_node = this;
63  (*last)->_force_node_path = node_path;
64  }
65 }
66 
67 /**
68  * replace operation
69  */
70 void ForceNode::
71 set_force(size_t index, BaseForce *force) {
72  nassertv(index < _forces.size());
73 
74  _forces[index]->_force_node = nullptr;
75  _forces[index]->_force_node_path.clear();
76  _forces[index] = force;
77  force->_force_node = this;
78  force->_force_node_path = NodePath(this);
79 }
80 
81 /**
82  * insert operation
83  */
84 void ForceNode::
85 insert_force(size_t index, BaseForce *force) {
86  if (index > _forces.size()) {
87  index = _forces.size();
88  }
89 
90  _forces.insert(_forces.begin() + index, force);
91  force->_force_node = this;
92  force->_force_node_path = NodePath(this);
93 }
94 
95 /**
96  * remove operation
97  */
98 void ForceNode::
100  pvector< PT(BaseForce) >::iterator found;
101  PT(BaseForce) ptbf = f;
102  found = find(_forces.begin(), _forces.end(), ptbf);
103  if (found == _forces.end())
104  return;
105  _forces.erase(found);
106 }
107 
108 /**
109  * remove operation
110  */
111 void ForceNode::
112 remove_force(size_t index) {
113  nassertv(index <= _forces.size());
114 
115  pvector< PT(BaseForce) >::iterator remove;
116  remove = _forces.begin() + index;
117  (*remove)->_force_node = nullptr;
118  (*remove)->_force_node_path = NodePath();
119 
120  _forces.erase(remove);
121 }
122 
123 /**
124  * Write a string representation of this instance to <out>.
125  */
126 void ForceNode::
127 output(std::ostream &out) const {
128  PandaNode::output(out);
129  out<<" ("<<_forces.size()<<" forces)";
130 }
131 
132 /**
133  * Write a string representation of this instance to <out>.
134  */
135 void ForceNode::
136 write_forces(std::ostream &out, int indent) const {
137  #ifndef NDEBUG //[
138  out.width(indent); out<<""<<"_forces ("<<_forces.size()<<" forces)"<<"\n";
139  for (ForceVector::const_iterator i=_forces.begin();
140  i != _forces.end();
141  ++i) {
142  out.width(indent+2); out<<""; out<<"(id "<<&(*i)<<" "<<(*i)->is_linear()<<")\n";
143  // #*#(*i)->write(out, indent+2);
144  }
145  #endif //] NDEBUG
146 }
147 
148 /**
149  * Write a string representation of this instance to <out>.
150  */
151 void ForceNode::
152 write(std::ostream &out, int indent) const {
153  #ifndef NDEBUG //[
154  out.width(indent); out<<""; out<<"ForceNode (id "<<this<<") ";
155  // #*#PandaNode::output(out);
156  out<<"\n";
157  // #*#write_forces(out, indent+2);
158  PandaNode::write(out, indent+4);
159  #endif //] NDEBUG
160 }
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition: forceNode.cxx:152
remove_force
remove operation
Definition: forceNode.h:42
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
ForceNode(const std::string &name)
default constructor
Definition: forceNode.cxx:23
A force that lives in the scene graph and is therefore subject to local coordinate systems.
Definition: forceNode.h:27
insert_force
insert operation
Definition: forceNode.h:42
pure virtual base class for all forces that could POSSIBLY exist.
Definition: baseForce.h:29
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
virtual void write_forces(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition: forceNode.cxx:136
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
virtual PandaNode * make_copy() const
dynamic child copy
Definition: forceNode.cxx:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_force
replace operation
Definition: forceNode.h:42
virtual ~ForceNode()
destructor
Definition: forceNode.cxx:39
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition: forceNode.cxx:127
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
void add_forces_from(const ForceNode &other)
append operation
Definition: forceNode.cxx:54
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.