Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE void PhysicsObject::
18set_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 */
26INLINE void PhysicsObject::
27set_position(const LPoint3 &pos) {
28 nassertv(!pos.is_nan());
29 _position = pos;
30}
31
32/**
33 * Piecewise position assignment
34 */
35INLINE void PhysicsObject::
36set_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 */
45INLINE void PhysicsObject::
46reset_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 */
56INLINE void PhysicsObject::
57reset_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 */
66INLINE void PhysicsObject::
67set_last_position(const LPoint3 &pos) {
68 _last_position = pos;
69}
70
71/**
72 * Vector velocity assignment
73 */
74INLINE void PhysicsObject::
75set_velocity(const LVector3 &vel) {
76 nassertv(!vel.is_nan());
77 _velocity = vel;
78}
79
80/**
81 * Piecewise velocity assignment
82 */
83INLINE void PhysicsObject::
84set_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 */
94INLINE void PhysicsObject::
95add_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 */
106add_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 */
117add_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 */
128add_impulse(const LVector3 &impulse) {
129 nassertv(!impulse.is_nan());
130 _velocity+=impulse;
131}
132
133/**
134 * Process Flag assignment
135 */
136INLINE void PhysicsObject::
137set_active(bool flag) {
138 _process_me = flag;
139}
140
141/**
142 * tv assignment
143 */
144INLINE void PhysicsObject::
145set_terminal_velocity(PN_stdfloat tv) {
146 _terminal_velocity = tv;
147}
148
149/**
150 * Get the mass in slugs (or kilograms).
151 */
152INLINE PN_stdfloat PhysicsObject::
153get_mass() const {
154 return _mass;
155}
156
157/**
158 * Position Query
159 */
160INLINE LPoint3 PhysicsObject::
161get_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 */
169INLINE LPoint3 PhysicsObject::
170get_last_position() const {
171 return _last_position;
172}
173
174/**
175 * Velocity Query per second
176 */
177INLINE LVector3 PhysicsObject::
178get_velocity() const {
179 return _velocity;
180}
181
182/**
183 * Velocity Query over the last dt
184 */
185INLINE LVector3 PhysicsObject::
186get_implicit_velocity() const {
187 return _position-_last_position;
188}
189
190/**
191 * Process Flag Query
192 */
193INLINE bool PhysicsObject::
194get_active() const {
195 return _process_me;
196}
197
198/**
199 * tv query
200 */
201INLINE PN_stdfloat PhysicsObject::
202get_terminal_velocity() const {
203 return _terminal_velocity;
204}
205
206/**
207 *
208 */
209INLINE void PhysicsObject::
210set_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 */
218INLINE void PhysicsObject::
219set_rotation(const LRotation &rotation) {
220 nassertv(!rotation.is_nan());
221 _rotation = rotation;
222}
223
224/**
225 * get current orientation.
226 */
227INLINE LOrientation PhysicsObject::
228get_orientation() const {
229 return _orientation;
230}
231
232/**
233 * get rotation per second.
234 */
235INLINE LRotation PhysicsObject::
236get_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 */
244INLINE void PhysicsObject::
245set_oriented(bool flag) {
246 _oriented = flag;
247}
248
249/**
250 * See set_oriented().
251 */
252INLINE bool PhysicsObject::
253get_oriented() const {
254 return _oriented;
255}
get_oriented
See set_oriented().
get_active
Process Flag Query.
get_position
Position Query.
get_velocity
Velocity Query per second.
get_last_position
Get the position of the physics object at the start of the most recent do_physics.
set_active
Process Flag assignment.
void add_local_torque(const LRotation &torque)
Adds an torque force (i.e.
set_rotation
set rotation as a quaternion delta per second.
void add_local_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
set_velocity
Vector velocity assignment.
set_last_position
Last position assignment.
set_mass
Set the mass in slugs (or kilograms).
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...
get_terminal_velocity
tv query
void reset_orientation(const LOrientation &orientation)
set the orientation while clearing the rotation velocity.
get_rotation
get rotation per second.
void add_torque(const LRotation &torque)
Adds an torque force (i.e.
get_orientation
get current orientation.
set_terminal_velocity
tv assignment
void add_impulse(const LVector3 &impulse)
Adds an impulse force (i.e.
get_implicit_velocity
Velocity Query over the last dt.
set_position
Vector position assignment.
set_oriented
Set flag to determine whether this object should do any rotation or orientation calculations.
get_mass
Get the mass in slugs (or kilograms).