|
coastline 0.0.4
|
The physics of the vehicles: the forces on their bodies and wheels, the grip of the tyres, the suspension, and the collisions with the track and with each other. More...
#include <PR/ultratypes.h>#include "common/rigidbody.h"#include "common/tricache.h"#include "common/vecmath.h"

Go to the source code of this file.
Classes | |
| struct | CollisionTriangleNode |
| A node of the list of the triangles that cross the box of a body. More... | |
| union | CollisionContactVector |
| A contact plane with a vector view and its original four-component array view. More... | |
Macros | |
| #define | GRIP_WEATHERS 3 |
| The weathers the grip of a surface differs in: dry, rain and snow. | |
| #define | TRACK_SURFACES 8 |
| The surfaces of the track. | |
| #define | COLLISION_TRIANGLE_NODES 200 |
| The nodes of the list. | |
| #define | g_fCollisionContactW (g_vCollisionContact.axis[3]) |
| The word after g_vCollisionContact, which ComputeCollisionPenetration() scales. | |
Typedefs | |
| typedef struct CollisionTriangleNode | CollisionTriangleNode |
| A node of the list of the triangles that cross the box of a body. | |
| typedef union CollisionContactVector | CollisionContactVector |
| A contact plane with a vector view and its original four-component array view. | |
Functions | |
| void | ResetCollisionCaches (void) |
| Empty the cache of the triangles and the list of the triangles that cross the box. | |
| void | SumBodyForces (RigidBody *body) |
| Add the forces of the list of a body to its sums of force and torque. | |
| 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 part along the ground to the torque of the body while the wheel touches the ground. | |
| void | ComputeVehicleAccelerations (RigidBody *body) |
| Turn the sums of the force and torque of the body of a vehicle, and the forces of its wheels, into its accelerations, left in the sums. | |
| void | ComputeVehicleForces (RigidBody *body) |
| Sum the forces of the body of a vehicle and of its wheels, and turn them into its accelerations. | |
| 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 | GetWheelWorldVelocity (Vec3f *out, RigidBody *body, RigidBody *wheel) |
| The velocity of the point of a body at a wheel. | |
| void | GetBodyPointVelocity (Vec3f *out, RigidBody *body, Vec3f *point) |
| The velocity of a point of a body, given in its frame. | |
| 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 tyres allows on their surfaces, and lean the body as it skids. | |
| 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, as far as the weight on it lets it, and spin and turn the wheel. | |
| s16 | IsPointInTrackTriangle (TrackTriangle *triangle, Vec3f *point) |
| Whether a point lies within a triangle of the track, seen along the main axis of its normal. | |
| f32 | PlaneDistance (Vec3f *normal, f32 offset, Vec3f *point) |
| The distance of a point from a plane. | |
| 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, and damp its spin about the plane. | |
| s32 | UnusedCollisionResponseStub (void *body, void *normal, void *damp) |
| An empty collision response. | |
| 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 into a surface, record a hard hit, and retain a part of the slide along the surface. | |
| void | PushCollisionTriangle (TrackTriangle *triangle) |
| Add a triangle to the list of those that cross the box. | |
| void | PrintCollisionTriangleCount (void) |
| Print the length of the list on the debug output. | |
| s32 | ClassifyTriangleInUnitCube (Vec3f triangle[3]) |
| Sort out a triangle against the unit cube by its corners and its edges. | |
| 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 | DoesSegmentCrossUnitCube (Vec3f *start, Vec3f *end) |
| Whether a segment passes through the unit cube. | |
| s32 | DoesTriangleCrossUnitCube (Vec3f triangle[3], Vec3f *normal) |
| Whether an edge of a triangle, or a diagonal of the unit cube, crosses the other. | |
| s32 | IsTriangleInUnitCube (Vec3f triangle[3], Vec3f *normal) |
| Whether a triangle crosses the unit cube. | |
| s32 | CollectTrianglesInBox (RigidBody *body, f32 box[4][4]) |
| List the triangles of the cache under a body that cross its box. | |
| s32 | UnusedTrackCollisionStub (void *body) |
| An empty collision of a body with the track. | |
| s32 | TipBalancedVehicle (RigidBody *body) |
| Roll a vehicle that stands still balanced on one or two wheels off its balance, printing what it finds on the debug output. | |
| 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. | |
| 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 those it hit. | |
| void | StepVehicleCollisions (RigidBody *body) |
| Step the vehicle body through a frame, collide it, and count its upside-down frames. | |
| 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. | |
| f32 | CastWheelRay (RigidBody *body, RigidBody *wheel) |
| Find the ground below a wheel in the cache of the triangles. | |
| void | UpdateWheelHeights (RigidBody *body) |
| Find the ground below each wheel of a vehicle, and hang each wheel to it, no more than 0.4 down. | |
| void | ComputeSpringForces (RigidBody *body) |
| Set the springs of the wheels of a vehicle, and count the frames each wheel touches the ground. | |
| void | ComputeDampingForces (RigidBody *body) |
| Set the dampers of the wheels of a vehicle on the ground. | |
| 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. | |
| void | CollideVehicles (void) |
| Collide each pair of the vehicles of the race that are near, sharing their speed along the line between them and pushing them apart. | |
Variables | |
| CollisionTriangleNode | g_aCollisionTriangleNodes [COLLISION_TRIANGLE_NODES] |
| The nodes available for the triangles crossing the box of a body. | |
| CollisionTriangleNode * | g_pCollisionTriangleList |
| The list, the latest first. | |
| CollisionTriangleNode * | g_pNextCollisionTriangleNode |
| The next free node. | |
| s32 | g_dwCollisionContactType |
| How the last collision with a triangle is resolved: 1 against its plane alone, 2 at the face of the box nearest the triangle, otherwise at the corner of the box. | |
| TrackTriangle * | g_pCollisionTriangle |
| The triangle of the last collision. | |
| s32 | g_bTrackCollisionFrameToggle |
| Whether the triangles of the cache are collected from the last. | |
| f32 | g_afSurfaceGrip [GRIP_WEATHERS][TRACK_SURFACES] |
| The grip of the tyres on each surface in each weather, the load below which they hold, and the load above which they hold no less. | |
| f32 | g_afSurfaceMaxLoad [GRIP_WEATHERS][TRACK_SURFACES] |
| The tyre load at which the surface grip stops increasing, by weather and surface. | |
| f32 | g_afSurfaceSlipLoad [GRIP_WEATHERS][TRACK_SURFACES] |
| The minimum tyre load used when calculating sliding grip, by weather and surface. | |
| Vec3f | g_vecUnitX |
| The axes. | |
| Vec3f | g_vecUnitY |
| The unit vector along the positive Y axis. | |
| Vec3f | g_vecUnitZ |
| The unit vector along the positive Z axis. | |
| Vec3f | g_vecNegUnitZ |
| The unit vector along the negative Z axis. | |
| Vec3f | g_vVehicleObbHalfExtents |
| The half extents of the box two vehicles collide by. | |
| CollisionContactVector | g_vCollisionContact |
| Where the last collision with the track touched the body, in its frame. | |
| Vec3f | g_vCollisionPenetration |
| How far the last collision put the body into the triangle. | |
| f32 | g_fConst0p0001 |
| The restitution threshold for recording a hard collision. | |
| f32 | g_fConst0p9_3 |
| The velocity scale after a hard collision. | |
| f32 | g_fConst0p2 |
| The fraction of tangential speed retained when friction applies. | |
| f32 | g_fConst1p05 |
| The fixed part of collision restitution. | |
The physics of the vehicles: the forces on their bodies and wheels, the grip of the tyres, the suspension, and the collisions with the track and with each other.
A collision with the track works in the frame of the box of the body scaled to a unit cube: the triangles of the track in the cache are moved into it, and those that cross the cube are kept in a list for the steps of the frame.
| #define GRIP_WEATHERS 3 |
The weathers the grip of a surface differs in: dry, rain and snow.
| #define TRACK_SURFACES 8 |
The surfaces of the track.
| #define COLLISION_TRIANGLE_NODES 200 |
The nodes of the list.
| #define g_fCollisionContactW (g_vCollisionContact.axis[3]) |
The word after g_vCollisionContact, which ComputeCollisionPenetration() scales.
| typedef struct CollisionTriangleNode CollisionTriangleNode |
A node of the list of the triangles that cross the box of a body.
| typedef union CollisionContactVector CollisionContactVector |
A contact plane with a vector view and its original four-component array view.
| void ResetCollisionCaches | ( | void | ) |
Empty the cache of the triangles and the list of the triangles that cross the box.
| void SumBodyForces | ( | RigidBody * | body | ) |
Add the forces of the list of a body to its sums of force and torque.
| body | The body whose forces are summed. |
Add the forces of a wheel, in the frame of the body, to the force of the wheel, and the turn of their part along the ground to the torque of the body while the wheel touches the ground.
| body | The body of the vehicle. |
| wheel | The wheel whose forces are summed. |
| void ComputeVehicleAccelerations | ( | RigidBody * | body | ) |
Turn the sums of the force and torque of the body of a vehicle, and the forces of its wheels, into its accelerations, left in the sums.
| body | The body of the vehicle. |
| void ComputeVehicleForces | ( | RigidBody * | body | ) |
Sum the forces of the body of a vehicle and of its wheels, and turn them into its accelerations.
| body | The body of the vehicle. |
The velocity of the point of a body over a wheel at the height of the body, in the frame of the body.
| out | Receives the velocity, in the frame of the body. |
| body | The body of the vehicle. |
| wheel | The wheel the point lies over. |
The velocity of the point of a body at a wheel.
| out | Receives the velocity, in the world. |
| body | The body of the vehicle. |
| wheel | The wheel at whose position the velocity is taken. |
The velocity of a point of a body, given in its frame.
| out | Receives the velocity, in the world. |
| body | The body. |
| point | The point, in the frame of the body. |
| 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 tyres allows on their surfaces, and lean the body as it skids.
| body | The body of the vehicle. |
| dt | The time of the step. |
| rearLoad | The load on the rear tyres, to which DriveWheel() adds. |
| frontLoad | The load on the front tyres, to which DriveWheel() adds. |
| rearSliding | Whether the rear tyres slid, updated for the next step. |
| frontSliding | Whether the front tyres slid, updated for the next step. |
Drive a wheel on the ground, pushing the body along the way the wheel rolls by its drive, as far as the weight on it lets it, and spin and turn the wheel.
| body | The body of the vehicle. |
| wheel | The wheel to drive. |
| load | The load of its tyres, to which half the push is added. |
| sliding | Whether its tyres slid, selecting sliding traction. |
| dt | The time of the step. |
| s16 IsPointInTrackTriangle | ( | TrackTriangle * | triangle, |
| Vec3f * | point ) |
Whether a point lies within a triangle of the track, seen along the main axis of its normal.
| triangle | The triangle. |
| point | The point, on the plane of the triangle. |
The distance of a point from a plane.
| normal | The unit normal of the plane. |
| offset | The constant term of the equation of the plane. |
| point | The point. |
Stop the next step of a body moving into a plane, with a little bounce, record a hard hit, and damp its spin about the plane.
| body | The body whose next step bounces. |
| normal | The unit normal of the plane, pointing out of it. |
| damp | Whether the velocity is damped as well. |
| spin | Whether the spin is damped. |
| s32 UnusedCollisionResponseStub | ( | void * | body, |
| void * | normal, | ||
| void * | damp ) |
An empty collision response.
| body | A body this routine ignores. |
| normal | A normal this routine ignores. |
| damp | A flag this routine ignores. |
| 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 into a surface, record a hard hit, and retain a part of the slide along the surface.
| body | The body whose next step receives the impulse. |
| point | The point of contact, in the frame of the body. |
| normal | The unit normal of the surface. |
| friction | Whether a fifth of the slide is retained, rather than none. |
| restitution | How much the point bounces, more than the 1.05 it always does. |
| void PushCollisionTriangle | ( | TrackTriangle * | triangle | ) |
Add a triangle to the list of those that cross the box.
| triangle | The triangle to add. |
| void PrintCollisionTriangleCount | ( | void | ) |
Print the length of the list on the debug output.
Sort out a triangle against the unit cube by its corners and its edges.
| triangle | The corners of the triangle in the frame of the unit cube. |
How many times a triangle winds about a point of its plane, seen along the main axis of its normal.
| triangle | The corners of the triangle. |
| normal | The normal of the triangle. |
| point | The point, on the plane of the triangle. |
Whether a segment passes through the unit cube.
| start | One end of the segment. |
| end | The other end of the segment. |
Whether an edge of a triangle, or a diagonal of the unit cube, crosses the other.
| triangle | The corners of the triangle in the frame of the unit cube. |
| normal | The normal of the triangle. |
Whether a triangle crosses the unit cube.
| triangle | The corners of the triangle in the frame of the unit cube. |
| normal | The normal of the triangle. |
List the triangles of the cache under a body that cross its box.
| body | The body whose position selects the cell of the cache. |
| box | The matrix that takes the track into the unit cube of the box. |
| s32 UnusedTrackCollisionStub | ( | void * | body | ) |
An empty collision of a body with the track.
| body | A body this routine ignores. |
Roll a vehicle that stands still balanced on one or two wheels off its balance, printing what it finds on the debug output.
| body | The body of the vehicle. |
| 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.
| body | The body whose box scales the contact. |
| normal | The unit normal of the triangle in the unit cube. |
| offset | The distance of the plane of the triangle from the middle of the cube. |
| contact | The corner or the face of the box in the unit cube. |
| triangle | The corners of the triangle in the unit cube. |
Collide the next step of a body with the listed triangles that cross its box, and move it back out of those it hit.
| body | The body to collide. |
| box | The matrix that takes the track into the unit cube of the box. |
| void StepVehicleCollisions | ( | RigidBody * | body | ) |
Step the vehicle body through a frame, collide it, and count its upside-down frames.
| body | The body of the vehicle. |
| 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.
| body | The body of the vehicle. |
| force | The force to set. |
Find the ground below a wheel in the cache of the triangles.
| body | The body of the vehicle. |
| wheel | The wheel, whose ground, surface, and plane are set to those found. |
| void UpdateWheelHeights | ( | RigidBody * | body | ) |
Find the ground below each wheel of a vehicle, and hang each wheel to it, no more than 0.4 down.
| body | The body of the vehicle. |
| void ComputeSpringForces | ( | RigidBody * | body | ) |
Set the springs of the wheels of a vehicle, and count the frames each wheel touches the ground.
| body | The body of the vehicle. |
| void ComputeDampingForces | ( | RigidBody * | body | ) |
Set the dampers of the wheels of a vehicle on the ground.
| body | The body of the vehicle. |
Whether two boxes overlap, by the separating axes of their faces and of the products of their edges.
| rotation | The rotation of the second box in the frame of the first. |
| offset | The second box from the first, in the frame of the first. |
| halfA | The half extents of the first box. |
| halfB | The half extents of the second box. |
| void CollideVehicles | ( | void | ) |
Collide each pair of the vehicles of the race that are near, sharing their speed along the line between them and pushing them apart.
It stops at the first pair whose boxes do not meet.
|
extern |
The nodes available for the triangles crossing the box of a body.
|
extern |
The list, the latest first.
|
extern |
The next free node.
|
extern |
How the last collision with a triangle is resolved: 1 against its plane alone, 2 at the face of the box nearest the triangle, otherwise at the corner of the box.
|
extern |
The triangle of the last collision.
|
extern |
Whether the triangles of the cache are collected from the last.
|
extern |
The grip of the tyres on each surface in each weather, the load below which they hold, and the load above which they hold no less.
|
extern |
The tyre load at which the surface grip stops increasing, by weather and surface.
|
extern |
The minimum tyre load used when calculating sliding grip, by weather and surface.
|
extern |
The axes.
|
extern |
The unit vector along the positive Y axis.
|
extern |
The unit vector along the positive Z axis.
|
extern |
The unit vector along the negative Z axis.
|
extern |
The half extents of the box two vehicles collide by.
|
extern |
Where the last collision with the track touched the body, in its frame.
|
extern |
How far the last collision put the body into the triangle.
|
extern |
The restitution threshold for recording a hard collision.
|
extern |
The velocity scale after a hard collision.
|
extern |
The fraction of tangential speed retained when friction applies.
|
extern |
The fixed part of collision restitution.