coastline 0.0.4
Loading...
Searching...
No Matches
physicsimpact.h
Go to the documentation of this file.
1#ifndef COASTLINE_PHYSICSIMPACT_H
2#define COASTLINE_PHYSICSIMPACT_H
3
4#include "common/physics.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
11#define MAX_IMPACT_SPEED 27.0f
12
14static inline u8 ImpactVolume(f32 speed) {
15#if TGR_BOSS_RALLY
16 /* __ftol truncates through 64 bits, which gives 0 for a NaN speed. */
17 return (u32)(s64)(128.0L - (long double)speed * -4.70370388031005859375f);
18#else
19 return (u32)(speed * 127.0f / MAX_IMPACT_SPEED + 128.0f);
20#endif
21}
22
24static inline void RecordImpact(RigidBody *body, f32 speed) {
25#if TGR_BOSS_RALLY
26 /* __ftol truncates through 64 bits, which gives 0 for a NaN speed. */
27 body->impactSpeed = (u32)(s64)speed;
28#else
29 body->impactSpeed = (u32)speed;
30#endif
31#if !TGR_BOSS_RALLY
32 if (body->impactSpeed < 10) {
33 body->impactSpeed = 0;
34 } else
35#endif
36 {
40 }
41}
42
44static inline void RecordImpactVolume(RigidBody *body, f32 speed) {
45 u8 volume = ImpactVolume(speed);
46
47 /* The original writes the volume back even when it does not change. */
48 body->impactVolume = body->impactVolume < volume ? volume : body->impactVolume;
49}
50
51#ifdef __cplusplus
52}
53#endif
54
55#endif /* COASTLINE_PHYSICSIMPACT_H */
The physics of the vehicles: the forces on their bodies and wheels, the grip of the tyres,...
CollisionContactVector g_vCollisionContact
Where the last collision with the track touched the body, in its frame.
#define MAX_IMPACT_SPEED
The speed a hit is counted up to for its sound.
Definition physicsimpact.h:11
static void RecordImpactVolume(RigidBody *body, f32 speed)
Retain the loudest impact sound for body.
Definition physicsimpact.h:44
static void RecordImpact(RigidBody *body, f32 speed)
Record a hard impact and its contact point in body.
Definition physicsimpact.h:24
static u8 ImpactVolume(f32 speed)
Definition physicsimpact.h:14
A rigid body: the body of a vehicle or of one of its wheels.
Definition rigidbody.h:60
u8 impactVolume
Definition rigidbody.h:105
Vec3f impactPoint
Definition rigidbody.h:99
u8 impactSpeed
Definition rigidbody.h:102
f32 z
Definition vecmath.h:20
f32 x
Definition vecmath.h:18
f32 y
Definition vecmath.h:19
unsigned int u32
Definition ultratypes.h:20
float f32
Definition ultratypes.h:38
long long s64
Definition ultratypes.h:26
unsigned char u8
Definition ultratypes.h:18