1#ifndef COASTLINE_PHYSICS_H
2#define COASTLINE_PHYSICS_H
29#define GRIP_WEATHERS 3
32#define TRACK_SURFACES 8
36typedef union CollisionContactState {
39} CollisionContactState;
47extern CollisionContactState g_CollisionContactState;
49#define g_dwCollisionContactType (g_CollisionContactState.type)
50#define g_fCollisionContactW (g_CollisionContactState.w)
58extern f32 g_fCollisionImpulseScale;
101void SelectVehiclePhysicsTables(
s32 model);
111#define COLLISION_TRIANGLE_NODES 200
266#if TGR_PLATFORM == TGR_PLATFORM_N64
290#if TGR_PLATFORM == TGR_PLATFORM_N64
304#if TGR_PLATFORM == TGR_PLATFORM_N64
305#define g_fCollisionContactW (g_vCollisionContact.axis[3])
540#if TGR_PLATFORM == TGR_PLATFORM_N64
635s32 ComputeAabbCornerPlaneClipCode(
Vec3f *v,
s32 mask);
f32 g_fConst0p0001
The restitution threshold for recording a hard collision.
s32 g_dwCollisionContactType
How the last collision with a triangle is resolved: 1 against its plane alone, 2 at the face of the b...
void ComputeSpringForces(RigidBody *body)
Set the springs of the wheels of a vehicle, and count the frames each wheel touches the ground.
void GetWheelWorldVelocity(Vec3f *out, RigidBody *body, RigidBody *wheel)
The velocity of the point of a body at a wheel.
f32 g_afSurfaceMaxLoad[GRIP_WEATHERS][TRACK_SURFACES]
The tyre load at which the surface grip stops increasing, by weather and surface.
#define TRACK_SURFACES
The surfaces of the track.
Definition physics.h:32
CollisionTriangleNode * g_pCollisionTriangleList
The list, the latest first.
Vec3f g_vecUnitY
The unit vector along the positive Y axis.
s32 g_bTrackCollisionFrameToggle
Whether the triangles of the cache are collected from the last.
Vec3f g_vCollisionPenetration
How far the last collision put the body into the triangle.
#define GRIP_WEATHERS
The weathers the grip of a surface differs in: dry, rain and snow.
Definition physics.h:29
void ComputeVehicleForces(RigidBody *body)
Sum the forces of the body of a vehicle and of its wheels, and turn them into its accelerations.
TrackTriangle * g_pCollisionTriangle
The triangle of the last collision.
Vec3f g_vecUnitX
The axes.
void ComputeWheelLocalVelocity(Vec3f *out, RigidBody *body, RigidBody *wheel)
The velocity of the point of a body over a wheel at the height of the body, in the frame of the body.
void CollideVehicles(void)
Collide each pair of the vehicles of the race that are near, sharing their speed along the line betwe...
f32 PlaneDistance(Vec3f *normal, f32 offset, Vec3f *point)
The distance of a point from a plane.
void ComputeCollisionPenetration(RigidBody *body, Vec3f *normal, f32 offset, Vec3f *contact, Vec3f triangle[3])
Find how far the box of a body is into a triangle.
void SumBodyForces(RigidBody *body)
Add the forces of the list of a body to its sums of force and torque.
#define COLLISION_TRIANGLE_NODES
The nodes of the list.
Definition physics.h:111
f32 g_afSurfaceGrip[GRIP_WEATHERS][TRACK_SURFACES]
The grip of the tyres on each surface in each weather, the load below which they hold,...
s32 TipBalancedVehicle(RigidBody *body)
Roll a vehicle that stands still balanced on one or two wheels off its balance, printing what it find...
s32 CollideBodyWithTriangles(RigidBody *body, f32 box[4][4])
Collide the next step of a body with the listed triangles that cross its box, and move it back out of...
void StepVehicleCollisions(RigidBody *body)
Step the vehicle body through a frame, collide it, and count its upside-down frames.
void UpdateWheelHeights(RigidBody *body)
Find the ground below each wheel of a vehicle, and hang each wheel to it, no more than 0....
s32 CollectTrianglesInBox(RigidBody *body, f32 box[4][4])
List the triangles of the cache under a body that cross its box.
CollisionContactVector g_vCollisionContact
Where the last collision with the track touched the body, in its frame.
void GetBodyPointVelocity(Vec3f *out, RigidBody *body, Vec3f *point)
The velocity of a point of a body, given in its frame.
s32 UnusedCollisionResponseStub(void *body, void *normal, void *damp)
An empty collision response.
void ApplySideGrip(RigidBody *body, f32 dt, f32 *rearLoad, f32 *frontLoad, u8 *rearSliding, u8 *frontSliding)
Cancel the sideways slip of the rear and the front of the body of a vehicle as far as the grip of the...
f32 g_fConst0p2
The fraction of tangential speed retained when friction applies.
void ComputeVehicleAccelerations(RigidBody *body)
Turn the sums of the force and torque of the body of a vehicle, and the forces of its wheels,...
CollisionTriangleNode g_aCollisionTriangleNodes[COLLISION_TRIANGLE_NODES]
The nodes available for the triangles crossing the box of a body.
Vec3f g_vecUnitZ
The unit vector along the positive Z axis.
f32 CastWheelRay(RigidBody *body, RigidBody *wheel)
Find the ground below a wheel in the cache of the triangles.
#define g_fCollisionContactW
The word after g_vCollisionContact, which ComputeCollisionPenetration() scales.
Definition physics.h:305
s32 DoesSegmentCrossUnitCube(Vec3f *start, Vec3f *end)
Whether a segment passes through the unit cube.
s32 BounceOffPlane(RigidBody *body, Vec3f *normal, s32 damp, s32 spin)
Stop the next step of a body moving into a plane, with a little bounce, record a hard hit,...
f32 g_fConst0p9_3
The velocity scale after a hard collision.
void ComputeDragForce(RigidBody *body, RigidBodyForce *force)
Set a force to the drag on the body of a vehicle, which grows on the surface that slows it.
void PushCollisionTriangle(TrackTriangle *triangle)
Add a triangle to the list of those that cross the box.
Vec3f g_vVehicleObbHalfExtents
The half extents of the box two vehicles collide by.
s32 TestObbIntersection(f32 rotation[3][3], Vec3f *offset, Vec3f *halfA, Vec3f *halfB)
Whether two boxes overlap, by the separating axes of their faces and of the products of their edges.
f32 g_fConst1p05
The fixed part of collision restitution.
Vec3f g_vecNegUnitZ
The unit vector along the negative Z axis.
void ComputeDampingForces(RigidBody *body)
Set the dampers of the wheels of a vehicle on the ground.
void DriveWheel(RigidBody *body, RigidBody *wheel, f32 *load, u8 *sliding, f32 dt)
Drive a wheel on the ground, pushing the body along the way the wheel rolls by its drive,...
s32 CountTriangleWinding(Vec3f triangle[3], Vec3f *normal, Vec3f *point)
How many times a triangle winds about a point of its plane, seen along the main axis of its normal.
s32 ClassifyTriangleInUnitCube(Vec3f triangle[3])
Sort out a triangle against the unit cube by its corners and its edges.
s32 DoesTriangleCrossUnitCube(Vec3f triangle[3], Vec3f *normal)
Whether an edge of a triangle, or a diagonal of the unit cube, crosses the other.
void PrintCollisionTriangleCount(void)
Print the length of the list on the debug output.
CollisionTriangleNode * g_pNextCollisionTriangleNode
The next free node.
s32 UnusedTrackCollisionStub(void *body)
An empty collision of a body with the track.
s32 IsTriangleInUnitCube(Vec3f triangle[3], Vec3f *normal)
Whether a triangle crosses the unit cube.
void ResetCollisionCaches(void)
Empty the cache of the triangles and the list of the triangles that cross the box.
s16 IsPointInTrackTriangle(TrackTriangle *triangle, Vec3f *point)
Whether a point lies within a triangle of the track, seen along the main axis of its normal.
s32 ApplyCollisionImpulse(RigidBody *body, Vec3f *point, Vec3f *normal, s32 friction, f32 restitution)
Give the next step of a body the impulse at a point of it, in its frame, that stops the point moving ...
f32 g_afSurfaceSlipLoad[GRIP_WEATHERS][TRACK_SURFACES]
The minimum tyre load used when calculating sliding grip, by weather and surface.
void SumWheelForces(RigidBody *body, RigidBody *wheel)
Add the forces of a wheel, in the frame of the body, to the force of the wheel, and the turn of their...
The rigid bodies of the physics: their state, forces and inertia, and the quaternion and 3 by 3 matri...
A node of the list of the triangles that cross the box of a body.
Definition physics.h:105
TrackTriangle * triangle
Definition physics.h:106
struct CollisionTriangleNode * next
Definition physics.h:107
A force on a rigid body, in a list.
Definition rigidbody.h:42
A rigid body: the body of a vehicle or of one of its wheels.
Definition rigidbody.h:60
A triangle of the track with its plane.
Definition tricache.h:25
A point or direction in space.
Definition vecmath.h:17
A vehicle.
Definition vehicle.h:143
The cache of the triangles of the track around a point, one cell of the 32-unit grid of the track in ...
Integer and floating-point types of libultra.
short s16
Definition ultratypes.h:24
float f32
Definition ultratypes.h:38
int s32
Definition ultratypes.h:25
unsigned char u8
Definition ultratypes.h:18
The vector and matrix arithmetic of the game, its arctangent and power, the triangle and segment test...