class Physics

Inherits: Module<Physics>

Provides global physics settings, factory methods for physics objects and scene queries.

Public

Constructors

Physics

Physics(const PhysicsCreateInformation &init)

Methods

~Physics

virtual ~Physics() noexcept = default

ToggleCollision

void ToggleCollision(u64 groupA, u64 groupB, bool enabled)

Enables or disables collision between two layers.

Each physics object can be assigned a specific layer, and here you can determine which layers can interact with each other.

IsCollisionEnabled

bool IsCollisionEnabled(u64 groupA, u64 groupB) const

Checks if two collision layers are allowed to interact.

staticInstance

static T &Instance()

Returns a reference to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticInstancePtr

static T *InstancePtr()

Returns a pointer to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticShutDown

static void ShutDown()

Shuts down this module and frees any resources it is using.

staticIsStarted

static bool IsStarted()

Query if the module has been started.

Internal

Methods

CreateMaterial

virtual SPtr<PhysicsMaterial> CreateMaterial(float staticFriction, float dynamicFriction, float restitution) = 0

Creates a new physics material.

staticFriction
Controls friction when two in-contact objects are not moving lateral to each other (for example how difficult is to get an object moving from a static state while it is in contact other object(s)).
dynamicFriction
Sets dynamic friction of the material. Controls friction when two in-contact objects are moving lateral to each other (for example how quickly does an object slow down when sliding along another object).
restitution
Controls "bounciness" of an object during a collision. Value of 1 means the collision is elastic, and value of 0 means the value is inelastic. Must be in [0, 1] range.

CreateMesh

virtual UPtr<IPhysicsMeshImplementation> CreateMesh(const SPtr<MeshData> &meshData, PhysicsMeshType type) = 0

Creates a physics mesh implementation.

CreatePhysicsScene

virtual SPtr<PhysicsScene> CreatePhysicsScene() = 0

Creates an object representing the physics scene.

Must be manually released via destroyPhysicsScene().

CreateColliderShape

virtual SPtr<ColliderShape> CreateColliderShape() = 0

Creates a new empty collider shape.

Note you must set the shape information after creation.

CreateColliderImplementation

virtual UPtr<IColliderImplementation> CreateColliderImplementation() = 0

Creates an object that provides low-level functionality required for a Collider.

CreateRigidbodyImplementation

virtual UPtr<IRigidbodyImplementation> CreateRigidbodyImplementation(Rigidbody &owner) = 0

Creates an object that provides low-level functionality required for a Rigidbody.

RayCast

virtual bool RayCast(const Vector3 &origin, const Vector3 &unitDirection, const ColliderShape &colliderShape, PhysicsQueryHit &hit, float maximumDistance = 3.40282347E+38F) const = 0

Checks does the ray hit the provided collider shape.

origin
Origin of the ray to check.
unitDirection
Unit direction of the ray to check.
colliderShape
Collider shape to check for hit.
hit
Information about the hit. Valid only if the method returns true.
maximumDistance
Maximum distance from the ray origin to search for hits.

Returns: True if the ray has hit the collider.

RayCast

virtual bool RayCast(const Vector3 &origin, const Vector3 &unitDirection, const Collider &collider, PhysicsQueryHit &hit, float maximumDistance = 3.40282347E+38F) const = 0

Checks does the ray hit any of the shapes on the provided collider.

origin
Origin of the ray to check.
unitDirection
Unit direction of the ray to check.
collider
Collider to check for hit.
hit
Information about the hit. Valid only if the method returns true.
maximumDistance
Maximum distance from the ray origin to search for hits.

Returns: True if the ray has hit the collider.

Protected

Methods

~Module<T>

virtual ~Module<T>() = default

OnStartUp

virtual void OnStartUp()

Override if you want your module to be notified once it has been constructed and started.

OnShutDown

virtual void OnShutDown()

Override if you want your module to be notified just before it is deleted.

staticInstanceInternal

static T *&InstanceInternal()

Returns a singleton instance of this module.

staticIsDestroyed

static bool &IsDestroyed()

Checks has the Module been shut down.

staticIsStartedUp

static bool &IsStartedUp()

Checks has the Module been started up.

Fields

mMutex

Mutex mMutex

mCollisionMap

bool[64][64] mCollisionMap