coastline 0.0.4
Loading...
Searching...
No Matches
rigidbody.h File Reference

The rigid bodies of the physics: their state, forces and inertia, and the quaternion and 3 by 3 matrix arithmetic they use. More...

#include "common/types.h"
#include "common/vecmath.h"
Include dependency graph for rigidbody.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Quaternion
 A rotation as a unit quaternion. More...
struct  RigidBodyState
 The motion of a rigid body at an instant. More...
struct  RigidBodyForce
 A force on a rigid body, in a list. More...
struct  RigidBody
 A rigid body: the body of a vehicle or of one of its wheels. More...

Typedefs

typedef struct RigidBodyForce RigidBodyForce
 A force on a rigid body, in a list.
typedef struct RigidBody RigidBody
 A rigid body: the body of a vehicle or of one of its wheels.

Enumerations

enum  { RIGID_BODY_FORCE_WORLD , RIGID_BODY_FORCE_BODY }
 The frames a force can be given in. More...
enum  { RIGID_BODY_BOX , RIGID_BODY_BOX_1 , RIGID_BODY_NO_ROTATION }
 The kinds of rigid body. More...

Functions

void StubPhysics1 (void *data)
 An empty hook the inertia setup calls.
void MatrixToQuaternion (f32 m[4][4], Quaternion *q)
 The unit quaternion of the rotation of a matrix, from the largest of its diagonal terms.
void StubPhysics2 (void *data)
 An empty hook QuaternionToMatrix() calls.
void QuaternionMultiply (Quaternion *out, Quaternion *a, Quaternion *b)
 The product of two quaternions.
void QuaternionNormalize (Quaternion *q)
 Make a quaternion a unit quaternion.
void Vec3fNormalizeFast (Vec3f *v)
 Make a vector a unit vector.
void ComputeDeltaQuaternion (RigidBodyState *state)
 The rate of change of the orientation from the angular velocity: half of the product of the angular velocity and the orientation.
void ApplyRigidBodyImpulse (RigidBodyState *state, RigidBody *body, f32 dt)
 Add the force and torque of a body over a time to the velocity and angular velocity of a state.
void QuaternionToMatrix (f32 out[4][4], RigidBodyState *state)
 The 4 by 4 matrix of the orientation and position of a state.
void IntegrateRigidBodyState (RigidBodyState *out, RigidBodyState *in, f32 dt)
 Advance a state by a time, keeping its velocities.
void SetRigidBodyForce (RigidBodyForce *force, f32 x, f32 y, f32 z, f32 pointX, f32 pointY, f32 pointZ, s32 frame)
 Set the vector, the point, and the frame of a force.
void Mtx4fInverseRotate (Vec3f *out, f32 m[4][4], Vec3f *v)
 The dot products of the rotation rows of a matrix with a vector, which turns a vector of the world into the frame of the matrix.
void Mtx3x3MulVec3f (Vec3f *out, f32 m[4][4], Vec3f *v)
 A vector times the rotation of a matrix, which turns a vector of the frame into the world.
void Mtx4x4TransformPoint (Vec3f *out, f32 m[4][4], Vec3f *v)
 A point times a matrix, with its translation.
void Mtx3fMulVec3f (Vec3f *out, f32 m[3][3], Vec3f *v)
 A 3 by 3 matrix times a column vector.
void ComputeRigidBodyAcceleration (RigidBody *body)
 Turn the summed force and torque of a body into its accelerations.
void ApplySingleForceWithDebug (RigidBody *body, RigidBodyForce *force)
 Add a force and its torque to the sums of a body, and print both on the debug output.
void ApplyAllForcesToBody (RigidBody *body)
 Add each force of the list of a body to its sums of force and torque, printing each on the debug output.
void InitRigidBody (RigidBody *body)
 Reset a body, and set the inertia of a box from its size and mass.
void BuildSkewSymmetricMatrix (f32 out[3][3], Vec3f *v)
 The matrix of the cross product with a vector.
void TransposeCopyMatrix3x3 (f32 transpose[3][3], f32 copy[3][3], f32 m[4][4])
 Copy the rotation of a matrix, and its transpose.
void Transpose4x4Into3x3 (f32 out[3][3], f32 m[4][4])
 The transpose of the rotation of a matrix.
