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