coastline 0.0.4
Loading...
Searching...
No Matches
physics.h
Go to the documentation of this file.
1#ifndef COASTLINE_PHYSICS_H
2#define COASTLINE_PHYSICS_H
3
13
14#include <PR/ultratypes.h>
15
16#include "common/rigidbody.h"
17#include "common/tricache.h"
18#include "common/vecmath.h"
19
20#if TGR_BOSS_RALLY
21#include "common/vehiclefwd.h"
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
29#define GRIP_WEATHERS 3
30
32#define TRACK_SURFACES 8
33
34#if TGR_BOSS_RALLY
36typedef union CollisionContactState {
37 s32 type;
38 f32 w;
39} CollisionContactState;
40
47extern CollisionContactState g_CollisionContactState;
48
49#define g_dwCollisionContactType (g_CollisionContactState.type)
50#define g_fCollisionContactW (g_CollisionContactState.w)
51
58extern f32 g_fCollisionImpulseScale;
59
64extern f32 (*g_pSteeringFrictionTableA)[GRIP_WEATHERS][TRACK_SURFACES];
65
70extern f32 (*g_pSteeringFrictionTableB)[TRACK_SURFACES];
71
73extern f32 (*g_pWheelSteeringTable)[GRIP_WEATHERS][TRACK_SURFACES];
74
76extern f32 g_afVehiclePhysicsTableA0[3][GRIP_WEATHERS][TRACK_SURFACES];
77
79extern f32 g_afVehiclePhysicsTableA1[3][GRIP_WEATHERS][TRACK_SURFACES];
80
82extern f32 g_afVehiclePhysicsTableB0[GRIP_WEATHERS][TRACK_SURFACES];
83
85extern f32 g_afVehiclePhysicsTableB1[GRIP_WEATHERS][TRACK_SURFACES];
86
88extern f32 g_afVehiclePhysicsTableC0[3][GRIP_WEATHERS][TRACK_SURFACES];
89
91extern f32 g_afVehiclePhysicsTableC1[3][GRIP_WEATHERS][TRACK_SURFACES];
93
101void SelectVehiclePhysicsTables(s32 model);
102#endif /* TGR_BOSS_RALLY */
103
109
111#define COLLISION_TRIANGLE_NODES 200
112
124
136
148
149#if !TGR_BOSS_RALLY
160#endif /* !TGR_BOSS_RALLY */
161
173
185
196
206
218
224extern Vec3f g_vecUnitX;
225
234extern Vec3f g_vecUnitY;
235
244extern Vec3f g_vecUnitZ;
245
254extern Vec3f g_vecNegUnitZ;
255
265
266#if TGR_PLATFORM == TGR_PLATFORM_N64
278#endif
279
290#if TGR_PLATFORM == TGR_PLATFORM_N64
292#else
294#endif
295
304#if TGR_PLATFORM == TGR_PLATFORM_N64
305#define g_fCollisionContactW (g_vCollisionContact.axis[3])
306#elif !TGR_BOSS_RALLY
308#endif /* !TGR_BOSS_RALLY */
309
321
333
346
361
375
388
404
419
433void GetBodyPointVelocity(Vec3f *out, RigidBody *body, Vec3f *point);
434
453 RigidBody *body, f32 dt, f32 *rearLoad, f32 *frontLoad, u8 *rearSliding, u8 *frontSliding);
454
471void DriveWheel(RigidBody *body, RigidBody *wheel, f32 *load, u8 *sliding, f32 dt);
472
487
502#if TGR_BOSS_RALLY
503long double PlaneDistance(Vec3f *normal, f32 offset, Vec3f *point);
504#else
505f32 PlaneDistance(Vec3f *normal, f32 offset, Vec3f *point);
506#endif
507
524s32 BounceOffPlane(RigidBody *body, Vec3f *normal, s32 damp, s32 spin);
525
538s32 UnusedCollisionResponseStub(void *body, void *normal, void *damp);
539
540#if TGR_PLATFORM == TGR_PLATFORM_N64
549extern f32 g_fConst0p0001;
550
559extern f32 g_fConst0p9_3;
560
569extern f32 g_fConst0p2;
570
579extern f32 g_fConst1p05;
580#endif
581
600 RigidBody *body, Vec3f *point, Vec3f *normal, s32 friction, f32 restitution);
601
614
624
625#if TGR_BOSS_RALLY
635s32 ComputeAabbCornerPlaneClipCode(Vec3f *v, s32 mask);
636#endif /* TGR_BOSS_RALLY */
637
652
668s32 CountTriangleWinding(Vec3f triangle[3], Vec3f *normal, Vec3f *point);
669
684
699
713s32 IsTriangleInUnitCube(Vec3f triangle[3], Vec3f *normal);
714
729
741
756
773 RigidBody *body, Vec3f *normal, f32 offset, Vec3f *contact, Vec3f triangle[3]);
774
790
791#if TGR_BOSS_RALLY
802void StepVehicleCollisions(Vehicle *vehicle, RigidBody *body);
803#else
814#endif /* TGR_BOSS_RALLY */
828
843
856
869
882
899s32 TestObbIntersection(f32 rotation[3][3], Vec3f *offset, Vec3f *halfA, Vec3f *halfB);
900
913
914#ifdef __cplusplus
915}
916#endif
917
918#endif /* COASTLINE_PHYSICS_H */
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
A contact plane with a vector view and its original four-component array view.
Definition physics.h:268
f32 axis[4]
Definition physics.h:276
f32 w
Definition physics.h:274
f32 z
Definition physics.h:273
f32 y
Definition physics.h:272
Vec3f vector
Definition physics.h:269
f32 x
Definition physics.h:271
The vector and matrix arithmetic of the game, its arctangent and power, the triangle and segment test...