void CopyMatrix4x4To3x3 (f32 out[3][3], f32 m[4][4])
 Copy the rotation of a matrix.
void Mtx3fMultiply (f32 out[3][3], f32 a[3][3], f32 b[3][3])
 The product of two 3 by 3 matrices.
void SubtractMatrix3x3 (f32 out[3][3], f32 a[3][3], f32 b[3][3])
 The difference of two 3 by 3 matrices.
void MtxBuildScaledInverse (f32 m[4][4], f32 out[4][4], Vec3f *scale)
 The inverse of a rigid transform whose axes are scaled.
void SolveLinearSystem3x3 (Vec3f *out, f32 a[3][3], Vec3f *b)
 Solve a system of three linear equations by Cramer's rule.

Detailed Description

The rigid bodies of the physics: their state, forces and inertia, and the quaternion and 3 by 3 matrix arithmetic they use.

A 3 by 3 matrix is packed in nine words; the rotation part of a 4 by 4 matrix is its first three rows.

Typedef Documentation

◆ RigidBodyForce

typedef struct RigidBodyForce RigidBodyForce

A force on a rigid body, in a list.

◆ RigidBody

typedef struct RigidBody RigidBody

A rigid body: the body of a vehicle or of one of its wheels.

A wheel uses the ground, steering, spin and suspension fields, the body of a vehicle the springs, box and collision fields.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

The frames a force can be given in.

Enumerator
RIGID_BODY_FORCE_WORLD 

The vector of the force is in world axes.

RIGID_BODY_FORCE_BODY 

The vector of the force is in the axes of the body.

◆ anonymous enum

anonymous enum

The kinds of rigid body.

A box may turn; a body of the last kind does not.

Enumerator
RIGID_BODY_BOX 

A box that turns, with the inertia of its sides.

RIGID_BODY_BOX_1 

A box like the first kind, used for the body of a vehicle.

RIGID_BODY_NO_ROTATION 

A body that does not turn, used for a wheel.

Function Documentation

◆ StubPhysics1()

void StubPhysics1 ( void * data)

An empty hook the inertia setup calls.

Parameters
dataThe inertia of the body, ignored.
Ghidra address:
USA: 0x80258070
Ghidra address:
Asia: 0x80257BC0
Ghidra address:
EUR: 0x80259640
Ghidra address:
JPN: 0x80258fd0

◆ MatrixToQuaternion()

void MatrixToQuaternion ( f32 m[4][4],
Quaternion * q )

The unit quaternion of the rotation of a matrix, from the largest of its diagonal terms.

Parameters
mThe matrix.
qReceives the quaternion.
Ghidra address:
USA: 0x8021ff90
Ghidra address:
Asia: 0x8021FAE0
Ghidra address:
EUR: 0x80221290
Ghidra address:
JPN: 0x80220a80
Ghidra address:
BRD3D: 0x100765e0
Ghidra address:
BRGlide: 0x1006f840

◆ StubPhysics2()

void StubPhysics2 ( void * data)

An empty hook QuaternionToMatrix() calls.

Parameters
dataThe matrix just built, ignored.
Ghidra address:
USA: 0x80258078
Ghidra address:
Asia: 0x80257BC8
Ghidra address:
EUR: 0x80259648
Ghidra address:
JPN: 0x80258fd8
Ghidra address:
BRD3D: 0x10008b80
Ghidra address:
BRGlide: 0x10008d60

◆ QuaternionMultiply()

void QuaternionMultiply ( Quaternion * out,
Quaternion * a,
Quaternion * b )

The product of two quaternions.

Parameters
outReceives a times b, and may be either factor.
aThe left factor.
bThe right factor.
Ghidra address:
USA: 0x80258080
Ghidra address:
Asia: 0x80257BD0
Ghidra address:
EUR: 0x80259650
Ghidra address:
JPN: 0x80258fe0
Ghidra address:
BRD3D: 0x10074090
Ghidra address:
BRGlide: 0x1006d2e0

◆ QuaternionNormalize()

void QuaternionNormalize ( Quaternion * q)

Make a quaternion a unit quaternion.

Parameters
qThe quaternion, normalised in place.
Ghidra address:
USA: 0x8025813c
Ghidra address:
Asia: 0x80257C8C
Ghidra address:
EUR: 0x8025970c
Ghidra address:
JPN: 0x8025909c
Ghidra address:
BRD3D: 0x100741b0
Ghidra address:
BRGlide: 0x1006d410

