@@ -348,7 +348,7 @@ namespace vg::physics
348348 }
349349
350350 // --------------------------------------------------------------------------------------
351- void VehicleConstraint::FixedUpdate (const DriveState & _driveState)
351+ void VehicleConstraint::UpdateDriveState (const DriveState & _driveState)
352352 {
353353 if (m_joltVehicleConstraint)
354354 {
@@ -430,10 +430,80 @@ namespace vg::physics
430430 m_joltVehicleConstraint->SetVehicleCollisionTester (m_joltVehicleCollisionTester);
431431 }
432432
433- // --------------------------------------------------------------------------------------
434- // TODO: move debug display to tool update pass
435433 // --------------------------------------------------------------------------------------
436434 void VehicleConstraint::updateVisuals ()
435+ {
436+ if (m_joltVehicleConstraint)
437+ {
438+ switch (m_vehicleConstraintDesc->GetVehicleType ())
439+ {
440+ default :
441+ {
442+ VG_ASSERT_ENUM_NOT_IMPLEMENTED (m_vehicleConstraintDesc->GetVehicleType ());
443+ }
444+ break ;
445+
446+ case VehicleType::Car:
447+ {
448+ const CarConstraintDesc * desc = VG_SAFE_STATIC_CAST (const CarConstraintDesc, m_vehicleConstraintDesc);
449+
450+ const uint wheelCount = desc->GetWheelCount ();
451+
452+ for (uint i = 0 ; i < wheelCount; ++i)
453+ {
454+ const JPH ::Wheel * wheel = m_joltVehicleConstraint->GetWheel (i);
455+ const JPH ::WheelSettings * wheelSettings = wheel->GetSettings ();
456+
457+ const float radius = wheelSettings->mRadius ;
458+ const float width = wheelSettings->mWidth ;
459+
460+ // transform the wheel visual
461+ const TwoWheeledAxleDesc & axle = (i < 2 ) ? desc->m_front : desc->m_rear ;
462+ const ObjectHandle & handle = (i & 1 ) ? axle.m_rightWheel : axle.m_leftWheel ;
463+
464+ IObject * obj = handle.getObject ();
465+ if (IGameObject * wheelGameobject = VG_SAFE_STATIC_CAST (IGameObject, obj))
466+ {
467+ float4x4 wheelMat = GetWheelMatrix (i);
468+ wheelGameobject->SetGlobalMatrix (wheelMat);
469+ }
470+ }
471+ }
472+ break ;
473+
474+ case VehicleType::Bike:
475+ {
476+ const BikeConstraintDesc * desc = VG_SAFE_STATIC_CAST (const BikeConstraintDesc, m_vehicleConstraintDesc);
477+
478+ const uint wheelCount = desc->GetWheelCount ();
479+
480+ for (uint i = 0 ; i < wheelCount; ++i)
481+ {
482+ const JPH ::Wheel * wheel = m_joltVehicleConstraint->GetWheel (i);
483+ const JPH ::WheelSettings * wheelSettings = wheel->GetSettings ();
484+
485+ const float radius = wheelSettings->mRadius ;
486+ const float width = wheelSettings->mWidth ;
487+
488+ // transform the wheel visual
489+ const OneWheeledAxleDesc & axle = (i == 0 ) ? desc->m_front : desc->m_rear ;
490+ const ObjectHandle & handle = axle.m_wheel ;
491+
492+ IObject * obj = handle.getObject ();
493+ if (IGameObject * wheelGameobject = VG_SAFE_STATIC_CAST (IGameObject, obj))
494+ {
495+ float4x4 wheelMat = GetWheelMatrix (i);
496+ wheelGameobject->SetGlobalMatrix (wheelMat);
497+ }
498+ }
499+ }
500+ break ;
501+ }
502+ }
503+ }
504+
505+ // --------------------------------------------------------------------------------------
506+ void VehicleConstraint::DrawDebug ()
437507 {
438508 // debug
439509 renderer::IDebugDraw * debugDraw = Physics::get ()->getDebugDraw ();
@@ -472,21 +542,10 @@ namespace vg::physics
472542 if (0 == (i & 1 ))
473543 {
474544 float3 leftWheelPos = wheelMatDebug[3 ].xyz ;
475- float3 rightWheelPos = fromJoltVec3 (m_joltVehicleConstraint->GetWheelWorldTransform (i+ 1 , JPH::Vec3::sAxisZ (), JPH::Vec3::sAxisY ()).GetTranslation ());
545+ float3 rightWheelPos = fromJoltVec3 (m_joltVehicleConstraint->GetWheelWorldTransform (i + 1 , JPH::Vec3::sAxisZ (), JPH::Vec3::sAxisY ()).GetTranslation ());
476546 debugDraw->AddLine (m_world, leftWheelPos, rightWheelPos, 0xFF0000FF );
477547 }
478548 }
479-
480- // transform the wheel visual
481- const TwoWheeledAxleDesc & axle = (i < 2 ) ? desc->m_front : desc->m_rear ;
482- const ObjectHandle & handle = (i & 1 ) ? axle.m_rightWheel : axle.m_leftWheel ;
483-
484- IObject * obj = handle.getObject ();
485- if (IGameObject * wheelGameobject = VG_SAFE_STATIC_CAST (IGameObject, obj))
486- {
487- float4x4 wheelMat = GetWheelMatrix (i);
488- wheelGameobject->SetGlobalMatrix (wheelMat);
489- }
490549 }
491550 }
492551 break ;
@@ -512,17 +571,6 @@ namespace vg::physics
512571 float4x4 wheelMatDebug = fromJoltMatrix (m_joltVehicleConstraint->GetWheelWorldTransform (i, JPH::Vec3::sAxisZ (), JPH::Vec3::sAxisY ()));
513572 debugDraw->AddWireframeCylinder (m_world, radius, width, 0xFF0000FF , wheelMatDebug);
514573 }
515-
516- // transform the wheel visual
517- const OneWheeledAxleDesc & axle = (i == 0 ) ? desc->m_front : desc->m_rear ;
518- const ObjectHandle & handle = axle.m_wheel ;
519-
520- IObject * obj = handle.getObject ();
521- if (IGameObject * wheelGameobject = VG_SAFE_STATIC_CAST (IGameObject, obj))
522- {
523- float4x4 wheelMat = GetWheelMatrix (i);
524- wheelGameobject->SetGlobalMatrix (wheelMat);
525- }
526574 }
527575 }
528576 break ;
0 commit comments