Panda3D
physical.I
1 // Filename: physical.I
2 // Created by: charles (16Jun00)
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 <algorithm>
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function : clear_linear_forces
19 // Access : Public
20 // Description : Erases the linear force list
21 ////////////////////////////////////////////////////////////////////
22 INLINE void Physical::
24  _linear_forces.erase(_linear_forces.begin(),
25  _linear_forces.end());
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function : clear_angular_forces
30 // Access : Public
31 // Description : Erases the angular force list
32 ////////////////////////////////////////////////////////////////////
33 INLINE void Physical::
35  _angular_forces.erase(_angular_forces.begin(),
36  _angular_forces.end());
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function : clear_physics_objects
41 // Access : Public
42 // Description : Erases the object list
43 ////////////////////////////////////////////////////////////////////
44 INLINE void Physical::
46  _physics_objects.erase(_physics_objects.begin(),
47  _physics_objects.end());
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function : add_linear_force
52 // Access : Public
53 // Description : Adds a linear force to the force list
54 ////////////////////////////////////////////////////////////////////
55 INLINE void Physical::
57  _linear_forces.push_back(f);
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function : add_angular_force
62 // Access : Public
63 // Description : Adds an angular force to the force list
64 ////////////////////////////////////////////////////////////////////
65 INLINE void Physical::
67  _angular_forces.push_back(f);
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function : remove_linear_force
72 // Access : Public
73 // Description : removes a linear force from the force list
74 ////////////////////////////////////////////////////////////////////
75 INLINE void Physical::
77  LinearForceVector::iterator found;
78 
79  // this is a PT because the templates don't like what should be
80  // perfectly allowable, which is to search for bf directly.
81  PT(LinearForce) pt_lf = f;
82  found = find(_linear_forces.begin(), _linear_forces.end(), pt_lf);
83 
84  if (found == _linear_forces.end())
85  return;
86 
87  _linear_forces.erase(found);
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function : remove_angular_force
92 // Access : Public
93 // Description : removes an angular force from the force list
94 ////////////////////////////////////////////////////////////////////
95 INLINE void Physical::
97  AngularForceVector::iterator found;
98 
99  PT(AngularForce) pt_af = f;
100  found = find(_angular_forces.begin(), _angular_forces.end(), pt_af);
101 
102  if (found == _angular_forces.end())
103  return;
104 
105  _angular_forces.erase(found);
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function : add_physics_object
110 // Access : Public
111 // Description : Adds an object to the physics object vector
112 ////////////////////////////////////////////////////////////////////
113 INLINE void Physical::
115  _physics_objects.push_back(po);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function : get_physics_manager
120 // Access : Public
121 ////////////////////////////////////////////////////////////////////
122 INLINE PhysicsManager *Physical::
123 get_physics_manager() const {
124  return _physics_manager;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function : get_phys_body
129 // Access : Public
130 ////////////////////////////////////////////////////////////////////
131 INLINE PhysicsObject *Physical::
132 get_phys_body() const {
133  return _phys_body;
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function : get_physical_node
138 // Access : Public
139 ////////////////////////////////////////////////////////////////////
140 INLINE PhysicalNode *Physical::
141 get_physical_node() const {
142  return _physical_node;
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function : get_physical_node_path
147 // Access : Public
148 ////////////////////////////////////////////////////////////////////
149 INLINE NodePath Physical::
150 get_physical_node_path() const {
151  return NodePath((PandaNode*) _physical_node);
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function : get_object_vector
156 // Access : Public
157 ////////////////////////////////////////////////////////////////////
158 INLINE const PhysicsObject::Vector &Physical::
159 get_object_vector() const {
160  return _physics_objects;
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function : get_linear_forces
165 // Access : Public
166 ////////////////////////////////////////////////////////////////////
167 INLINE const Physical::LinearForceVector &Physical::
168 get_linear_forces() const {
169  return _linear_forces;
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function : get_angular_forces
174 // Access : Public
175 ////////////////////////////////////////////////////////////////////
176 INLINE const Physical::AngularForceVector &Physical::
177 get_angular_forces() const {
178  return _angular_forces;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function : get_num_linear_forces
183 // Access : Public
184 ////////////////////////////////////////////////////////////////////
185 INLINE int Physical::
186 get_num_linear_forces() const {
187  return _linear_forces.size();
188 }
189 
190 ////////////////////////////////////////////////////////////////////
191 // Function : get_linear_force
192 // Access : Public
193 ////////////////////////////////////////////////////////////////////
194 INLINE PT(LinearForce) Physical::
195 get_linear_force(int index) const {
196  nassertr(index >= 0 && index < (int)_linear_forces.size(), NULL);
197  return _linear_forces[index];
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function : get_num_angular_forces
202 // Access : Public
203 ////////////////////////////////////////////////////////////////////
204 INLINE int Physical::
205 get_num_angular_forces() const {
206  return _angular_forces.size();
207 }
208 
209 ////////////////////////////////////////////////////////////////////
210 // Function : get_angular_force
211 // Access : Public
212 ////////////////////////////////////////////////////////////////////
213 INLINE PT(AngularForce) Physical::
214 get_angular_force(int index) const {
215  nassertr(index >= 0 && index < (int)_angular_forces.size(), NULL);
216  return _angular_forces[index];
217 }
218 
219 ////////////////////////////////////////////////////////////////////
220 // Function : set_viscosity
221 // Access : Public
222 // Description : Set the local viscosity.
223 ////////////////////////////////////////////////////////////////////
224 INLINE void Physical::
225 set_viscosity(PN_stdfloat viscosity) {
226  _viscosity=viscosity;
227 }
228 
229 ////////////////////////////////////////////////////////////////////
230 // Function : get_viscosity
231 // Access : Public
232 // Description : Get the local viscosity.
233 ////////////////////////////////////////////////////////////////////
234 INLINE PN_stdfloat Physical::
235 get_viscosity() const {
236  //zzzzzzzzzzzzzzzz return max(_viscosity, get_physics_manager()->get_viscosity());
237  return _viscosity;
238 }
void remove_angular_force(AngularForce *f)
removes an angular force from the force list
Definition: physical.I:96
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
A body on which physics will be applied.
Definition: physicsObject.h:29
PN_stdfloat get_viscosity() const
Get the local viscosity.
Definition: physical.I:235
void clear_physics_objects()
Erases the object list.
Definition: physical.I:45
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:25
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:31
Physics don&#39;t get much higher-level than this.
void add_linear_force(LinearForce *f)
Adds a linear force to the force list.
Definition: physical.I:56
void add_angular_force(AngularForce *f)
Adds an angular force to the force list.
Definition: physical.I:66
pure virtual parent of all quat-based forces.
Definition: angularForce.h:24
void remove_linear_force(LinearForce *f)
removes a linear force from the force list
Definition: physical.I:76
void add_physics_object(PhysicsObject *po)
Adds an object to the physics object vector.
Definition: physical.I:114
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
void clear_angular_forces()
Erases the angular force list.
Definition: physical.I:34
void clear_linear_forces()
Erases the linear force list.
Definition: physical.I:23