◆ Vec3fNormalizeFast()

void Vec3fNormalizeFast ( Vec3f * v)

Make a vector a unit vector.

Parameters
vThe non-zero vector, normalised in place.
Ghidra address:
USA: 0x802581cc
Ghidra address:
Asia: 0x80257D1C
Ghidra address:
EUR: 0x8025979c
Ghidra address:
JPN: 0x8025912c
Ghidra address:
BRD3D: 0x10074250
Ghidra address:
BRGlide: 0x1006d4b0

◆ ComputeDeltaQuaternion()

void ComputeDeltaQuaternion ( RigidBodyState * state)

The rate of change of the orientation from the angular velocity: half of the product of the angular velocity and the orientation.

Parameters
stateThe state whose spin is set.
Ghidra address:
USA: 0x80258248
Ghidra address:
Asia: 0x80257D98
Ghidra address:
EUR: 0x80259818
Ghidra address:
JPN: 0x802591a8
Ghidra address:
BRD3D: 0x100742d0
Ghidra address:
BRGlide: 0x1006d530

◆ ApplyRigidBodyImpulse()

void ApplyRigidBodyImpulse ( RigidBodyState * state,
RigidBody * body,
f32 dt )

Add the force and torque of a body over a time to the velocity and angular velocity of a state.

Parameters
stateThe state to change.
bodyThe body whose force and torque are added.
dtThe time over which they act.
Ghidra address:
USA: 0x80258324
Ghidra address:
Asia: 0x80257E74
Ghidra address:
EUR: 0x802598f4
Ghidra address:
JPN: 0x80259284
Ghidra address:
BRD3D: 0x100743a0
Ghidra address:
BRGlide: 0x1006d600

◆ QuaternionToMatrix()

void QuaternionToMatrix ( f32 out[4][4],
RigidBodyState * state )

The 4 by 4 matrix of the orientation and position of a state.

Parameters
outReceives the matrix.
stateThe state.
Ghidra address:
USA: 0x802583dc
Ghidra address:
Asia: 0x80257F2C
Ghidra address:
EUR: 0x802599ac
Ghidra address:
JPN: 0x8025933c
Ghidra address:
BRD3D: 0x10074450
Ghidra address:
BRGlide: 0x1006d6b0

◆ IntegrateRigidBodyState()

void IntegrateRigidBodyState ( RigidBodyState * out,
RigidBodyState * in,
f32 dt )

Advance a state by a time, keeping its velocities.

Parameters
outReceives the advanced state.
inThe state to advance.
dtThe time to advance by.
Ghidra address:
USA: 0x80258530
Ghidra address:
Asia: 0x80258080
Ghidra address:
EUR: 0x80259b00
Ghidra address:
JPN: 0x80259490
Ghidra address:
BRD3D: 0x100745f0
Ghidra address:
BRGlide: 0x1006d850

◆ SetRigidBodyForce()

void SetRigidBodyForce ( RigidBodyForce * force,
f32 x,
f32 y,
f32 z,
f32 pointX,
f32 pointY,
f32 pointZ,
s32 frame )

Set the vector, the point, and the frame of a force.

Parameters
forceThe force to set.
xThe x of the vector.
yThe y of the vector.
zThe z of the vector.
pointXThe x of the point the force acts at, in the frame of the body.
pointYThe y of the point.
pointZThe z of the point.
frameThe frame of the vector, RIGID_BODY_FORCE_WORLD or RIGID_BODY_FORCE_BODY.
Ghidra address:
USA: 0x80258680
Ghidra address:
Asia: 0x802581D0
Ghidra address:
EUR: 0x80259c50
Ghidra address:
JPN: 0x802595e0
Ghidra address:
BRD3D: 0x100746e0
Ghidra address:
BRGlide: 0x1006d940

◆ Mtx4fInverseRotate()

void Mtx4fInverseRotate ( Vec3f * out,
f32 m[4][4],
Vec3f * v )

The dot products of the rotation rows of a matrix with a vector, which turns a vector of the world into the frame of the matrix.

