Panda3D
 All Classes Functions Variables Enumerations
physicsObject.I
1 // Filename: physicsObject.I
2 // Created by: charles (13Jun00)
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 ////////////////////////////////////////////////////////////////////
16 // Function : set_mass
17 // Access : Public
18 // Description : Set the mass in slugs (or kilograms).
19 ////////////////////////////////////////////////////////////////////
20 INLINE void PhysicsObject::
21 set_mass(PN_stdfloat m) {
22  nassertv(m > 0);
23  _mass = m;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function : set_position
28 // Access : Public
29 // Description : Vector position assignment. This is also used as
30 // the center of mass.
31 ////////////////////////////////////////////////////////////////////
32 INLINE void PhysicsObject::
33 set_position(const LPoint3 &pos) {
34  nassertv(!pos.is_nan());
35  _position = pos;
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function : set_position
40 // Access : Public
41 // Description : Piecewise position assignment
42 ////////////////////////////////////////////////////////////////////
43 INLINE void PhysicsObject::
44 set_position(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
45  nassertv(!LPoint3(x, y, z).is_nan());
46  _position.set(x, y, z);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function : reset_position
51 // Access : Public
52 // Description : use this to place an object in a completely new
53 // position, that has nothing to do with its last
54 // position.
55 ////////////////////////////////////////////////////////////////////
56 INLINE void PhysicsObject::
57 reset_position(const LPoint3 &pos) {
58  nassertv(!pos.is_nan());
59  _position = pos;
60  _last_position = pos;
61  _velocity.set(0.0f, 0.0f, 0.0f);
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function : reset_orientation
66 // Access : Public
67 // Description : set the orientation while clearing the rotation
68 // velocity.
69 ////////////////////////////////////////////////////////////////////
70 INLINE void PhysicsObject::
71 reset_orientation(const LOrientation &orientation) {
72  nassertv(!orientation.is_nan());
73  _orientation = orientation;
74  _rotation = LRotation::ident_quat();
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function : set_last_position
79 // Access : Public
80 // Description : Last position assignment
81 ////////////////////////////////////////////////////////////////////
82 INLINE void PhysicsObject::
84  _last_position = pos;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function : set_velocity
89 // Access : Public
90 // Description : Vector velocity assignment
91 ////////////////////////////////////////////////////////////////////
92 INLINE void PhysicsObject::
93 set_velocity(const LVector3 &vel) {
94  nassertv(!vel.is_nan());
95  _velocity = vel;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function : set_velocity
100 // Access : Public
101 // Description : Piecewise velocity assignment
102 ////////////////////////////////////////////////////////////////////
103 INLINE void PhysicsObject::
104 set_velocity(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
105  nassertv(!LVector3(x, y, z).is_nan());
106  _velocity.set(x, y, z);
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function : add_local_torque
111 // Access : Public
112 // Description : Adds an torque force (i.e. an instantanious change
113 // in velocity). This is a quicker way to get the
114 // angular velocity, add a vector to it and set that
115 // value to be the new angular velocity.
116 ////////////////////////////////////////////////////////////////////
117 INLINE void PhysicsObject::
118 add_local_torque(const LRotation &torque) {
119  nassertv(!torque.is_nan());
120  _rotation+=_orientation.xform(torque);
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function : add_local_impulse
125 // Access : Public
126 // Description : Adds an impulse force (i.e. an instantanious change
127 // in velocity). This is a quicker way to get the
128 // velocity, add a vector to it and set that value to
129 // be the new velocity.
130 ////////////////////////////////////////////////////////////////////
131 INLINE void PhysicsObject::
132 add_local_impulse(const LVector3 &impulse) {
133  nassertv(!impulse.is_nan());
134  _velocity += _orientation.xform(impulse);
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function : add_torque
139 // Access : Public
140 // Description : Adds an torque force (i.e. an instantanious change
141 // in velocity). This is a quicker way to get the
142 // angular velocity, add a vector to it and set that
143 // value to be the new angular velocity.
144 ////////////////////////////////////////////////////////////////////
145 INLINE void PhysicsObject::
146 add_torque(const LRotation &torque) {
147  nassertv(!torque.is_nan());
148  _rotation+=torque;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function : add_impulse
153 // Access : Public
154 // Description : Adds an impulse force (i.e. an instantanious change
155 // in velocity). This is a quicker way to get the
156 // velocity, add a vector to it and set that value to
157 // be the new velocity.
158 ////////////////////////////////////////////////////////////////////
159 INLINE void PhysicsObject::
160 add_impulse(const LVector3 &impulse) {
161  nassertv(!impulse.is_nan());
162  _velocity+=impulse;
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function : set_active
167 // Access : Public
168 // Description : Process Flag assignment
169 ////////////////////////////////////////////////////////////////////
170 INLINE void PhysicsObject::
171 set_active(bool flag) {
172  _process_me = flag;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function : set_terminal_velocity
177 // Access : Public
178 // Description : tv assignment
179 ////////////////////////////////////////////////////////////////////
180 INLINE void PhysicsObject::
181 set_terminal_velocity(PN_stdfloat tv) {
182  _terminal_velocity = tv;
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function : get_mass
187 // Access : Public
188 // Description : Get the mass in slugs (or kilograms).
189 ////////////////////////////////////////////////////////////////////
190 INLINE PN_stdfloat PhysicsObject::
191 get_mass() const {
192  return _mass;
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function : get_position
197 // Access : Public
198 // Description : Position Query
199 ////////////////////////////////////////////////////////////////////
201 get_position() const {
202  return _position;
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function : get_last_position
207 // Access : Public
208 // Description : Get the position of the physics object at the start
209 // of the most recent do_physics.
210 ////////////////////////////////////////////////////////////////////
213  return _last_position;
214 }
215 
216 ////////////////////////////////////////////////////////////////////
217 // Function : get_velocity
218 // Access : Public
219 // Description : Velocity Query per second
220 ////////////////////////////////////////////////////////////////////
222 get_velocity() const {
223  return _velocity;
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function : get_implicit_velocity
228 // Access : Public
229 // Description : Velocity Query over the last dt
230 ////////////////////////////////////////////////////////////////////
233  return _position-_last_position;
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function : get_active
238 // Access : Public
239 // Description : Process Flag Query
240 ////////////////////////////////////////////////////////////////////
241 INLINE bool PhysicsObject::
242 get_active() const {
243  return _process_me;
244 }
245 
246 ////////////////////////////////////////////////////////////////////
247 // Function : get_terminal_velocity
248 // Access : Public
249 // Description : tv query
250 ////////////////////////////////////////////////////////////////////
251 INLINE PN_stdfloat PhysicsObject::
253  return _terminal_velocity;
254 }
255 
256 ////////////////////////////////////////////////////////////////////
257 // Function : set_orientation
258 // Access : Public
259 // Description :
260 ////////////////////////////////////////////////////////////////////
261 INLINE void PhysicsObject::
262 set_orientation(const LOrientation &orientation) {
263  nassertv(!orientation.is_nan());
264  _orientation = orientation;
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function : set_rotation
269 // Access : Public
270 // Description : set rotation as a quaternion delta per second.
271 ////////////////////////////////////////////////////////////////////
272 INLINE void PhysicsObject::
273 set_rotation(const LRotation &rotation) {
274  nassertv(!rotation.is_nan());
275  _rotation = rotation;
276 }
277 
278 ////////////////////////////////////////////////////////////////////
279 // Function : get_orientation
280 // Access : Public
281 // Description : get current orientation.
282 ////////////////////////////////////////////////////////////////////
285  return _orientation;
286 }
287 
288 ////////////////////////////////////////////////////////////////////
289 // Function : get_rotation
290 // Access : Public
291 // Description : get rotation per second.
292 ////////////////////////////////////////////////////////////////////
294 get_rotation() const {
295  return _rotation;
296 }
297 
298 ////////////////////////////////////////////////////////////////////
299 // Function : set_oriented
300 // Access : Public
301 // Description : Set flag to determine whether this object should do
302 // any rotation or orientation calculations. Optimization.
303 ////////////////////////////////////////////////////////////////////
304 INLINE void PhysicsObject::
305 set_oriented(bool flag) {
306  _oriented = flag;
307 }
308 
309 ////////////////////////////////////////////////////////////////////
310 // Function : get_oriented
311 // Access : Public
312 // Description : See set_oriented().
313 ////////////////////////////////////////////////////////////////////
314 INLINE bool PhysicsObject::
315 get_oriented() const {
316  return _oriented;
317 }
static const LQuaternionf & ident_quat()
Returns an identity quaternion.
Definition: lquaternion.h:851
LPoint3 get_position() const
Position Query.
void reset_position(const LPoint3 &pos)
use this to place an object in a completely new position, that has nothing to do with its last positi...
Definition: physicsObject.I:57
LVector3 get_velocity() const
Velocity Query per second.
This is a unit quaternion representing a rotation.
Definition: lrotation.h:92
void add_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
void set_position(const LPoint3 &pos)
Vector position assignment.
Definition: physicsObject.I:33
LPoint3 get_last_position() const
Get the position of the physics object at the start of the most recent do_physics.
void add_local_torque(const LRotation &torque)
Adds an torque force (i.e.
bool get_active() const
Process Flag Query.
bool get_oriented() const
See set_oriented().
LVector3 get_implicit_velocity() const
Velocity Query over the last dt.
LOrientation get_orientation() const
get current orientation.
This is a unit quaternion representing an orientation.
Definition: lorientation.h:92
void set_velocity(const LVector3 &vel)
Vector velocity assignment.
Definition: physicsObject.I:93
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase4.h:575
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:463
void set_active(bool flag)
Process Flag assignment.
LVecBase3f xform(const LVecBase3f &v) const
Transforms a 3-d vector by the indicated rotation.
Definition: lquaternion.h:280
void add_local_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
void set_last_position(const LPoint3 &pos)
Last position assignment.
Definition: physicsObject.I:83
void add_torque(const LRotation &torque)
Adds an torque force (i.e.
PN_stdfloat get_mass() const
Get the mass in slugs (or kilograms).
PN_stdfloat get_terminal_velocity() const
tv query
void reset_orientation(const LOrientation &orientation)
set the orientation while clearing the rotation velocity.
Definition: physicsObject.I:71
void set_mass(PN_stdfloat)
Set the mass in slugs (or kilograms).
Definition: physicsObject.I:21
LRotation get_rotation() const
get rotation per second.
void set_rotation(const LRotation &rotation)
set rotation as a quaternion delta per second.
void set_terminal_velocity(PN_stdfloat tv)
tv assignment
void set_oriented(bool flag)
Set flag to determine whether this object should do any rotation or orientation calculations.