Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
VehicleController.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
10#ifdef JPH_DEBUG_RENDERER
12#endif // JPH_DEBUG_RENDERER
13
15
16class PhysicsSystem;
19class WheelSettings;
20class Wheel;
21class StateRecorder;
22
24class JPH_EXPORT VehicleControllerSettings : public SerializableObject, public RefTarget<VehicleControllerSettings>
25{
27
28public:
30 virtual void SaveBinaryState(StreamOut &inStream) const = 0;
31
33 virtual void RestoreBinaryState(StreamIn &inStream) = 0;
34
36 virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const = 0;
37};
38
40class JPH_EXPORT VehicleController : public RefTarget<VehicleController>, public NonCopyable
41{
42public:
44
46 explicit VehicleController(VehicleConstraint &inConstraint) : mConstraint(inConstraint) { }
47 virtual ~VehicleController() = default;
48
50 VehicleConstraint & GetConstraint() { return mConstraint; }
51 const VehicleConstraint & GetConstraint() const { return mConstraint; }
52
53protected:
54 // The functions below are only for the VehicleConstraint
55 friend class VehicleConstraint;
56
57 // Create a new instance of wheel
58 virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const = 0;
59
60 // If the vehicle is allowed to go to sleep
61 virtual bool AllowSleep() const = 0;
62
63 // Called before the wheel probes have been done
64 virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
65
66 // Called after the wheel probes have been done
67 virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) = 0;
68
69 // Solve longitudinal and lateral constraint parts for all of the wheels
70 virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) = 0;
71
72 // Saving state for replay
73 virtual void SaveState(StateRecorder &inStream) const = 0;
74 virtual void RestoreState(StateRecorder &inStream) = 0;
75
76#ifdef JPH_DEBUG_RENDERER
77 // Drawing interface
78 virtual void Draw(DebugRenderer *inRenderer) const = 0;
79#endif // JPH_DEBUG_RENDERER
80
82};
83
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
#define JPH_DECLARE_SERIALIZABLE_ABSTRACT(linkage, class_name)
Definition SerializableObject.h:120
Definition DebugRenderer.h:47
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition PhysicsSystem.h:29
Definition Reference.h:35
Definition SerializableObject.h:156
Definition StateRecorder.h:105
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition VehicleConstraint.h:66
Runtime data for interface that controls acceleration / deceleration of the vehicle.
Definition VehicleController.h:41
virtual bool AllowSleep() const =0
virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)=0
virtual void Draw(DebugRenderer *inRenderer) const =0
virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem)=0
const VehicleConstraint & GetConstraint() const
Definition VehicleController.h:51
virtual void RestoreState(StateRecorder &inStream)=0
virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const =0
VehicleConstraint & GetConstraint()
Access the vehicle constraint that this controller is part of.
Definition VehicleController.h:50
virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime)=0
JPH_OVERRIDE_NEW_DELETE VehicleController(VehicleConstraint &inConstraint)
Constructor / destructor.
Definition VehicleController.h:46
virtual ~VehicleController()=default
virtual void SaveState(StateRecorder &inStream) const =0
VehicleConstraint & mConstraint
The vehicle constraint we belong to.
Definition VehicleController.h:81
Basic settings object for interface that controls acceleration / deceleration of the vehicle.
Definition VehicleController.h:25
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const =0
Create an instance of the vehicle controller class.
virtual void RestoreBinaryState(StreamIn &inStream)=0
Restore the contents of the controller settings in binary form from inStream.
virtual void SaveBinaryState(StreamOut &inStream) const =0
Saves the contents of the controller settings in binary form to inStream.
Base class for runtime data for a wheel, each VehicleController can implement a derived class of this...
Definition Wheel.h:46
Base class for wheel settings, each VehicleController can implement a derived class of this.
Definition Wheel.h:19