Parameters
outReceives the vector in the frame of the matrix.
mThe matrix.
vThe vector in the world.
Ghidra address:
USA: 0x802586c0
Ghidra address:
Asia: 0x80258210
Ghidra address:
EUR: 0x80259c90
Ghidra address:
JPN: 0x80259620
Ghidra address:
BRD3D: 0x10074720
Ghidra address:
BRGlide: 0x1006d980

◆ Mtx3x3MulVec3f()

void Mtx3x3MulVec3f ( Vec3f * out,
f32 m[4][4],
Vec3f * v )

A vector times the rotation of a matrix, which turns a vector of the frame into the world.

Parameters
outReceives the vector in the world.
mThe matrix.
vThe vector in the frame of the matrix.
Ghidra address:
USA: 0x80258758
Ghidra address:
Asia: 0x802582A8
Ghidra address:
EUR: 0x80259d28
Ghidra address:
JPN: 0x802596b8
Ghidra address:
BRD3D: 0x10074770
Ghidra address:
BRGlide: 0x1006d9d0

◆ Mtx4x4TransformPoint()

void Mtx4x4TransformPoint ( Vec3f * out,
f32 m[4][4],
Vec3f * v )

A point times a matrix, with its translation.

Parameters
outReceives the transformed point.
mThe matrix.
vThe point.
Ghidra address:
USA: 0x802587e8
Ghidra address:
Asia: 0x80258338
Ghidra address:
EUR: 0x80259db8
Ghidra address:
JPN: 0x80259748
Ghidra address:
BRD3D: 0x100747c0
Ghidra address:
BRGlide: 0x1006da20

◆ Mtx3fMulVec3f()

void Mtx3fMulVec3f ( Vec3f * out,
f32 m[3][3],
Vec3f * v )

A 3 by 3 matrix times a column vector.

Parameters
outReceives the product.
mThe matrix.
vThe vector.
Ghidra address:
USA: 0x802588b8
Ghidra address:
Asia: 0x80258408
Ghidra address:
EUR: 0x80259e88
Ghidra address:
JPN: 0x80259818
Ghidra address:
BRD3D: 0x10074830
Ghidra address:
BRGlide: 0x1006da90

◆ ComputeRigidBodyAcceleration()

void ComputeRigidBodyAcceleration ( RigidBody * body)

Turn the summed force and torque of a body into its accelerations.

Parameters
bodyThe body whose sums become its accelerations.
Ghidra address:
USA: 0x80258950
Ghidra address:
Asia: 0x802584A0
Ghidra address:
EUR: 0x80259f20
Ghidra address:
JPN: 0x802598b0

◆ ApplySingleForceWithDebug()

void ApplySingleForceWithDebug ( RigidBody * body,
RigidBodyForce * force )

Add a force and its torque to the sums of a body, and print both on the debug output.

Parameters
bodyThe body.
forceThe force to add.
Ghidra address:
USA: 0x802589f4
Ghidra address:
Asia: 0x80258544
Ghidra address:
EUR: 0x80259fc4
Ghidra address:
JPN: 0x80259954

◆ ApplyAllForcesToBody()

void ApplyAllForcesToBody ( RigidBody * body)

Add each force of the list of a body to its sums of force and torque, printing each on the debug output.

Parameters
bodyThe body.
Ghidra address:
USA: 0x80258bdc
Ghidra address:
Asia: 0x8025872C
Ghidra address:
EUR: 0x8025a1ac
Ghidra address:
JPN: 0x80259b3c

◆ InitRigidBody()

void InitRigidBody ( RigidBody * body)

Reset a body, and set the inertia of a box from its size and mass.

Parameters
bodyThe body, with its kind, size, and mass already set.
Ghidra address:
USA: 0x80258c24
Ghidra address:
Asia: 0x80258774
Ghidra address:
EUR: 0x8025a1f4
Ghidra address:
JPN: 0x80259b84
Ghidra address:
BRD3D: 0x10074870
Ghidra address:
BRGlide: 0x1006dad0

◆ BuildSkewSymmetricMatrix()

void BuildSkewSymmetricMatrix ( f32 out[3][3],
Vec3f * v )

The matrix of the cross product with a vector.

Parameters
outReceives the matrix.
vThe vector.
Ghidra address:
USA: 0x80258db0
Ghidra address:
Asia: 0x80258900
Ghidra address:
EUR: 0x8025a380
Ghidra address:
JPN: 0x80259d10
Ghidra address:
BRD3D: 0x100749d0
Ghidra address:
BRGlide: 0x1006dc30

