Panda3D
bulletWheel.cxx
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 bulletWheel.cxx
10  * @author enn0x
11  * @date 2010-02-17
12  */
13 
14 #include "bulletWheel.h"
15 
16 #include "bulletWorld.h"
17 
18 /**
19  *
20  */
21 BulletWheel::
22 BulletWheel(btWheelInfo &info) : _info(info) {
23 
24 }
25 
26 /**
27  *
28  */
29 BulletWheelRaycastInfo::
30 BulletWheelRaycastInfo(btWheelInfo::RaycastInfo &info) : _info(info) {
31 
32 }
33 
34 /**
35  *
36  */
37 BulletWheelRaycastInfo BulletWheel::
38 get_raycast_info() const {
39  LightMutexHolder holder(BulletWorld::get_global_lock());
40 
41  return BulletWheelRaycastInfo(_info.m_raycastInfo);
42 }
43 
44 /**
45  * Returns the length of the suspension when the vehicle is standing still.
46  */
47 PN_stdfloat BulletWheel::
48 get_suspension_rest_length() const {
49  LightMutexHolder holder(BulletWorld::get_global_lock());
50 
51  return (PN_stdfloat)_info.getSuspensionRestLength();
52 }
53 
54 /**
55  * Sets how stiff the suspension shall be.
56  */
57 void BulletWheel::
58 set_suspension_stiffness(PN_stdfloat value) {
59  LightMutexHolder holder(BulletWorld::get_global_lock());
60 
61  _info.m_suspensionStiffness = (btScalar)value;
62 }
63 
64 /**
65  * Returns the stiffness of the suspension.
66  */
67 PN_stdfloat BulletWheel::
68 get_suspension_stiffness() const {
69  LightMutexHolder holder(BulletWorld::get_global_lock());
70 
71  return (PN_stdfloat)_info.m_suspensionStiffness;
72 }
73 
74 /**
75  * Sets the maximum distance the suspension can travel out of the resting
76  * position in centimeters.
77  */
78 void BulletWheel::
79 set_max_suspension_travel_cm(PN_stdfloat value) {
80  LightMutexHolder holder(BulletWorld::get_global_lock());
81 
82  _info.m_maxSuspensionTravelCm = (btScalar)value;
83 }
84 
85 /**
86  *
87  */
88 PN_stdfloat BulletWheel::
89 get_max_suspension_travel_cm() const {
90  LightMutexHolder holder(BulletWorld::get_global_lock());
91 
92  return (PN_stdfloat)_info.m_maxSuspensionTravelCm;
93 }
94 
95 /**
96  * Sets the slipperyness of the tyre.
97  */
98 void BulletWheel::
99 set_friction_slip(PN_stdfloat value) {
100  LightMutexHolder holder(BulletWorld::get_global_lock());
101 
102  _info.m_frictionSlip = (btScalar)value;
103 }
104 
105 /**
106  * Returns how slippery the tyres are.
107  */
108 PN_stdfloat BulletWheel::
109 get_friction_slip() const {
110  LightMutexHolder holder(BulletWorld::get_global_lock());
111 
112  return (PN_stdfloat)_info.m_frictionSlip;
113 }
114 
115 /**
116  * Sets the maximum suspension force the wheel can handle.
117  */
118 void BulletWheel::
119 set_max_suspension_force(PN_stdfloat value) {
120  LightMutexHolder holder(BulletWorld::get_global_lock());
121 
122  _info.m_maxSuspensionForce = (btScalar)value;
123 }
124 
125 /**
126  * Returns the maximum force (weight) the suspension can handle.
127  */
128 PN_stdfloat BulletWheel::
129 get_max_suspension_force() const {
130  LightMutexHolder holder(BulletWorld::get_global_lock());
131 
132  return (PN_stdfloat)_info.m_maxSuspensionForce;
133 }
134 
135 /**
136  * Sets the damping forces applied when the suspension gets compressed.
137  */
138 void BulletWheel::
139 set_wheels_damping_compression(PN_stdfloat value) {
140  LightMutexHolder holder(BulletWorld::get_global_lock());
141 
142  _info.m_wheelsDampingCompression = (btScalar)value;
143 }
144 
145 /**
146  * Returns the damping applied to the compressing suspension.
147  */
148 PN_stdfloat BulletWheel::
149 get_wheels_damping_compression() const {
150  LightMutexHolder holder(BulletWorld::get_global_lock());
151 
152  return (PN_stdfloat)_info.m_wheelsDampingCompression;
153 }
154 
155 /**
156  * Sets the damping forces applied when the suspension relaxes.
157  */
158 void BulletWheel::
159 set_wheels_damping_relaxation(PN_stdfloat value) {
160  LightMutexHolder holder(BulletWorld::get_global_lock());
161 
162  _info.m_wheelsDampingRelaxation = (btScalar)value;
163 }
164 
165 /**
166  * Returns the damping applied to the relaxing suspension.
167  */
168 PN_stdfloat BulletWheel::
169 get_wheels_damping_relaxation() const {
170  LightMutexHolder holder(BulletWorld::get_global_lock());
171 
172  return (PN_stdfloat)_info.m_wheelsDampingRelaxation;
173 }
174 
175 /**
176  * Defines a scaling factor for roll forces that affect the chassis. 0.0
177  * means no roll - the chassis won't ever flip over - while 1.0 means original
178  * physical behaviour. Basically, this allows moving the center of mass up
179  * and down.
180  */
181 void BulletWheel::
182 set_roll_influence(PN_stdfloat value) {
183  LightMutexHolder holder(BulletWorld::get_global_lock());
184 
185  _info.m_rollInfluence = (btScalar)value;
186 }
187 
188 /**
189  * Returns the factor by which roll forces are scaled. See
190  * set_roll_influence.
191  */
192 PN_stdfloat BulletWheel::
193 get_roll_influence() const {
194  LightMutexHolder holder(BulletWorld::get_global_lock());
195 
196  return (PN_stdfloat)_info.m_rollInfluence;
197 }
198 
199 /**
200  * Sets the wheel radius.
201  */
202 void BulletWheel::
203 set_wheel_radius(PN_stdfloat value) {
204  LightMutexHolder holder(BulletWorld::get_global_lock());
205 
206  _info.m_wheelsRadius = (btScalar)value;
207 }
208 
209 /**
210  * Returns the wheel radius.
211  */
212 PN_stdfloat BulletWheel::
213 get_wheel_radius() const {
214  LightMutexHolder holder(BulletWorld::get_global_lock());
215 
216  return (PN_stdfloat)_info.m_wheelsRadius;
217 }
218 
219 /**
220  * Sets the steering angle.
221  */
222 void BulletWheel::
223 set_steering(PN_stdfloat value) {
224  LightMutexHolder holder(BulletWorld::get_global_lock());
225 
226  _info.m_steering = (btScalar)value;
227 }
228 
229 /**
230  * Returns the steering angle in degrees.
231  */
232 PN_stdfloat BulletWheel::
233 get_steering() const {
234  LightMutexHolder holder(BulletWorld::get_global_lock());
235 
236  return (PN_stdfloat)_info.m_steering;
237 }
238 
239 /**
240  *
241  */
242 void BulletWheel::
243 set_rotation(PN_stdfloat value) {
244  LightMutexHolder holder(BulletWorld::get_global_lock());
245 
246  _info.m_rotation = (btScalar)value;
247 }
248 
249 /**
250  *
251  */
252 PN_stdfloat BulletWheel::
253 get_rotation() const {
254  LightMutexHolder holder(BulletWorld::get_global_lock());
255 
256  return (PN_stdfloat)_info.m_rotation;
257 }
258 
259 /**
260  *
261  */
262 void BulletWheel::
263 set_delta_rotation(PN_stdfloat value) {
264  LightMutexHolder holder(BulletWorld::get_global_lock());
265 
266  _info.m_deltaRotation = (btScalar)value;
267 }
268 
269 /**
270  *
271  */
272 PN_stdfloat BulletWheel::
273 get_delta_rotation() const {
274  LightMutexHolder holder(BulletWorld::get_global_lock());
275 
276  return (PN_stdfloat)_info.m_deltaRotation;
277 }
278 
279 /**
280  * Defines how much force should be used to rotate the wheel.
281  */
282 void BulletWheel::
283 set_engine_force(PN_stdfloat value) {
284  LightMutexHolder holder(BulletWorld::get_global_lock());
285 
286  _info.m_engineForce = (btScalar)value;
287 }
288 
289 /**
290  * Returns the amount of accelleration force currently applied.
291  */
292 PN_stdfloat BulletWheel::
293 get_engine_force() const {
294  LightMutexHolder holder(BulletWorld::get_global_lock());
295 
296  return (PN_stdfloat)_info.m_engineForce;
297 }
298 
299 /**
300  *
301  */
302 void BulletWheel::
303 set_brake(PN_stdfloat value) {
304  LightMutexHolder holder(BulletWorld::get_global_lock());
305 
306  _info.m_brake = (btScalar)value;
307 }
308 
309 /**
310  * Returns the amount of braking force currently applied.
311  */
312 PN_stdfloat BulletWheel::
313 get_brake() const {
314  LightMutexHolder holder(BulletWorld::get_global_lock());
315 
316  return (PN_stdfloat)_info.m_brake;
317 }
318 
319 /**
320  *
321  */
322 void BulletWheel::
323 set_skid_info(PN_stdfloat value) {
324  LightMutexHolder holder(BulletWorld::get_global_lock());
325 
326  _info.m_skidInfo = (btScalar)value;
327 }
328 
329 /**
330  *
331  */
332 PN_stdfloat BulletWheel::
333 get_skid_info() const {
334  LightMutexHolder holder(BulletWorld::get_global_lock());
335 
336  return (PN_stdfloat)_info.m_skidInfo;
337 }
338 
339 /**
340  *
341  */
342 void BulletWheel::
343 set_wheels_suspension_force(PN_stdfloat value) {
344  LightMutexHolder holder(BulletWorld::get_global_lock());
345 
346  _info.m_wheelsSuspensionForce = (btScalar)value;
347 }
348 
349 /**
350  *
351  */
352 PN_stdfloat BulletWheel::
353 get_wheels_suspension_force() const {
354  LightMutexHolder holder(BulletWorld::get_global_lock());
355 
356  return (PN_stdfloat)_info.m_wheelsSuspensionForce;
357 }
358 
359 /**
360  *
361  */
362 void BulletWheel::
363 set_suspension_relative_velocity(PN_stdfloat value) {
364  LightMutexHolder holder(BulletWorld::get_global_lock());
365 
366  _info.m_suspensionRelativeVelocity = (btScalar)value;
367 }
368 
369 /**
370  *
371  */
372 PN_stdfloat BulletWheel::
373 get_suspension_relative_velocity() const {
374  LightMutexHolder holder(BulletWorld::get_global_lock());
375 
376  return (PN_stdfloat)_info.m_suspensionRelativeVelocity;
377 }
378 
379 /**
380  *
381  */
382 void BulletWheel::
383 set_clipped_inv_connection_point_cs(PN_stdfloat value) {
384  LightMutexHolder holder(BulletWorld::get_global_lock());
385 
386  _info.m_clippedInvContactDotSuspension = (btScalar)value;
387 }
388 
389 /**
390  *
391  */
392 PN_stdfloat BulletWheel::
393 get_clipped_inv_connection_point_cs() const {
394  LightMutexHolder holder(BulletWorld::get_global_lock());
395 
396  return (PN_stdfloat)_info.m_clippedInvContactDotSuspension;
397 }
398 
399 /**
400  * Sets the point where the wheel is connected to the chassis.
401  */
402 void BulletWheel::
403 set_chassis_connection_point_cs(const LPoint3 &pos) {
404  LightMutexHolder holder(BulletWorld::get_global_lock());
405 
406  nassertv(!pos.is_nan());
407  _info.m_chassisConnectionPointCS = LVecBase3_to_btVector3(pos);
408 }
409 
410 /**
411  * Returns the point where the wheel is connected to the chassis.
412  */
413 LPoint3 BulletWheel::
414 get_chassis_connection_point_cs() const {
415  LightMutexHolder holder(BulletWorld::get_global_lock());
416 
417  return btVector3_to_LPoint3(_info.m_chassisConnectionPointCS);
418 }
419 
420 /**
421  * Sets the wheel's forward vector. (Most likely orthogonal to the axle
422  * vector.)
423  */
424 void BulletWheel::
425 set_wheel_direction_cs(const LVector3 &dir) {
426  LightMutexHolder holder(BulletWorld::get_global_lock());
427 
428  nassertv(!dir.is_nan());
429  _info.m_wheelDirectionCS = LVecBase3_to_btVector3(dir);
430 }
431 
432 /**
433  * Returns the wheel's forward vector relative to the chassis.
434  */
435 LVector3 BulletWheel::
436 get_wheel_direction_cs() const {
437  LightMutexHolder holder(BulletWorld::get_global_lock());
438 
439  return btVector3_to_LVector3(_info.m_wheelDirectionCS);
440 }
441 
442 /**
443  * Determines the wheel axle normal vector.
444  */
445 void BulletWheel::
446 set_wheel_axle_cs(const LVector3 &axle) {
447  LightMutexHolder holder(BulletWorld::get_global_lock());
448 
449  nassertv(!axle.is_nan());
450  _info.m_wheelAxleCS = LVecBase3_to_btVector3(axle);
451 }
452 
453 /**
454  * Returns the normal vector of the wheel axle.
455  */
456 LVector3 BulletWheel::
457 get_wheel_axle_cs() const {
458  LightMutexHolder holder(BulletWorld::get_global_lock());
459 
460  return btVector3_to_LVector3(_info.m_wheelAxleCS);
461 }
462 
463 /**
464  *
465  */
466 void BulletWheel::
467 set_world_transform(const LMatrix4 &mat) {
468  LightMutexHolder holder(BulletWorld::get_global_lock());
469 
470  nassertv(!mat.is_nan());
471  _info.m_worldTransform = LMatrix4_to_btTrans(mat);
472 }
473 
474 /**
475  *
476  */
477 LMatrix4 BulletWheel::
478 get_world_transform() const {
479  LightMutexHolder holder(BulletWorld::get_global_lock());
480 
481  return btTrans_to_LMatrix4(_info.m_worldTransform);
482 }
483 
484 /**
485  * Sets if the wheel is steerable.
486  */
487 void BulletWheel::
488 set_front_wheel(bool value) {
489  LightMutexHolder holder(BulletWorld::get_global_lock());
490 
491  _info.m_bIsFrontWheel = value;
492 }
493 
494 /**
495  * Determines if a wheel is steerable.
496  */
497 bool BulletWheel::
498 is_front_wheel() const {
499  LightMutexHolder holder(BulletWorld::get_global_lock());
500 
501  return _info.m_bIsFrontWheel;
502 }
503 
504 /**
505  * Sets the PandaNode which representates the visual appearance of this wheel.
506  */
507 void BulletWheel::
508 set_node(PandaNode *node) {
509  LightMutexHolder holder(BulletWorld::get_global_lock());
510 
511  _info.m_clientInfo = (void *)node;
512 }
513 
514 /**
515  * Returns the PandaNode which representates the visual appearance of this
516  * wheel, if such a representation has been set previously.
517  */
518 PandaNode *BulletWheel::
519 get_node() const {
520  LightMutexHolder holder(BulletWorld::get_global_lock());
521 
522  return (_info.m_clientInfo == nullptr) ? nullptr : (PandaNode *)_info.m_clientInfo;
523 }
524 
525 /**
526  *
527  */
528 bool BulletWheelRaycastInfo::
529 is_in_contact() const {
530  LightMutexHolder holder(BulletWorld::get_global_lock());
531 
532  return _info.m_isInContact;
533 }
534 
535 /**
536  *
537  */
538 PN_stdfloat BulletWheelRaycastInfo::
539 get_suspension_length() const {
540  LightMutexHolder holder(BulletWorld::get_global_lock());
541 
542  return _info.m_suspensionLength;
543 }
544 
545 /**
546  *
547  */
548 LPoint3 BulletWheelRaycastInfo::
549 get_contact_point_ws() const {
550  LightMutexHolder holder(BulletWorld::get_global_lock());
551 
552  return btVector3_to_LPoint3(_info.m_contactPointWS);
553 }
554 
555 /**
556  *
557  */
558 LPoint3 BulletWheelRaycastInfo::
559 get_hard_point_ws() const {
560  LightMutexHolder holder(BulletWorld::get_global_lock());
561 
562  return btVector3_to_LPoint3(_info.m_hardPointWS);
563 }
564 
565 /**
566  *
567  */
568 LVector3 BulletWheelRaycastInfo::
569 get_contact_normal_ws() const {
570  LightMutexHolder holder(BulletWorld::get_global_lock());
571 
572  return btVector3_to_LVector3(_info.m_contactNormalWS);
573 }
574 
575 /**
576  *
577  */
578 LVector3 BulletWheelRaycastInfo::
579 get_wheel_direction_ws() const {
580  LightMutexHolder holder(BulletWorld::get_global_lock());
581 
582  return btVector3_to_LVector3(_info.m_wheelDirectionWS);
583 }
584 
585 /**
586  *
587  */
588 LVector3 BulletWheelRaycastInfo::
589 get_wheel_axle_ws() const {
590  LightMutexHolder holder(BulletWorld::get_global_lock());
591 
592  return btVector3_to_LVector3(_info.m_wheelAxleWS);
593 }
594 
595 /**
596  *
597  */
598 PandaNode *BulletWheelRaycastInfo::
599 get_ground_object() const {
600  LightMutexHolder holder(BulletWorld::get_global_lock());
601 
602  return _info.m_groundObject ? (PandaNode *)_info.m_groundObject : nullptr;
603 }
set_wheel_direction_cs
Sets the wheel's forward vector.
Definition: bulletWheel.h:137
set_steering
Sets the steering angle.
Definition: bulletWheel.h:127
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
set_wheels_damping_relaxation
Sets the damping forces applied when the suspension relaxes.
Definition: bulletWheel.h:124
set_wheels_damping_compression
Sets the damping forces applied when the suspension gets compressed.
Definition: bulletWheel.h:123
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Similar to MutexHolder, but for a light mutex.
set_chassis_connection_point_cs
Sets the point where the wheel is connected to the chassis.
Definition: bulletWheel.h:136
set_front_wheel
Sets if the wheel is steerable.
Definition: bulletWheel.h:140
set_wheel_axle_cs
Determines the wheel axle normal vector.
Definition: bulletWheel.h:138
set_max_suspension_force
Sets the maximum suspension force the wheel can handle.
Definition: bulletWheel.h:122
set_max_suspension_travel_cm
Sets the maximum distance the suspension can travel out of the resting position in centimeters.
Definition: bulletWheel.h:120
set_engine_force
Defines how much force should be used to rotate the wheel.
Definition: bulletWheel.h:130
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_node
Sets the PandaNode which representates the visual appearance of this wheel.
Definition: bulletWheel.h:141
set_suspension_stiffness
Sets how stiff the suspension shall be.
Definition: bulletWheel.h:119
set_roll_influence
Defines a scaling factor for roll forces that affect the chassis.
Definition: bulletWheel.h:125
set_friction_slip
Sets the slipperyness of the tyre.
Definition: bulletWheel.h:121
set_wheel_radius
Sets the wheel radius.
Definition: bulletWheel.h:126