Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
Physics::Builder::VehicleBuilder< 4 > Class Reference

Specialized builder for 4-wheel vehicles. More...

#include <VehicleBuilder.hpp>

Public Member Functions

VehicleBuilderSetChassisMesh (const Object::Component::Mesh &chassisMesh, const glm::vec3 &position=glm::vec3(0.0f), const glm::quat &rotation=glm::quat(1.0f, 0.0f, 0.0f, 0.0f), const glm::vec3 &scale=glm::vec3(1.0f))
 Set the chassis mesh and initial transform.
VehicleBuilderSetWheelMesh (Component::WheelIndex index, const Object::Component::Mesh &wheelMesh)
 Set mesh for a specific wheel.
VehicleBuilderSetWheelSettings (Component::WheelIndex index, const Component::WheelSettings &settings)
 Set wheel settings for a specific wheel.
VehicleBuilderSetMaxBrakeTorque (Component::WheelIndex index, float torque)
 Set maximum brake torque for a specific wheel.
VehicleBuilderSetMaxHandBrakeTorque (Component::WheelIndex index, float torque)
 Set maximum handbrake torque for a specific wheel.
VehicleBuilderSetDrivetrain (Component::DrivetrainType drivetrain)
 Set drivetrain type (AWD, FWD, RWD).
VehicleBuilderSetEngine (const Component::EngineSettings &engine)
 Set engine configuration.
VehicleBuilderSetGearbox (const Component::GearboxSettings &gearbox)
 Set gearbox configuration.
VehicleBuilderSetRollbar (const Component::RollbarSettings &rollbar)
 Set rollbar configuration.
VehicleBuilderSetWheelPositions (const glm::vec3 &frontLeft, const glm::vec3 &frontRight, const glm::vec3 &rearLeft, const glm::vec3 &rearRight)
 Set wheel offset positions relative to chassis center.
Engine::Entity Build (Engine::Core &core)
 Build the vehicle and create all entities.
VehicleBuilderSetChassisMass (float mass)
 Set chassis mass in kilograms.
VehicleBuilderSetCollisionTesterType (Component::CollisionTesterType type)
 Set the collision tester type for wheel-ground detection.
VehicleBuilderSetConvexRadiusFraction (float fraction)
 Set the convex radius fraction for CastCylinder tester.

Private Attributes

Component::Vehicle _vehicle = Component::Vehicle::CreateDefaultCar()
Object::Component::Mesh _chassisMesh
glm::vec3 _chassisPosition = glm::vec3(0.0f)
glm::quat _chassisRotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f)
glm::vec3 _chassisScale = glm::vec3(1.0f)
float _chassisMass = 1500.0f
std::array< Object::Component::Mesh, 4 > _wheelMeshes
std::array< glm::vec3, 4 > _wheelPositions = Component::Vehicle::GetDefaultWheelPositions()
bool _hasChassisSet = false
std::array< bool, 4 > _hasWheelMesh = {false, false, false, false}

Detailed Description

Specialized builder for 4-wheel vehicles.

Member Function Documentation

◆ Build()

Build the vehicle and create all entities.

Creates:

  • 1 chassis entity with Vehicle, VehicleController, and Mesh components
  • 4 wheel entities with Mesh and Transform components

The VehicleSystem will automatically create the Jolt constraint when the Vehicle component is constructed.

Parameters
coreEngine core reference
Returns
The chassis entity

◆ SetChassisMass()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetChassisMass ( float mass)
inline

Set chassis mass in kilograms.

◆ SetChassisMesh()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetChassisMesh ( const Object::Component::Mesh & chassisMesh,
const glm::vec3 & position = glm::vec3(0.0f),
const glm::quat & rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f),
const glm::vec3 & scale = glm::vec3(1.0f) )
inline

Set the chassis mesh and initial transform.

Parameters
chassisMeshMesh for the vehicle body
positionInitial position of the chassis
rotationInitial rotation of the chassis
scaleScale of the chassis mesh

