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 */
21BulletWheel::
22BulletWheel(btWheelInfo &info) : _info(info) {
23
24}
25
26/**
27 *
28 */
29BulletWheelRaycastInfo::
30BulletWheelRaycastInfo(btWheelInfo::RaycastInfo &info) : _info(info) {
31
32}
33
34/**
35 *
36 */
37BulletWheelRaycastInfo BulletWheel::
38get_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 */
47PN_stdfloat BulletWheel::
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 */
58set_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 */
67PN_stdfloat BulletWheel::
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 */
79set_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 */
88PN_stdfloat BulletWheel::
89get_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 */
99set_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 */
108PN_stdfloat BulletWheel::
109get_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 */
118void BulletWheel::
119set_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 */
128PN_stdfloat BulletWheel::
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 */
138void BulletWheel::
139set_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 */
148PN_stdfloat BulletWheel::
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 */
158void BulletWheel::
159set_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 */
168PN_stdfloat BulletWheel::
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 */
181void BulletWheel::
182set_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 */
192PN_stdfloat BulletWheel::
193get_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 */
202void BulletWheel::
203set_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 */
212PN_stdfloat BulletWheel::
213get_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 */
222void BulletWheel::
223set_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 */
232PN_stdfloat BulletWheel::
233get_steering() const {
234 LightMutexHolder holder(BulletWorld::get_global_lock());
235
236 return (PN_stdfloat)_info.m_steering;
237}
238
239/**
240 *
241 */
242void BulletWheel::
243set_rotation(PN_stdfloat value) {
244 LightMutexHolder holder(BulletWorld::get_global_lock());
245
246 _info.m_rotation = (btScalar)value;
247}
248
249/**
250 *
251 */
252PN_stdfloat BulletWheel::
253get_rotation() const {
254 LightMutexHolder holder(BulletWorld::get_global_lock());
255
256 return (PN_stdfloat)_info.m_rotation;
257}
258
259/**
260 *
261 */
262void BulletWheel::
263set_delta_rotation(PN_stdfloat value) {
264 LightMutexHolder holder(BulletWorld::get_global_lock());
265
266 _info.m_deltaRotation = (btScalar)value;
267}
268
269/**
270 *
271 */
272PN_stdfloat BulletWheel::
273get_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 */
282void BulletWheel::
283set_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 */
292PN_stdfloat BulletWheel::
293get_engine_force() const {
294 LightMutexHolder holder(BulletWorld::get_global_lock());
295
296 return (PN_stdfloat)_info.m_engineForce;
297}
298
299/**
300 *
301 */
302void BulletWheel::
303set_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 */
312PN_stdfloat BulletWheel::
313get_brake() const {
314 LightMutexHolder holder(BulletWorld::get_global_lock());
315
316 return (PN_stdfloat)_info.m_brake;
317}
318
319/**
320 *
321 */
322void BulletWheel::
323set_skid_info(PN_stdfloat value) {
324 LightMutexHolder holder(BulletWorld::get_global_lock());
325
326 _info.m_skidInfo = (btScalar)value;
327}
328
329/**
330 *
331 */
332PN_stdfloat BulletWheel::
333get_skid_info() const {
334 LightMutexHolder holder(BulletWorld::get_global_lock());
335
336 return (PN_stdfloat)_info.m_skidInfo;
337}
338
339/**
340 *
341 */
342void BulletWheel::
343set_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 */
352PN_stdfloat BulletWheel::
353get_wheels_suspension_force() const {
354 LightMutexHolder holder(BulletWorld::get_global_lock());
355
356 return (PN_stdfloat)_info.m_wheelsSuspensionForce;
357}
358
359/**
360 *
361 */
362void BulletWheel::
363set_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 */
372PN_stdfloat BulletWheel::
373get_suspension_relative_velocity() const {
374 LightMutexHolder holder(BulletWorld::get_global_lock());
375
376 return (PN_stdfloat)_info.m_suspensionRelativeVelocity;
377}
378
379/**
380 *
381 */
382void BulletWheel::
383set_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 */
392PN_stdfloat BulletWheel::
393get_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 */
402void BulletWheel::
403set_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 */
413LPoint3 BulletWheel::
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 */
424void BulletWheel::
425set_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 */
435LVector3 BulletWheel::
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 */
445void BulletWheel::
446set_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 */
456LVector3 BulletWheel::
457get_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 */
466void BulletWheel::
467set_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 */
477LMatrix4 BulletWheel::
478get_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 */
487void BulletWheel::
488set_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 */
497bool BulletWheel::
498is_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 */
507void BulletWheel::
508set_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 */
519get_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 */
528bool BulletWheelRaycastInfo::
529is_in_contact() const {
530 LightMutexHolder holder(BulletWorld::get_global_lock());
531
532 return _info.m_isInContact;
533}
534
535/**
536 *
537 */
538PN_stdfloat BulletWheelRaycastInfo::
539get_suspension_length() const {
540 LightMutexHolder holder(BulletWorld::get_global_lock());
541
542 return _info.m_suspensionLength;
543}
544
545/**
546 *
547 */
548LPoint3 BulletWheelRaycastInfo::
549get_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 */
558LPoint3 BulletWheelRaycastInfo::
559get_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 */
568LVector3 BulletWheelRaycastInfo::
569get_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 */
578LVector3 BulletWheelRaycastInfo::
579get_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 */
588LVector3 BulletWheelRaycastInfo::
589get_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 */
598PandaNode *BulletWheelRaycastInfo::
599get_ground_object() const {
600 LightMutexHolder holder(BulletWorld::get_global_lock());
601
602 return _info.m_groundObject ? (PandaNode *)_info.m_groundObject : nullptr;
603}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
set_front_wheel
Sets if the wheel is steerable.
Definition: bulletWheel.h:140
get_friction_slip
Returns how slippery the tyres are.
Definition: bulletWheel.h:121
get_engine_force
Returns the amount of accelleration force currently applied.
Definition: bulletWheel.h:130
get_wheel_radius
Returns the wheel radius.
Definition: bulletWheel.h:126
set_roll_influence
Defines a scaling factor for roll forces that affect the chassis.
Definition: bulletWheel.h:125
get_wheel_axle_cs
Returns the normal vector of the wheel axle.
Definition: bulletWheel.h:138
set_friction_slip
Sets the slipperyness of the tyre.
Definition: bulletWheel.h:121
set_wheel_axle_cs
Determines the wheel axle normal vector.
Definition: bulletWheel.h:138
get_brake
Returns the amount of braking force currently applied.
Definition: bulletWheel.h:131
set_chassis_connection_point_cs
Sets the point where the wheel is connected to the chassis.
Definition: bulletWheel.h:136
set_max_suspension_travel_cm
Sets the maximum distance the suspension can travel out of the resting position in centimeters.
Definition: bulletWheel.h:120
get_wheels_damping_compression
Returns the damping applied to the compressing suspension.
Definition: bulletWheel.h:123
get_suspension_rest_length
Returns the length of the suspension when the vehicle is standing still.
Definition: bulletWheel.h:118
set_wheels_damping_relaxation
Sets the damping forces applied when the suspension relaxes.
Definition: bulletWheel.h:124
set_wheel_direction_cs
Sets the wheel's forward vector.
Definition: bulletWheel.h:137
set_node
Sets the PandaNode which representates the visual appearance of this wheel.
Definition: bulletWheel.h:141
get_suspension_stiffness
Returns the stiffness of the suspension.
Definition: bulletWheel.h:119
set_wheels_damping_compression
Sets the damping forces applied when the suspension gets compressed.
Definition: bulletWheel.h:123
set_steering
Sets the steering angle.
Definition: bulletWheel.h:127
set_suspension_stiffness
Sets how stiff the suspension shall be.
Definition: bulletWheel.h:119
get_steering
Returns the steering angle in degrees.
Definition: bulletWheel.h:127
is_front_wheel
Determines if a wheel is steerable.
Definition: bulletWheel.h:140
set_wheel_radius
Sets the wheel radius.
Definition: bulletWheel.h:126
get_wheel_direction_cs
Returns the wheel's forward vector relative to the chassis.
Definition: bulletWheel.h:137
get_node
Returns the PandaNode which representates the visual appearance of this wheel, if such a representati...
Definition: bulletWheel.h:141
get_chassis_connection_point_cs
Returns the point where the wheel is connected to the chassis.
Definition: bulletWheel.h:136
set_max_suspension_force
Sets the maximum suspension force the wheel can handle.
Definition: bulletWheel.h:122
get_roll_influence
Returns the factor by which roll forces are scaled.
Definition: bulletWheel.h:125
get_max_suspension_force
Returns the maximum force (weight) the suspension can handle.
Definition: bulletWheel.h:122
set_engine_force
Defines how much force should be used to rotate the wheel.
Definition: bulletWheel.h:130
get_wheels_damping_relaxation
Returns the damping applied to the relaxing suspension.
Definition: bulletWheel.h:124
Similar to MutexHolder, but for a light mutex.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65