Bullet Collision Detection & Physics Library
btRaycastVehicle.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
3 *
4 * Permission to use, copy, modify, distribute and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies.
7 * Erwin Coumans makes no representations about the suitability
8 * of this software for any purpose.
9 * It is provided "as is" without express or implied warranty.
10*/
11
13#include "btRaycastVehicle.h"
14
19#include "btVehicleRaycaster.h"
20#include "btWheelInfo.h"
21#include "LinearMath/btMinMax.h"
24
25#define ROLLING_INFLUENCE_FIX
26
27
29{
30 static btRigidBody s_fixed(0, 0,0);
31 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
32 return s_fixed;
33}
34
36:m_vehicleRaycaster(raycaster),
37m_pitchControl(btScalar(0.))
38{
39 m_chassisBody = chassis;
41 m_indexUpAxis = 2;
43 defaultInit(tuning);
44}
45
46
48{
49 (void)tuning;
52
53}
54
55
56
58{
59}
60
61
62//
63// basically most of the code is general for 2 or 4 wheel vehicles, but some of it needs to be reviewed
64//
65btWheelInfo& btRaycastVehicle::addWheel( const btVector3& connectionPointCS, const btVector3& wheelDirectionCS0,const btVector3& wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius,const btVehicleTuning& tuning, bool isFrontWheel)
66{
67
69
70 ci.m_chassisConnectionCS = connectionPointCS;
71 ci.m_wheelDirectionCS = wheelDirectionCS0;
72 ci.m_wheelAxleCS = wheelAxleCS;
73 ci.m_suspensionRestLength = suspensionRestLength;
74 ci.m_wheelRadius = wheelRadius;
79 ci.m_bIsFrontWheel = isFrontWheel;
82
83 m_wheelInfo.push_back( btWheelInfo(ci));
84
86
87 updateWheelTransformsWS( wheel , false );
89 return wheel;
90}
91
92
93
94
96{
97 btAssert(wheelIndex < getNumWheels());
98 const btWheelInfo& wheel = m_wheelInfo[wheelIndex];
99 return wheel.m_worldTransform;
100
101}
102
103void btRaycastVehicle::updateWheelTransform( int wheelIndex , bool interpolatedTransform)
104{
105
106 btWheelInfo& wheel = m_wheelInfo[ wheelIndex ];
107 updateWheelTransformsWS(wheel,interpolatedTransform);
109 const btVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
110 btVector3 fwd = up.cross(right);
111 fwd = fwd.normalize();
112// up = right.cross(fwd);
113// up.normalize();
114
115 //rotate around steering over de wheelAxleWS
116 btScalar steering = wheel.m_steering;
117
118 btQuaternion steeringOrn(up,steering);//wheel.m_steering);
119 btMatrix3x3 steeringMat(steeringOrn);
120
121 btQuaternion rotatingOrn(right,-wheel.m_rotation);
122 btMatrix3x3 rotatingMat(rotatingOrn);
123
124 btMatrix3x3 basis2(
125 right[0],fwd[0],up[0],
126 right[1],fwd[1],up[1],
127 right[2],fwd[2],up[2]
128 );
129
130 wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
133 );
134}
135
137{
138
139 int i;
140 for (i=0;i<m_wheelInfo.size(); i++)
141 {
142 btWheelInfo& wheel = m_wheelInfo[i];
145
147 //wheel_info.setContactFriction(btScalar(0.0));
149 }
150}
151
152void btRaycastVehicle::updateWheelTransformsWS(btWheelInfo& wheel , bool interpolatedTransform)
153{
154 wheel.m_raycastInfo.m_isInContact = false;
155
156 btTransform chassisTrans = getChassisWorldTransform();
157 if (interpolatedTransform && (getRigidBody()->getMotionState()))
158 {
160 }
161
162 wheel.m_raycastInfo.m_hardPointWS = chassisTrans( wheel.m_chassisConnectionPointCS );
163 wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.getBasis() * wheel.m_wheelDirectionCS ;
164 wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.getBasis() * wheel.m_wheelAxleCS;
165}
166
168{
169 updateWheelTransformsWS( wheel,false);
170
171
172 btScalar depth = -1;
173
174 btScalar raylen = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius;
175
176 btVector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
177 const btVector3& source = wheel.m_raycastInfo.m_hardPointWS;
178 wheel.m_raycastInfo.m_contactPointWS = source + rayvector;
179 const btVector3& target = wheel.m_raycastInfo.m_contactPointWS;
180
181 btScalar param = btScalar(0.);
182
184
186
187 void* object = m_vehicleRaycaster->castRay(source,target,rayResults);
188
190
191 if (object)
192 {
193 param = rayResults.m_distFraction;
194 depth = raylen * rayResults.m_distFraction;
196 wheel.m_raycastInfo.m_isInContact = true;
197
199 //wheel.m_raycastInfo.m_groundObject = object;
200
201
202 btScalar hitDistance = param*raylen;
203 wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelsRadius;
204 //clamp on max suspension travel
205
206 btScalar minSuspensionLength = wheel.getSuspensionRestLength() - wheel.m_maxSuspensionTravelCm*btScalar(0.01);
207 btScalar maxSuspensionLength = wheel.getSuspensionRestLength()+ wheel.m_maxSuspensionTravelCm*btScalar(0.01);
208 if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength)
209 {
210 wheel.m_raycastInfo.m_suspensionLength = minSuspensionLength;
211 }
212 if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength)
213 {
214 wheel.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
215 }
216
218
220
221 btVector3 chassis_velocity_at_contactPoint;
223
224 chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);
225
226 btScalar projVel = wheel.m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );
227
228 if ( denominator >= btScalar(-0.1))
229 {
232 }
233 else
234 {
235 btScalar inv = btScalar(-1.) / denominator;
236 wheel.m_suspensionRelativeVelocity = projVel * inv;
238 }
239
240 } else
241 {
242 //put wheel info as in rest position
247 }
248
249 return depth;
250}
251
252
254{
255 /*if (getRigidBody()->getMotionState())
256 {
257 btTransform chassisWorldTrans;
258 getRigidBody()->getMotionState()->getWorldTransform(chassisWorldTrans);
259 return chassisWorldTrans;
260 }
261 */
262
263
265}
266
267
269{
270 {
271 for (int i=0;i<getNumWheels();i++)
272 {
273 updateWheelTransform(i,false);
274 }
275 }
276
277
279
280 const btTransform& chassisTrans = getChassisWorldTransform();
281
282 btVector3 forwardW (
283 chassisTrans.getBasis()[0][m_indexForwardAxis],
284 chassisTrans.getBasis()[1][m_indexForwardAxis],
285 chassisTrans.getBasis()[2][m_indexForwardAxis]);
286
287 if (forwardW.dot(getRigidBody()->getLinearVelocity()) < btScalar(0.))
288 {
290 }
291
292 //
293 // simulate suspension
294 //
295
296 int i=0;
297 for (i=0;i<m_wheelInfo.size();i++)
298 {
299 //btScalar depth;
300 //depth =
301 rayCast( m_wheelInfo[i]);
302 }
303
304 updateSuspension(step);
305
306
307 for (i=0;i<m_wheelInfo.size();i++)
308 {
309 //apply suspension force
310 btWheelInfo& wheel = m_wheelInfo[i];
311
312 btScalar suspensionForce = wheel.m_wheelsSuspensionForce;
313
314 if (suspensionForce > wheel.m_maxSuspensionForce)
315 {
316 suspensionForce = wheel.m_maxSuspensionForce;
317 }
318 btVector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
320
321 getRigidBody()->applyImpulse(impulse, relpos);
322
323 }
324
325
326
327 updateFriction( step);
328
329
330 for (i=0;i<m_wheelInfo.size();i++)
331 {
332 btWheelInfo& wheel = m_wheelInfo[i];
335
337 {
338 const btTransform& chassisWorldTransform = getChassisWorldTransform();
339
340 btVector3 fwd (
341 chassisWorldTransform.getBasis()[0][m_indexForwardAxis],
342 chassisWorldTransform.getBasis()[1][m_indexForwardAxis],
343 chassisWorldTransform.getBasis()[2][m_indexForwardAxis]);
344
346 fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;
347
348 btScalar proj2 = fwd.dot(vel);
349
350 wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelsRadius);
351 wheel.m_rotation += wheel.m_deltaRotation;
352
353 } else
354 {
355 wheel.m_rotation += wheel.m_deltaRotation;
356 }
357
358 wheel.m_deltaRotation *= btScalar(0.99);//damping of rotation when not in contact
359
360 }
361
362
363
364}
365
366
368{
369 btAssert(wheel>=0 && wheel < getNumWheels());
370
371 btWheelInfo& wheelInfo = getWheelInfo(wheel);
372 wheelInfo.m_steering = steering;
373}
374
375
376
378{
379 return getWheelInfo(wheel).m_steering;
380}
381
382
384{
385 btAssert(wheel>=0 && wheel < getNumWheels());
386 btWheelInfo& wheelInfo = getWheelInfo(wheel);
387 wheelInfo.m_engineForce = force;
388}
389
390
392{
393 btAssert((index >= 0) && (index < getNumWheels()));
394
395 return m_wheelInfo[index];
396}
397
399{
400 btAssert((index >= 0) && (index < getNumWheels()));
401
402 return m_wheelInfo[index];
403}
404
405void btRaycastVehicle::setBrake(btScalar brake,int wheelIndex)
406{
407 btAssert((wheelIndex >= 0) && (wheelIndex < getNumWheels()));
408 getWheelInfo(wheelIndex).m_brake = brake;
409}
410
411
413{
414 (void)deltaTime;
415
416 btScalar chassisMass = btScalar(1.) / m_chassisBody->getInvMass();
417
418 for (int w_it=0; w_it<getNumWheels(); w_it++)
419 {
420 btWheelInfo &wheel_info = m_wheelInfo[w_it];
421
422 if ( wheel_info.m_raycastInfo.m_isInContact )
423 {
424 btScalar force;
425 // Spring
426 {
427 btScalar susp_length = wheel_info.getSuspensionRestLength();
428 btScalar current_length = wheel_info.m_raycastInfo.m_suspensionLength;
429
430 btScalar length_diff = (susp_length - current_length);
431
432 force = wheel_info.m_suspensionStiffness
433 * length_diff * wheel_info.m_clippedInvContactDotSuspension;
434 }
435
436 // Damper
437 {
438 btScalar projected_rel_vel = wheel_info.m_suspensionRelativeVelocity;
439 {
440 btScalar susp_damping;
441 if ( projected_rel_vel < btScalar(0.0) )
442 {
443 susp_damping = wheel_info.m_wheelsDampingCompression;
444 }
445 else
446 {
447 susp_damping = wheel_info.m_wheelsDampingRelaxation;
448 }
449 force -= susp_damping * projected_rel_vel;
450 }
451 }
452
453 // RESULT
454 wheel_info.m_wheelsSuspensionForce = force * chassisMass;
455 if (wheel_info.m_wheelsSuspensionForce < btScalar(0.))
456 {
457 wheel_info.m_wheelsSuspensionForce = btScalar(0.);
458 }
459 }
460 else
461 {
462 wheel_info.m_wheelsSuspensionForce = btScalar(0.0);
463 }
464 }
465
466}
467
468
470{
477
478
479 btWheelContactPoint(btRigidBody* body0,btRigidBody* body1,const btVector3& frictionPosWorld,const btVector3& frictionDirectionWorld, btScalar maxImpulse)
480 :m_body0(body0),
481 m_body1(body1),
482 m_frictionPositionWorld(frictionPosWorld),
483 m_frictionDirectionWorld(frictionDirectionWorld),
484 m_maxImpulse(maxImpulse)
485 {
486 btScalar denom0 = body0->computeImpulseDenominator(frictionPosWorld,frictionDirectionWorld);
487 btScalar denom1 = body1->computeImpulseDenominator(frictionPosWorld,frictionDirectionWorld);
488 btScalar relaxation = 1.f;
489 m_jacDiagABInv = relaxation/(denom0+denom1);
490 }
491
492
493
494};
495
498{
499
500 btScalar j1=0.f;
501
502 const btVector3& contactPosWorld = contactPoint.m_frictionPositionWorld;
503
504 btVector3 rel_pos1 = contactPosWorld - contactPoint.m_body0->getCenterOfMassPosition();
505 btVector3 rel_pos2 = contactPosWorld - contactPoint.m_body1->getCenterOfMassPosition();
506
507 btScalar maxImpulse = contactPoint.m_maxImpulse;
508
509 btVector3 vel1 = contactPoint.m_body0->getVelocityInLocalPoint(rel_pos1);
510 btVector3 vel2 = contactPoint.m_body1->getVelocityInLocalPoint(rel_pos2);
511 btVector3 vel = vel1 - vel2;
512
513 btScalar vrel = contactPoint.m_frictionDirectionWorld.dot(vel);
514
515 // calculate j that moves us to zero relative velocity
516 j1 = -vrel * contactPoint.m_jacDiagABInv;
517 btSetMin(j1, maxImpulse);
518 btSetMax(j1, -maxImpulse);
519
520 return j1;
521}
522
523
524
525
528{
529
530 //calculate the impulse, so that the wheels don't move sidewards
531 int numWheel = getNumWheels();
532 if (!numWheel)
533 return;
534
535 m_forwardWS.resize(numWheel);
536 m_axle.resize(numWheel);
537 m_forwardImpulse.resize(numWheel);
538 m_sideImpulse.resize(numWheel);
539
540 int numWheelsOnGround = 0;
541
542
543 //collapse all those loops into one!
544 for (int i=0;i<getNumWheels();i++)
545 {
546 btWheelInfo& wheelInfo = m_wheelInfo[i];
547 class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
548 if (groundObject)
549 numWheelsOnGround++;
550 m_sideImpulse[i] = btScalar(0.);
551 m_forwardImpulse[i] = btScalar(0.);
552
553 }
554
555 {
556
557 for (int i=0;i<getNumWheels();i++)
558 {
559
560 btWheelInfo& wheelInfo = m_wheelInfo[i];
561
562 class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
563
564 if (groundObject)
565 {
566
567 const btTransform& wheelTrans = getWheelTransformWS( i );
568
569 btMatrix3x3 wheelBasis0 = wheelTrans.getBasis();
570 m_axle[i] = btVector3(
571 wheelBasis0[0][m_indexRightAxis],
572 wheelBasis0[1][m_indexRightAxis],
573 wheelBasis0[2][m_indexRightAxis]);
574
575 const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
576 btScalar proj = m_axle[i].dot(surfNormalWS);
577 m_axle[i] -= surfNormalWS * proj;
578 m_axle[i] = m_axle[i].normalize();
579
580 m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
581 m_forwardWS[i].normalize();
582
583
585 *groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
586 btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);
587
589
590 }
591
592
593 }
594 }
595
596 btScalar sideFactor = btScalar(1.);
597 btScalar fwdFactor = 0.5;
598
599 bool sliding = false;
600 {
601 for (int wheel =0;wheel <getNumWheels();wheel++)
602 {
603 btWheelInfo& wheelInfo = m_wheelInfo[wheel];
604 class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
605
606 btScalar rollingFriction = 0.f;
607
608 if (groundObject)
609 {
610 if (wheelInfo.m_engineForce != 0.f)
611 {
612 rollingFriction = wheelInfo.m_engineForce* timeStep;
613 } else
614 {
615 btScalar defaultRollingFrictionImpulse = 0.f;
616 btScalar maxImpulse = wheelInfo.m_brake ? wheelInfo.m_brake : defaultRollingFrictionImpulse;
617 btWheelContactPoint contactPt(m_chassisBody,groundObject,wheelInfo.m_raycastInfo.m_contactPointWS,m_forwardWS[wheel],maxImpulse);
618 rollingFriction = calcRollingFriction(contactPt);
619 }
620 }
621
622 //switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
623
624
625
626
627 m_forwardImpulse[wheel] = btScalar(0.);
628 m_wheelInfo[wheel].m_skidInfo= btScalar(1.);
629
630 if (groundObject)
631 {
632 m_wheelInfo[wheel].m_skidInfo= btScalar(1.);
633
634 btScalar maximp = wheelInfo.m_wheelsSuspensionForce * timeStep * wheelInfo.m_frictionSlip;
635 btScalar maximpSide = maximp;
636
637 btScalar maximpSquared = maximp * maximpSide;
638
639
640 m_forwardImpulse[wheel] = rollingFriction;//wheelInfo.m_engineForce* timeStep;
641
642 btScalar x = (m_forwardImpulse[wheel] ) * fwdFactor;
643 btScalar y = (m_sideImpulse[wheel] ) * sideFactor;
644
645 btScalar impulseSquared = (x*x + y*y);
646
647 if (impulseSquared > maximpSquared)
648 {
649 sliding = true;
650
651 btScalar factor = maximp / btSqrt(impulseSquared);
652
653 m_wheelInfo[wheel].m_skidInfo *= factor;
654 }
655 }
656
657 }
658 }
659
660
661
662
663 if (sliding)
664 {
665 for (int wheel = 0;wheel < getNumWheels(); wheel++)
666 {
667 if (m_sideImpulse[wheel] != btScalar(0.))
668 {
669 if (m_wheelInfo[wheel].m_skidInfo< btScalar(1.))
670 {
671 m_forwardImpulse[wheel] *= m_wheelInfo[wheel].m_skidInfo;
672 m_sideImpulse[wheel] *= m_wheelInfo[wheel].m_skidInfo;
673 }
674 }
675 }
676 }
677
678 // apply the impulses
679 {
680 for (int wheel = 0;wheel<getNumWheels() ; wheel++)
681 {
682 btWheelInfo& wheelInfo = m_wheelInfo[wheel];
683
684 btVector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS -
686
687 if (m_forwardImpulse[wheel] != btScalar(0.))
688 {
689 m_chassisBody->applyImpulse(m_forwardWS[wheel]*(m_forwardImpulse[wheel]),rel_pos);
690 }
691 if (m_sideImpulse[wheel] != btScalar(0.))
692 {
693 class btRigidBody* groundObject = (class btRigidBody*) m_wheelInfo[wheel].m_raycastInfo.m_groundObject;
694
695 btVector3 rel_pos2 = wheelInfo.m_raycastInfo.m_contactPointWS -
696 groundObject->getCenterOfMassPosition();
697
698
699 btVector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel];
700
701#if defined ROLLING_INFLUENCE_FIX // fix. It only worked if car's up was along Y - VT.
703 rel_pos -= vChassisWorldUp * (vChassisWorldUp.dot(rel_pos) * (1.f-wheelInfo.m_rollInfluence));
704#else
705 rel_pos[m_indexUpAxis] *= wheelInfo.m_rollInfluence;
706#endif
707 m_chassisBody->applyImpulse(sideImp,rel_pos);
708
709 //apply friction impulse on the ground
710 groundObject->applyImpulse(-sideImp,rel_pos2);
711 }
712 }
713 }
714
715
716}
717
718
719
721{
722
723 for (int v=0;v<this->getNumWheels();v++)
724 {
725 btVector3 wheelColor(0,1,1);
726 if (getWheelInfo(v).m_raycastInfo.m_isInContact)
727 {
728 wheelColor.setValue(0,0,1);
729 } else
730 {
731 wheelColor.setValue(1,0,1);
732 }
733
735
736 btVector3 axle = btVector3(
740
741 //debug wheels (cylinders)
742 debugDrawer->drawLine(wheelPosWS,wheelPosWS+axle,wheelColor);
743 debugDrawer->drawLine(wheelPosWS,getWheelInfo(v).m_raycastInfo.m_contactPointWS,wheelColor);
744
745 }
746}
747
748
750{
751// RayResultCallback& resultCallback;
752
754
755 m_dynamicsWorld->rayTest(from, to, rayCallback);
756
757 if (rayCallback.hasHit())
758 {
759
760 const btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
761 if (body && body->hasContactResponse())
762 {
763 result.m_hitPointInWorld = rayCallback.m_hitPointWorld;
764 result.m_hitNormalInWorld = rayCallback.m_hitNormalWorld;
766 result.m_distFraction = rayCallback.m_closestHitFraction;
767 return (void*)body;
768 }
769 }
770 return 0;
771}
772
void resolveSingleBilateral(btRigidBody &body1, const btVector3 &pos1, btRigidBody &body2, const btVector3 &pos2, btScalar distance, const btVector3 &normal, btScalar &impulse, btScalar timeStep)
resolveSingleBilateral is an obsolete methods used for vehicle friction between two dynamic objects
void btSetMin(T &a, const T &b)
Definition: btMinMax.h:41
void btSetMax(T &a, const T &b)
Definition: btMinMax.h:50
btScalar calcRollingFriction(btWheelContactPoint &contactPoint)
btScalar sideFrictionStiffness2
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btScalar btSqrt(btScalar y)
Definition: btScalar.h:444
#define btAssert(x)
Definition: btScalar.h:131
static btRigidBody & getFixedBody()
void resize(int newsize, const T &fillData=T())
btTransform m_worldTransform
bool hasContactResponse() const
virtual void rayTest(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, RayResultCallback &resultCallback) const
rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback This ...
virtual void * castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result)
btDynamicsWorld * m_dynamicsWorld
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:30
virtual void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)=0
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
btVector3 getColumn(int i) const
Get a column of the matrix as a vector.
Definition: btMatrix3x3.h:134
virtual void getWorldTransform(btTransform &worldTrans) const =0
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:55
btAlignedObjectArray< btVector3 > m_forwardWS
virtual void updateFriction(btScalar timeStep)
void defaultInit(const btVehicleTuning &tuning)
void updateWheelTransformsWS(btWheelInfo &wheel, bool interpolatedTransform=true)
btRigidBody * getRigidBody()
btAlignedObjectArray< btScalar > m_sideImpulse
const btTransform & getWheelTransformWS(int wheelIndex) const
int getNumWheels() const
btScalar m_currentVehicleSpeedKmHour
btScalar rayCast(btWheelInfo &wheel)
btScalar getSteeringValue(int wheel) const
void setBrake(btScalar brake, int wheelIndex)
void updateSuspension(btScalar deltaTime)
virtual ~btRaycastVehicle()
btAlignedObjectArray< btVector3 > m_axle
btRaycastVehicle(const btVehicleTuning &tuning, btRigidBody *chassis, btVehicleRaycaster *raycaster)
int getRightAxis() const
btVehicleRaycaster * m_vehicleRaycaster
virtual void updateVehicle(btScalar step)
btScalar m_steeringValue
btAlignedObjectArray< btScalar > m_forwardImpulse
btAlignedObjectArray< btWheelInfo > m_wheelInfo
btRigidBody * m_chassisBody
void applyEngineForce(btScalar force, int wheel)
btWheelInfo & addWheel(const btVector3 &connectionPointCS0, const btVector3 &wheelDirectionCS0, const btVector3 &wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius, const btVehicleTuning &tuning, bool isFrontWheel)
void debugDraw(btIDebugDraw *debugDrawer)
btActionInterface interface
const btTransform & getChassisWorldTransform() const
void updateWheelTransform(int wheelIndex, bool interpolatedTransform=true)
const btWheelInfo & getWheelInfo(int index) const
void setSteeringValue(btScalar steering, int wheel)
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:63
btVector3 getVelocityInLocalPoint(const btVector3 &rel_pos) const
Definition: btRigidBody.h:382
btScalar getInvMass() const
Definition: btRigidBody.h:273
const btTransform & getCenterOfMassTransform() const
Definition: btRigidBody.h:359
void applyImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
Definition: btRigidBody.h:334
btMotionState * getMotionState()
Definition: btRigidBody.h:474
void setMassProps(btScalar mass, const btVector3 &inertia)
const btVector3 & getCenterOfMassPosition() const
Definition: btRigidBody.h:354
btScalar computeImpulseDenominator(const btVector3 &pos, const btVector3 &normal) const
Definition: btRigidBody.h:403
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don't store a rigidbody pointer but a rigidbody ...
Definition: btRigidBody.h:203
const btVector3 & getLinearVelocity() const
Definition: btRigidBody.h:362
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btMatrix3x3 & getBasis()
Return the basis matrix for the rotation.
Definition: btTransform.h:112
btVector3 & getOrigin()
Return the origin vector translation.
Definition: btTransform.h:117
void setOrigin(const btVector3 &origin)
Set the translational element.
Definition: btTransform.h:150
void setBasis(const btMatrix3x3 &basis)
Set the rotational element by btMatrix3x3.
Definition: btTransform.h:159
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
btScalar length() const
Return the length of the vector.
Definition: btVector3.h:263
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition: btVector3.h:389
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:235
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:652
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition: btVector3.h:309
const btCollisionObject * m_collisionObject
btVehicleRaycaster is provides interface for between vehicle simulation and raycasting
virtual void * castRay(const btVector3 &from, const btVector3 &to, btVehicleRaycasterResult &result)=0
btVector3 m_frictionDirectionWorld
btWheelContactPoint(btRigidBody *body0, btRigidBody *body1, const btVector3 &frictionPosWorld, const btVector3 &frictionDirectionWorld, btScalar maxImpulse)
btVector3 m_wheelDirectionWS
Definition: btWheelInfo.h:47
btWheelInfo contains information per wheel about friction and suspension.
Definition: btWheelInfo.h:39
btScalar m_clippedInvContactDotSuspension
Definition: btWheelInfo.h:112
btScalar m_suspensionStiffness
Definition: btWheelInfo.h:64
btVector3 m_wheelDirectionCS
Definition: btWheelInfo.h:58
btScalar getSuspensionRestLength() const
Definition: btWheelInfo.cpp:15
btScalar m_maxSuspensionForce
Definition: btWheelInfo.h:72
btScalar m_rotation
Definition: btWheelInfo.h:69
btScalar m_maxSuspensionTravelCm
Definition: btWheelInfo.h:61
btScalar m_steering
Definition: btWheelInfo.h:68
btScalar m_wheelsSuspensionForce
Definition: btWheelInfo.h:115
btScalar m_wheelsRadius
Definition: btWheelInfo.h:63
btScalar m_rollInfluence
Definition: btWheelInfo.h:71
btVector3 m_chassisConnectionPointCS
Definition: btWheelInfo.h:57
btScalar m_brake
Definition: btWheelInfo.h:76
btScalar m_wheelsDampingCompression
Definition: btWheelInfo.h:65
btVector3 m_wheelAxleCS
Definition: btWheelInfo.h:59
btScalar m_suspensionRelativeVelocity
Definition: btWheelInfo.h:113
btScalar m_deltaRotation
Definition: btWheelInfo.h:70
btScalar m_frictionSlip
Definition: btWheelInfo.h:67
btScalar m_wheelsDampingRelaxation
Definition: btWheelInfo.h:66
btTransform m_worldTransform
Definition: btWheelInfo.h:55
RaycastInfo m_raycastInfo
Definition: btWheelInfo.h:53
btScalar m_engineForce
Definition: btWheelInfo.h:74