Panda3D
physxBodyDesc.cxx
1 // Filename: physxBodyDesc.cxx
2 // Created by: enn0x (05Sep09)
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 "physxBodyDesc.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: PhysxBodyDesc::set_mass
19 // Access: Published
20 // Description: Set the mass of body.
21 ////////////////////////////////////////////////////////////////////
22 void PhysxBodyDesc::
23 set_mass(float mass) {
24 
25  _desc.mass = mass;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: PhysxBodyDesc::get_mass
30 // Access: Published
31 // Description: Get the mass of body.
32 ////////////////////////////////////////////////////////////////////
33 float PhysxBodyDesc::
34 get_mass() const {
35 
36  return _desc.mass;
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxBodyDesc::set_linear_damping
41 // Access: Published
42 // Description: Set the linear damping applied to the body.
43 ////////////////////////////////////////////////////////////////////
44 void PhysxBodyDesc::
45 set_linear_damping(float damping) {
46 
47  _desc.linearDamping = damping;
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: PhysxBodyDesc::get_linear_damping
52 // Access: Published
53 // Description: Get the linear damping applied to the body.
54 ////////////////////////////////////////////////////////////////////
55 float PhysxBodyDesc::
57 
58  return _desc.linearDamping;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: PhysxBodyDesc::set_angular_damping
63 // Access: Published
64 // Description: Set the angular damping applied to the body.
65 ////////////////////////////////////////////////////////////////////
66 void PhysxBodyDesc::
67 set_angular_damping(float damping) {
68 
69  _desc.angularDamping = damping;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: PhysxBodyDesc::get_angular_damping
74 // Access: Published
75 // Description: Get the angular damping applied to the body.
76 ////////////////////////////////////////////////////////////////////
77 float PhysxBodyDesc::
79 
80  return _desc.angularDamping;
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: PhysxBodyDesc::set_linear_velocity
85 // Access: Published
86 // Description: Set the linear Velocity of the body.
87 ////////////////////////////////////////////////////////////////////
88 void PhysxBodyDesc::
89 set_linear_velocity(const LVector3f &velocity) {
90 
91  _desc.linearVelocity = PhysxManager::vec3_to_nxVec3(velocity);
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: PhysxBodyDesc::get_linear_velocity
96 // Access: Published
97 // Description: Get the linear Velocity of the body.
98 ////////////////////////////////////////////////////////////////////
101 
102  return PhysxManager::nxVec3_to_vec3(_desc.linearVelocity);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: PhysxBodyDesc::set_angular_velocity
107 // Access: Published
108 // Description: Set the angular velocity of the body.
109 ////////////////////////////////////////////////////////////////////
110 void PhysxBodyDesc::
111 set_angular_velocity(const LVector3f &velocity) {
112 
113  _desc.angularVelocity = PhysxManager::vec3_to_nxVec3(velocity);
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: PhysxBodyDesc::get_angular_velocity
118 // Access: Published
119 // Description: Get the angular velocity of the body.
120 ////////////////////////////////////////////////////////////////////
123 
124  return PhysxManager::nxVec3_to_vec3(_desc.angularVelocity);
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: PhysxBodyDesc::set_max_angular_velocity
129 // Access: Published
130 // Description: Set the maximum allowed angular velocity for this
131 // body.
132 ////////////////////////////////////////////////////////////////////
133 void PhysxBodyDesc::
134 set_max_angular_velocity(float maximum) {
135 
136  _desc.maxAngularVelocity = maximum;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: PhysxBodyDesc::get_max_angular_velocity
141 // Access: Published
142 // Description: Get the maximum allowed angular velocity for this
143 // body.
144 ////////////////////////////////////////////////////////////////////
145 float PhysxBodyDesc::
147 
148  return _desc.maxAngularVelocity;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: PhysxBodyDesc::set_sleep_linear_velocity
153 // Access: Published
154 // Description: Set the maximum linear velocity at which the body
155 // can go to sleep.
156 ////////////////////////////////////////////////////////////////////
157 void PhysxBodyDesc::
158 set_sleep_linear_velocity(float velocity) {
159 
160  _desc.sleepLinearVelocity = velocity;
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: PhysxBodyDesc::get_sleep_linear_velocity
165 // Access: Published
166 // Description: Get the maximum linear velocity at which the body
167 // can go to sleep.
168 ////////////////////////////////////////////////////////////////////
169 float PhysxBodyDesc::
171 
172  return _desc.sleepLinearVelocity;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: PhysxBodyDesc::set_sleep_angular_velocity
177 // Access: Published
178 // Description: Set the maximum angular velocity at which body
179 // can go to sleep.
180 ////////////////////////////////////////////////////////////////////
181 void PhysxBodyDesc::
182 set_sleep_angular_velocity(float velocity) {
183 
184  _desc.sleepAngularVelocity = velocity;
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: PhysxBodyDesc::get_sleep_angular_velocity
189 // Access: Published
190 // Description: Get the maximum angular velocity at which body
191 // can go to sleep.
192 ////////////////////////////////////////////////////////////////////
193 float PhysxBodyDesc::
195 
196  return _desc.sleepAngularVelocity;
197 }
198 
199 ////////////////////////////////////////////////////////////////////
200 // Function: PhysxBodyDesc::set_solver_iteration_count
201 // Access: Published
202 // Description: Set the number of solver iterations performed
203 // when processing joint/contacts connected to this
204 // body.
205 ////////////////////////////////////////////////////////////////////
206 void PhysxBodyDesc::
207 set_solver_iteration_count(unsigned int count) {
208 
209  _desc.solverIterationCount = count;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: PhysxBodyDesc::get_solver_iteration_count
214 // Access: Published
215 // Description: Get the number of solver iterations performed
216 // when processing joint/contacts connected to this
217 // body.
218 ////////////////////////////////////////////////////////////////////
219 unsigned int PhysxBodyDesc::
221 
222  return _desc.solverIterationCount;
223 }
224 
225 ////////////////////////////////////////////////////////////////////
226 // Function: PhysxBodyDesc::set_sleep_energy_threshold
227 // Access: Published
228 // Description: Set the threshold for the energy-based sleeping
229 // algorithm. Only used when the BF_energy_sleep_test
230 // flag is set.
231 ////////////////////////////////////////////////////////////////////
232 void PhysxBodyDesc::
233 set_sleep_energy_threshold(float threshold) {
234 
235  _desc.sleepEnergyThreshold = threshold;
236 }
237 
238 ////////////////////////////////////////////////////////////////////
239 // Function: PhysxBodyDesc::get_sleep_energy_threshold
240 // Access: Published
241 // Description: Get the threshold for the energy-based sleeping
242 // algorithm. Only used when the BF_energy_sleep_test
243 // flag is set.
244 ////////////////////////////////////////////////////////////////////
245 float PhysxBodyDesc::
247 
248  return _desc.sleepEnergyThreshold;
249 }
250 
251 ////////////////////////////////////////////////////////////////////
252 // Function: PhysxBodyDesc::set_sleep_damping
253 // Access: Published
254 // Description: Set the damping factor for bodies that are about
255 // to sleep.
256 ////////////////////////////////////////////////////////////////////
257 void PhysxBodyDesc::
258 set_sleep_damping(float damping) {
259 
260  _desc.sleepDamping = damping;
261 }
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: PhysxBodyDesc::get_sleep_damping
265 // Access: Published
266 // Description: Get the damping factor for bodies that are about
267 // to sleep.
268 ////////////////////////////////////////////////////////////////////
269 float PhysxBodyDesc::
271 
272  return _desc.sleepDamping;
273 }
274 
275 ////////////////////////////////////////////////////////////////////
276 // Function: PhysxBodyDesc::set_mass_local_mat
277 // Access: Published
278 // Description: Set the position and orientation of the center
279 // of mass.
280 ////////////////////////////////////////////////////////////////////
281 void PhysxBodyDesc::
283 
284  _desc.massLocalPose = PhysxManager::mat4_to_nxMat34(mat);
285 }
286 
287 ////////////////////////////////////////////////////////////////////
288 // Function: PhysxBodyDesc::get_mass_local_mat
289 // Access: Published
290 // Description: Get the position and orientation of the center
291 // of mass.
292 ////////////////////////////////////////////////////////////////////
295 
296  return PhysxManager::nxMat34_to_mat4(_desc.massLocalPose);
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: PhysxBodyDesc::set_mass_space_inertia
301 // Access: Published
302 // Description: Set the diagonal mass space inertia tensor in
303 // bodies mass frame.
304 ////////////////////////////////////////////////////////////////////
305 void PhysxBodyDesc::
307 
308  _desc.massSpaceInertia = PhysxManager::vec3_to_nxVec3(inertia);
309 }
310 
311 ////////////////////////////////////////////////////////////////////
312 // Function: PhysxBodyDesc::get_mass_space_inertia
313 // Access: Published
314 // Description: Get the diagonal mass space inertia tensor in
315 // bodies mass frame.
316 ////////////////////////////////////////////////////////////////////
319 
320  return PhysxManager::nxVec3_to_vec3(_desc.massSpaceInertia);
321 }
322 
323 ////////////////////////////////////////////////////////////////////
324 // Function: PhysxBodyDesc::set_flag
325 // Access: Published
326 // Description: Raise or lower individual body flags.
327 ////////////////////////////////////////////////////////////////////
328 void PhysxBodyDesc::
329 set_flag(const PhysxBodyFlag flag, bool value) {
330 
331  if (value == true) {
332  _desc.flags |= flag;
333  }
334  else {
335  _desc.flags &= ~(flag);
336  }
337 }
338 
339 ////////////////////////////////////////////////////////////////////
340 // Function: PhysxBodyDesc::get_flag
341 // Access: Published
342 // Description: Returns the specified body flag.
343 ////////////////////////////////////////////////////////////////////
344 bool PhysxBodyDesc::
345 get_flag(const PhysxBodyFlag flag) const {
346 
347  return (_desc.flags & flag) ? true : false;
348 }
349 
350 ////////////////////////////////////////////////////////////////////
351 // Function: PhysxBodyDesc::set_ccd_motion_threshold
352 // Access: Published
353 // Description: When CCD is globally enabled, it is still not
354 // performed if the motion distance of all points on
355 // the body is below this threshold.
356 ////////////////////////////////////////////////////////////////////
357 void PhysxBodyDesc::
358 set_ccd_motion_threshold(float threshold) {
359 
360  _desc.CCDMotionThreshold = threshold;
361 }
362 
363 ////////////////////////////////////////////////////////////////////
364 // Function: PhysxBodyDesc::get_ccd_motion_threshold
365 // Access: Published
366 // Description:
367 ////////////////////////////////////////////////////////////////////
368 float PhysxBodyDesc::
369 get_ccd_motion_threshold() const {
370 
371  return _desc.CCDMotionThreshold;
372 }
373 
374 ////////////////////////////////////////////////////////////////////
375 // Function: PhysxBodyDesc::set_wake_up_counter
376 // Access: Published
377 // Description: Set the body's initial wake up counter.
378 ////////////////////////////////////////////////////////////////////
379 void PhysxBodyDesc::
380 set_wake_up_counter(float value) {
381 
382  _desc.wakeUpCounter = value;
383 }
384 
385 ////////////////////////////////////////////////////////////////////
386 // Function: PhysxBodyDesc::get_wake_up_counter
387 // Access: Published
388 // Description:
389 ////////////////////////////////////////////////////////////////////
390 float PhysxBodyDesc::
391 get_wake_up_counter() const {
392 
393  return _desc.wakeUpCounter;
394 }
395 
396 ////////////////////////////////////////////////////////////////////
397 // Function: PhysxBodyDesc::set_contact_report_threshold
398 // Access: Published
399 // Description: Set The force threshold for contact reports.
400 ////////////////////////////////////////////////////////////////////
401 void PhysxBodyDesc::
403 
404  _desc.contactReportThreshold = threshold;
405 }
406 
407 ////////////////////////////////////////////////////////////////////
408 // Function: PhysxBodyDesc::get_contact_report_threshold
409 // Access: Published
410 // Description:
411 ////////////////////////////////////////////////////////////////////
412 float PhysxBodyDesc::
413 get_contact_report_threshold() const {
414 
415  return _desc.contactReportThreshold;
416 }
417 
void set_wake_up_counter(float value)
Set the body's initial wake up counter.
void set_linear_damping(float damping)
Set the linear damping applied to the body.
void set_mass_local_mat(const LMatrix4f &mat)
Set the position and orientation of the center of mass.
float get_linear_damping() const
Get the linear damping applied to the body.
float get_max_angular_velocity() const
Get the maximum allowed angular velocity for this body.
unsigned int get_solver_iteration_count() const
Get the number of solver iterations performed when processing joint/contacts connected to this body...
void set_contact_report_threshold(float threshold)
Set The force threshold for contact reports.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
void set_sleep_energy_threshold(float threshold)
Set the threshold for the energy-based sleeping algorithm.
void set_sleep_angular_velocity(float velocity)
Set the maximum angular velocity at which body can go to sleep.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Definition: physxManager.I:145
float get_sleep_energy_threshold() const
Get the threshold for the energy-based sleeping algorithm.
bool get_flag(PhysxBodyFlag flag) const
Returns the specified body flag.
void set_solver_iteration_count(unsigned int count)
Set the number of solver iterations performed when processing joint/contacts connected to this body...
void set_max_angular_velocity(float maximum)
Set the maximum allowed angular velocity for this body.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_linear_velocity(const LVector3f &velocity)
Set the linear Velocity of the body.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
float get_sleep_linear_velocity() const
Get the maximum linear velocity at which the body can go to sleep.
void set_mass_space_inertia(const LVector3f &inertia)
Set the diagonal mass space inertia tensor in bodies mass frame.
void set_sleep_linear_velocity(float velocity)
Set the maximum linear velocity at which the body can go to sleep.
float get_angular_damping() const
Get the angular damping applied to the body.
void set_ccd_motion_threshold(float threshold)
When CCD is globally enabled, it is still not performed if the motion distance of all points on the b...
LMatrix4f get_mass_local_mat() const
Get the position and orientation of the center of mass.
void set_mass(float mass)
Set the mass of body.
float get_sleep_damping() const
Get the damping factor for bodies that are about to sleep.
void set_angular_damping(float damping)
Set the angular damping applied to the body.
void set_angular_velocity(const LVector3f &velocity)
Set the angular velocity of the body.
LVector3f get_angular_velocity() const
Get the angular velocity of the body.
void set_sleep_damping(float damping)
Set the damping factor for bodies that are about to sleep.
LVector3f get_linear_velocity() const
Get the linear Velocity of the body.
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
Definition: physxManager.I:158
LVector3f get_mass_space_inertia() const
Get the diagonal mass space inertia tensor in bodies mass frame.
void set_flag(PhysxBodyFlag flag, bool value)
Raise or lower individual body flags.
float get_mass() const
Get the mass of body.
float get_sleep_angular_velocity() const
Get the maximum angular velocity at which body can go to sleep.