coastline 0.0.4
Loading...
Searching...
No Matches
trianglebox.h
Go to the documentation of this file.
1#ifndef COASTLINE_TRIANGLEBOX_H
2#define COASTLINE_TRIANGLEBOX_H
3
4#include "common/physics.h"
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
11static inline void TriangleInBox(Vec3f corners[3], Vec3f *normal, f32 box[4][4], TrackTriangle *t) {
12 Vec3f e1, e2;
13#if TGR_BOSS_RALLY
14 long double highE2[3];
15#endif
16
17 Mtx4x4TransformPoint(&corners[0], box, t->vertices[0]);
18 Mtx4x4TransformPoint(&corners[1], box, t->vertices[1]);
19 Mtx4x4TransformPoint(&corners[2], box, t->vertices[2]);
20 e1.x = corners[1].x - corners[0].x;
21 e1.y = corners[1].y - corners[0].y;
22 e1.z = corners[1].z - corners[0].z;
23#if TGR_BOSS_RALLY
24 highE2[0] = (long double)corners[2].x - corners[0].x;
25 highE2[1] = (long double)corners[2].y - corners[0].y;
26 highE2[2] = (long double)corners[2].z - corners[0].z;
27 e2.x = (f32)highE2[0];
28 e2.y = (f32)highE2[1];
29 e2.z = (f32)highE2[2];
30#else
31 e2.x = corners[2].x - corners[0].x;
32 e2.y = corners[2].y - corners[0].y;
33 e2.z = corners[2].z - corners[0].z;
34#endif /* TGR_BOSS_RALLY */
35#if TGR_BOSS_RALLY
36 /* The normal mixes retained second-edge values with their stored float copies. */
37 normal->x = (f32)(e1.y * highE2[2] - highE2[1] * e1.z);
38 normal->y = (f32)(e1.z * highE2[0] - (long double)e2.z * e1.x);
39 normal->z = (f32)((long double)e1.x * e2.y - (long double)e2.x * e1.y);
40#else
41 normal->x = e1.y * e2.z - e2.y * e1.z;
42 normal->y = e1.z * e2.x - e2.z * e1.x;
43 normal->z = e1.x * e2.y - e2.x * e1.y;
44#endif /* TGR_BOSS_RALLY */
45}
46
47#ifdef __cplusplus
48}
49#endif
50
51#endif /* COASTLINE_TRIANGLEBOX_H */
The physics of the vehicles: the forces on their bodies and wheels, the grip of the tyres,...
void Mtx4x4TransformPoint(Vec3f *out, f32 m[4][4], Vec3f *v)
A point times a matrix, with its translation.
A triangle of the track with its plane.
Definition tricache.h:25
Vec3f * vertices[3]
Definition tricache.h:28
A point or direction in space.
Definition vecmath.h:17
f32 z
Definition vecmath.h:20
f32 x
Definition vecmath.h:18
f32 y
Definition vecmath.h:19
static void TriangleInBox(Vec3f corners[3], Vec3f *normal, f32 box[4][4], TrackTriangle *t)
Move t into the unit cube of box and calculate its normal there.
Definition trianglebox.h:11
float f32
Definition ultratypes.h:38