17#include <fmt/format.h>
19#include <glm/gtc/quaternion.hpp>
41 static_assert(N == 4,
"VehicleBuilder currently only supports 4-wheel vehicles (N=4). "
42 "Support for other wheel counts may be added in future versions.");
59 const glm::vec3 &position = glm::vec3(0.0f),
60 const glm::quat &rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f),
61 const glm::vec3 &scale = glm::vec3(1.0f))
92 _vehicle.wheels[
static_cast<size_t>(index)] = settings;
104 _vehicle.wheels[
static_cast<size_t>(index)].maxBrakeTorque = torque;
118 _vehicle.wheels[
static_cast<size_t>(index)].maxHandBrakeTorque = torque;
172 const glm::vec3 &rearLeft,
const glm::vec3 &rearRight)
203 for (
size_t i = 0; i < 4; ++i)
211 if (
_vehicle.gearbox.forwardGearRatios.empty())
221 std::array<Engine::EntityId, 4> wheelEntities;
222 for (
size_t i = 0; i < 4; ++i)
227 glm::quat wheelRotation =
228 _chassisRotation * glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f));
236 chassisRigidBody.friction = 0.5f;
237 chassisRigidBody.restitution = 0.1f;
241 _vehicle.wheelEntities = wheelEntities;
265 _vehicle.collisionTesterType = type;
276 if (fraction < 0.0f || fraction > 1.0f)
280 _vehicle.convexRadiusFraction = fraction;
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
Entity CreateEntity()
Create an entity in the context of the registry.
Definition Core.cpp:44
Wrapper class providing a convenient interface for entity manipulation with the Core....
Definition Entity.hpp:20
decltype(auto) AddComponent(TComponent &&component)
Add a component to an entity.
Definition Entity.hpp:55
VehicleBuilder & SetRollbar(const Component::RollbarSettings &rollbar)
Set rollbar configuration.
Definition VehicleBuilder.hpp:152
VehicleBuilder & SetGearbox(const Component::GearboxSettings &gearbox)
Set gearbox configuration.
Definition VehicleBuilder.hpp:143
VehicleBuilder & 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))
Set the chassis mesh and initial transform.
Definition VehicleBuilder.hpp:58
VehicleBuilder & SetMaxHandBrakeTorque(Component::WheelIndex index, float torque)
Set maximum handbrake torque for a specific wheel.
Definition VehicleBuilder.hpp:116
bool _hasChassisSet
Definition VehicleBuilder.hpp:296
glm::quat _chassisRotation
Definition VehicleBuilder.hpp:289
VehicleBuilder & SetEngine(const Component::EngineSettings &engine)
Set engine configuration.
Definition VehicleBuilder.hpp:134
VehicleBuilder & SetWheelMesh(Component::WheelIndex index, const Object::Component::Mesh &wheelMesh)
Set mesh for a specific wheel.
Definition VehicleBuilder.hpp:77
Engine::Entity Build(Engine::Core &core)
Build the vehicle and create all entities.
Definition VehicleBuilder.hpp:196
VehicleBuilder & SetWheelPositions(const glm::vec3 &frontLeft, const glm::vec3 &frontRight, const glm::vec3 &rearLeft, const glm::vec3 &rearRight)
Set wheel offset positions relative to chassis center.
Definition VehicleBuilder.hpp:171
Component::Vehicle _vehicle
Definition VehicleBuilder.hpp:285
VehicleBuilder & SetMaxBrakeTorque(Component::WheelIndex index, float torque)
Set maximum brake torque for a specific wheel.
Definition VehicleBuilder.hpp:102
VehicleBuilder & SetChassisMass(float mass)
Set chassis mass in kilograms.
Definition VehicleBuilder.hpp:254
VehicleBuilder & SetCollisionTesterType(Component::CollisionTesterType type)
Set the collision tester type for wheel-ground detection.
Definition VehicleBuilder.hpp:263
std::array< Object::Component::Mesh, 4 > _wheelMeshes
Definition VehicleBuilder.hpp:293
std::array< bool, 4 > _hasWheelMesh
Definition VehicleBuilder.hpp:297
std::array< glm::vec3, 4 > _wheelPositions
Definition VehicleBuilder.hpp:294
VehicleBuilder & SetConvexRadiusFraction(float fraction)
Set the convex radius fraction for CastCylinder tester.
Definition VehicleBuilder.hpp:274
VehicleBuilder & SetWheelSettings(Component::WheelIndex index, const Component::WheelSettings &settings)
Set wheel settings for a specific wheel.
Definition VehicleBuilder.hpp:90
float _chassisMass
Definition VehicleBuilder.hpp:291
VehicleBuilder & SetDrivetrain(Component::DrivetrainType drivetrain)
Set drivetrain type (AWD, FWD, RWD).
Definition VehicleBuilder.hpp:125
glm::vec3 _chassisPosition
Definition VehicleBuilder.hpp:288
glm::vec3 _chassisScale
Definition VehicleBuilder.hpp:290
Object::Component::Mesh _chassisMesh
Definition VehicleBuilder.hpp:287
Builder for creating vehicles with N wheels.
Definition VehicleBuilder.hpp:40
Definition VehicleBuilderError.hpp:7
Definition VehicleBuilder.hpp:22
WheelIndex
Enum for identifying wheel positions in a 4-wheel vehicle.
Definition WheelSettings.hpp:11
DrivetrainType
Drivetrain configuration for vehicle.
Definition Vehicle.hpp:15
CollisionTesterType
Collision tester type for vehicle wheel collision detection.
Definition Vehicle.hpp:31
Mesh structure.
Definition Mesh.hpp:40
Convex hull mesh collider.
Definition ConvexHullMeshCollider.hpp:48
Engine configuration.
Definition Vehicle.hpp:107
Gearbox configuration for vehicle transmission.
Definition Vehicle.hpp:65
Definition RigidBody.hpp:64
static RigidBody CreateDynamic(float bodyMass=1.0f)
Create a dynamic rigid body.
Definition RigidBody.hpp:150
Rollbar (anti-roll bar) configuration.
Definition Vehicle.hpp:138
Vehicle input controller component.
Definition VehicleController.hpp:14
Main vehicle component containing all configuration.
Definition Vehicle.hpp:152
static std::array< glm::vec3, 4 > GetDefaultWheelPositions()
Get default wheel positions relative to chassis center.
Definition Vehicle.hpp:191
static Vehicle CreateDefaultCar()
Create a default RWD sports car configuration.
Definition Vehicle.hpp:204
Settings for an individual wheel in a vehicle.
Definition WheelSettings.hpp:37