◆ TransposeCopyMatrix3x3()

void TransposeCopyMatrix3x3 ( f32 transpose[3][3],
f32 copy[3][3],
f32 m[4][4] )

Copy the rotation of a matrix, and its transpose.

Parameters
transposeReceives the transpose of the rotation.
copyReceives the rotation.
mThe matrix.
Ghidra address:
USA: 0x80258e04
Ghidra address:
Asia: 0x80258954
Ghidra address:
EUR: 0x8025a3d4
Ghidra address:
JPN: 0x80259d64
Ghidra address:
BRD3D: 0x10074a10
Ghidra address:
BRGlide: 0x1006dc70

◆ Transpose4x4Into3x3()

void Transpose4x4Into3x3 ( f32 out[3][3],
f32 m[4][4] )

The transpose of the rotation of a matrix.

Parameters
outReceives the transpose.
mThe matrix.
Ghidra address:
USA: 0x80258e64
Ghidra address:
Asia: 0x802589B4
Ghidra address:
EUR: 0x8025a434
Ghidra address:
JPN: 0x80259dc4
Ghidra address:
BRD3D: 0x10074a50
Ghidra address:
BRGlide: 0x1006dcb0

◆ CopyMatrix4x4To3x3()

void CopyMatrix4x4To3x3 ( f32 out[3][3],
f32 m[4][4] )

Copy the rotation of a matrix.

Parameters
outReceives the rotation.
mThe matrix.
Ghidra address:
USA: 0x80258eac
Ghidra address:
Asia: 0x802589FC
Ghidra address:
EUR: 0x8025a47c
Ghidra address:
JPN: 0x80259e0c
Ghidra address:
BRD3D: 0x10074a90
Ghidra address:
BRGlide: 0x1006dcf0

◆ Mtx3fMultiply()

void Mtx3fMultiply ( f32 out[3][3],
f32 a[3][3],
f32 b[3][3] )

The product of two 3 by 3 matrices.

Parameters
outReceives a times b, and must be neither factor.
aThe left factor.
bThe right factor.
Ghidra address:
USA: 0x80258ef8
Ghidra address:
Asia: 0x80258A48
Ghidra address:
EUR: 0x8025a4c8
Ghidra address:
JPN: 0x80259e58
Ghidra address:
BRD3D: 0x10074ac0
Ghidra address:
BRGlide: 0x1006dd20

◆ SubtractMatrix3x3()

void SubtractMatrix3x3 ( f32 out[3][3],
f32 a[3][3],
f32 b[3][3] )

The difference of two 3 by 3 matrices.

Parameters
outReceives a minus b.
aThe matrix subtracted from.
bThe matrix subtracted.
Ghidra address:
USA: 0x80258f70
Ghidra address:
Asia: 0x80258AC0
Ghidra address:
EUR: 0x8025a540
Ghidra address:
JPN: 0x80259ed0
Ghidra address:
BRD3D: 0x10074b20
Ghidra address:
BRGlide: 0x1006dd80

◆ MtxBuildScaledInverse()

void MtxBuildScaledInverse ( f32 m[4][4],
f32 out[4][4],
Vec3f * scale )

The inverse of a rigid transform whose axes are scaled.

Parameters
mThe transform.
outReceives the inverse.
scaleThe factors the columns of the inverted rotation are scaled by.
Ghidra address:
USA: 0x80258fd4
Ghidra address:
Asia: 0x80258B24
Ghidra address:
EUR: 0x8025a5a4
Ghidra address:
JPN: 0x80259f34
Ghidra address:
BRD3D: 0x10074b70
Ghidra address:
BRGlide: 0x1006ddd0

◆ SolveLinearSystem3x3()

void SolveLinearSystem3x3 ( Vec3f * out,
f32 a[3][3],
Vec3f * b )

Solve a system of three linear equations by Cramer's rule.

Parameters
outReceives the solution.
aThe coefficients.
bThe constants.
Ghidra address:
USA: 0x802590e8
Ghidra address:
Asia: 0x80258C38
Ghidra address:
EUR: 0x8025a6b8
Ghidra address:
JPN: 0x8025a048
Ghidra address:
BRD3D: 0x10074c10
Ghidra address:
BRGlide: 0x1006de70