Panda3D
physicsObject.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 physicsObject.I
10  * @author charles
11  * @date 2000-06-13
12  */
13 
14 /**
15  * Set the mass in slugs (or kilograms).
16  */
17 INLINE void PhysicsObject::
18 set_mass(PN_stdfloat m) {
19  nassertv(m > 0);
20  _mass = m;
21 }
22 
23 /**
24  * Vector position assignment. This is also used as the center of mass.
25  */
26 INLINE void PhysicsObject::
27 set_position(const LPoint3 &pos) {
28  nassertv(!pos.is_nan());
29  _position = pos;
30 }
31 
32 /**
33  * Piecewise position assignment
34  */
35 INLINE void PhysicsObject::
36 set_position(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
37  nassertv(!LPoint3(x, y, z).is_nan());
38  _position.set(x, y, z);
39 }
40 
41 /**
42  * use this to place an object in a completely new position, that has nothing
43  * to do with its last position.
44  */
45 INLINE void PhysicsObject::
46 reset_position(const LPoint3 &pos) {
47  nassertv(!pos.is_nan());
48  _position = pos;
49  _last_position = pos;
50  _velocity.set(0.0f, 0.0f, 0.0f);
51 }
52 
53 /**
54  * set the orientation while clearing the rotation velocity.
55  */
56 INLINE void PhysicsObject::
57 reset_orientation(const LOrientation &orientation) {
58  nassertv(!orientation.is_nan());
59  _orientation = orientation;
60  _rotation = LRotation::ident_quat();
61 }
62 
63 /**
64  * Last position assignment
65  */
66 INLINE void PhysicsObject::
67 set_last_position(const LPoint3 &pos) {
68  _last_position = pos;
69 }
70 
71 /**
72  * Vector velocity assignment
73  */
74 INLINE void PhysicsObject::
75 set_velocity(const LVector3 &vel) {
76  nassertv(!vel.is_nan());
77  _velocity = vel;
78 }
79 
80 /**
81  * Piecewise velocity assignment
82  */
83 INLINE void PhysicsObject::
84 set_velocity(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
85  nassertv(!LVector3(x, y, z).is_nan());
86  _velocity.set(x, y, z);
87 }
88 
89 /**
90  * Adds an torque force (i.e. an instantanious change in velocity). This is
91  * a quicker way to get the angular velocity, add a vector to it and set that
92  * value to be the new angular velocity.
93  */
94 INLINE void PhysicsObject::
95 add_local_torque(const LRotation &torque) {
96  nassertv(!torque.is_nan());
97  _rotation+=_orientation.xform(torque);
98 }
99 
100 /**
101  * Adds an impulse force (i.e. an instantanious change in velocity). This is
102  * a quicker way to get the velocity, add a vector to it and set that value to
103  * be the new velocity.
104  */
105 INLINE void PhysicsObject::
106 add_local_impulse(const LVector3 &impulse) {
107  nassertv(!impulse.is_nan());
108  _velocity += _orientation.xform(impulse);
109 }
110 
111 /**
112  * Adds an torque force (i.e. an instantanious change in velocity). This is
113  * a quicker way to get the angular velocity, add a vector to it and set that
114  * value to be the new angular velocity.
115  */
116 INLINE void PhysicsObject::
117 add_torque(const LRotation &torque) {
118  nassertv(!torque.is_nan());
119  _rotation+=torque;
120 }
121 
122 /**
123  * Adds an impulse force (i.e. an instantanious change in velocity). This is
124  * a quicker way to get the velocity, add a vector to it and set that value to
125  * be the new velocity.
126  */
127 INLINE void PhysicsObject::
128 add_impulse(const LVector3 &impulse) {
129  nassertv(!impulse.is_nan());
130  _velocity+=impulse;
131 }
132 
133 /**
134  * Process Flag assignment
135  */
136 INLINE void PhysicsObject::
137 set_active(bool flag) {
138  _process_me = flag;
139 }
140 
141 /**
142  * tv assignment
143  */
144 INLINE void PhysicsObject::
145 set_terminal_velocity(PN_stdfloat tv) {
146  _terminal_velocity = tv;
147 }
148 
149 /**
150  * Get the mass in slugs (or kilograms).
151  */
152 INLINE PN_stdfloat PhysicsObject::
153 get_mass() const {
154  return _mass;
155 }
156 
157 /**
158  * Position Query
159  */
160 INLINE LPoint3 PhysicsObject::
161 get_position() const {
162  return _position;
163 }
164 
165 /**
166  * Get the position of the physics object at the start of the most recent
167  * do_physics.
168  */
169 INLINE LPoint3 PhysicsObject::
171  return _last_position;
172 }
173 
174 /**
175  * Velocity Query per second
176  */
177 INLINE LVector3 PhysicsObject::
178 get_velocity() const {
179  return _velocity;
180 }
181 
182 /**
183  * Velocity Query over the last dt
184  */
185 INLINE LVector3 PhysicsObject::
187  return _position-_last_position;
188 }
189 
190 /**
191  * Process Flag Query
192  */
193 INLINE bool PhysicsObject::
194 get_active() const {
195  return _process_me;
196 }
197 
198 /**
199  * tv query
200  */
201 INLINE PN_stdfloat PhysicsObject::
203  return _terminal_velocity;
204 }
205 
206 /**
207  *
208  */
209 INLINE void PhysicsObject::
210 set_orientation(const LOrientation &orientation) {
211  nassertv(!orientation.is_nan());
212  _orientation = orientation;
213 }
214 
215 /**
216  * set rotation as a quaternion delta per second.
217  */
218 INLINE void PhysicsObject::
219 set_rotation(const LRotation &rotation) {
220  nassertv(!rotation.is_nan());
221  _rotation = rotation;
222 }
223 
224 /**
225  * get current orientation.
226  */
227 INLINE LOrientation PhysicsObject::
229  return _orientation;
230 }
231 
232 /**
233  * get rotation per second.
234  */
235 INLINE LRotation PhysicsObject::
236 get_rotation() const {
237  return _rotation;
238 }
239 
240 /**
241  * Set flag to determine whether this object should do any rotation or
242  * orientation calculations. Optimization.
243  */
244 INLINE void PhysicsObject::
245 set_oriented(bool flag) {
246  _oriented = flag;
247 }
248 
249 /**
250  * See set_oriented().
251  */
252 INLINE bool PhysicsObject::
253 get_oriented() const {
254  return _oriented;
255 }
PN_stdfloat get_terminal_velocity() const
tv query
LPoint3 get_last_position() const
Get the position of the physics object at the start of the most recent do_physics.
LOrientation get_orientation() const
get current orientation.
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:46
void add_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
void set_position(const LPoint3 &pos)
Vector position assignment.
Definition: physicsObject.I:27
void add_local_torque(const LRotation &torque)
Adds an torque force (i.e.
Definition: physicsObject.I:95
bool get_active() const
Process Flag Query.
void set_velocity(const LVector3 &vel)
Vector velocity assignment.
Definition: physicsObject.I:75
PN_stdfloat get_mass() const
Get the mass in slugs (or kilograms).
bool get_oriented() const
See set_oriented().
void set_active(bool flag)
Process Flag assignment.
void add_local_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
LRotation get_rotation() const
get rotation per second.
void set_last_position(const LPoint3 &pos)
Last position assignment.
Definition: physicsObject.I:67
void add_torque(const LRotation &torque)
Adds an torque force (i.e.
void reset_orientation(const LOrientation &orientation)
set the orientation while clearing the rotation velocity.
Definition: physicsObject.I:57
LVector3 get_velocity() const
Velocity Query per second.
LVector3 get_implicit_velocity() const
Velocity Query over the last dt.
void set_mass(PN_stdfloat)
Set the mass in slugs (or kilograms).
Definition: physicsObject.I:18
LPoint3 get_position() const
Position Query.
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.