◆ SetCollisionTesterType()

Set the collision tester type for wheel-ground detection.

◆ SetConvexRadiusFraction()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetConvexRadiusFraction ( float fraction)
inline

Set the convex radius fraction for CastCylinder tester.

Parameters
fractionValue between 0.0 and 1.0 (default: 0.5)

◆ SetDrivetrain()

Set drivetrain type (AWD, FWD, RWD).

◆ SetEngine()

Set engine configuration.

◆ SetGearbox()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetGearbox ( const Component::GearboxSettings & gearbox)
inline

Set gearbox configuration.

◆ SetMaxBrakeTorque()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetMaxBrakeTorque ( Component::WheelIndex index,
float torque )
inline

Set maximum brake torque for a specific wheel.

Parameters
indexWheel position
torqueMaximum brake torque in Nm (default: 1500.0f)

◆ SetMaxHandBrakeTorque()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetMaxHandBrakeTorque ( Component::WheelIndex index,
float torque )
inline

Set maximum handbrake torque for a specific wheel.

Usually only applied to rear wheels.

Parameters
indexWheel position
torqueMaximum handbrake torque in Nm (default: 4000.0f)

◆ SetRollbar()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetRollbar ( const Component::RollbarSettings & rollbar)
inline

Set rollbar configuration.

◆ SetWheelMesh()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetWheelMesh ( Component::WheelIndex index,
const Object::Component::Mesh & wheelMesh )
inline

Set mesh for a specific wheel.

Parameters
indexWheel position (FrontLeft, FrontRight, RearLeft, RearRight)
wheelMeshMesh for the wheel visual

◆ SetWheelPositions()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetWheelPositions ( const glm::vec3 & frontLeft,
const glm::vec3 & frontRight,
const glm::vec3 & rearLeft,
const glm::vec3 & rearRight )
inline

Set wheel offset positions relative to chassis center.

Default positions assume a standard car layout:

  • Front wheels: ±1.0 X, +1.5 Z
  • Rear wheels: ±1.0 X, -1.5 Z
  • All wheels: -0.3 Y (below chassis center)
Parameters
frontLeftPosition of front-left wheel
frontRightPosition of front-right wheel
rearLeftPosition of rear-left wheel
rearRightPosition of rear-right wheel

◆ SetWheelSettings()

VehicleBuilder & Physics::Builder::VehicleBuilder< 4 >::SetWheelSettings ( Component::WheelIndex index,
const Component::WheelSettings & settings )
inline

Set wheel settings for a specific wheel.

Parameters
indexWheel position
settingsWheel physical properties

Member Data Documentation

◆ _chassisMass

float Physics::Builder::VehicleBuilder< 4 >::_chassisMass = 1500.0f
private

◆ _chassisMesh

◆ _chassisPosition

glm::vec3 Physics::Builder::VehicleBuilder< 4 >::_chassisPosition = glm::vec3(0.0f)
private

◆ _chassisRotation

glm::quat Physics::Builder::VehicleBuilder< 4 >::_chassisRotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f)
private

◆ _chassisScale

glm::vec3 Physics::Builder::VehicleBuilder< 4 >::_chassisScale = glm::vec3(1.0f)
private

◆ _hasChassisSet

bool Physics::Builder::VehicleBuilder< 4 >::_hasChassisSet = false
private

◆ _hasWheelMesh

std::array<bool, 4> Physics::Builder::VehicleBuilder< 4 >::_hasWheelMesh = {false, false, false, false}
private

◆ _vehicle

◆ _wheelMeshes

std::array<Object::Component::Mesh, 4> Physics::Builder::VehicleBuilder< 4 >::_wheelMeshes
private

◆ _wheelPositions

std::array<glm::vec3, 4> Physics::Builder::VehicleBuilder< 4 >::_wheelPositions = Component::Vehicle::GetDefaultWheelPositions()
private

The documentation for this class was generated from the following file: