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