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