Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Vehicle/VehicleController.h
9912 views
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
7
#include <Jolt/ObjectStream/SerializableObject.h>
8
#include <Jolt/Core/StreamIn.h>
9
#include <Jolt/Core/StreamOut.h>
10
#ifdef JPH_DEBUG_RENDERER
11
#include <Jolt/Renderer/DebugRenderer.h>
12
#endif // JPH_DEBUG_RENDERER
13
14
JPH_NAMESPACE_BEGIN
15
16
class PhysicsSystem;
17
class VehicleController;
18
class VehicleConstraint;
19
class WheelSettings;
20
class Wheel;
21
class StateRecorder;
22
23
/// Basic settings object for interface that controls acceleration / deceleration of the vehicle
24
class JPH_EXPORT VehicleControllerSettings : public SerializableObject, public RefTarget<VehicleControllerSettings>
25
{
26
JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, VehicleControllerSettings)
27
28
public:
29
/// Saves the contents of the controller settings in binary form to inStream.
30
virtual void SaveBinaryState(StreamOut &inStream) const = 0;
31
32
/// Restore the contents of the controller settings in binary form from inStream.
33
virtual void RestoreBinaryState(StreamIn &inStream) = 0;
34
35
/// Create an instance of the vehicle controller class
36
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const = 0;
37
};
38
39
/// Runtime data for interface that controls acceleration / deceleration of the vehicle
40
class JPH_EXPORT VehicleController : public NonCopyable
41
{
42
public:
43
JPH_OVERRIDE_NEW_DELETE
44
45
/// Constructor / destructor
46
explicit VehicleController(VehicleConstraint &inConstraint) : mConstraint(inConstraint) { }
47
virtual ~VehicleController() = default;
48
49
/// Access the vehicle constraint that this controller is part of
50
VehicleConstraint & GetConstraint() { return mConstraint; }
51
const VehicleConstraint & GetConstraint() const { return mConstraint; }
52
53
protected:
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
81
VehicleConstraint & mConstraint; ///< The vehicle constraint we belong to
82
};
83
84
JPH_NAMESPACE_END
85
86