coastline 0.0.4
Loading...
Searching...
No Matches
vecmath.h
Go to the documentation of this file.
1#ifndef COASTLINE_VECMATH_H
2#define COASTLINE_VECMATH_H
3
9
10#include "common/types.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
17typedef struct {
21} Vec3f;
22
24typedef struct {
27} Vec2f;
28
29#if TGR_BOSS_RALLY
31typedef struct {
32 f64 x;
33 f64 y;
34 f64 z;
35} Vec3d;
36#endif
37
48extern u32 g_dwRandomSeed;
49
62f32 Powf(f32 base, f32 exponent);
63
77void Vec3fCross(Vec3f *out, Vec3f *a, Vec3f *b);
78
92#if TGR_BOSS_RALLY
93long double Vec3fDot(const Vec3f *a, const Vec3f *b);
94#else
95f32 Vec3fDot(const Vec3f *a, const Vec3f *b);
96#endif
97
110void Vec3fNegate(Vec3f *out, Vec3f *v);
111
122
134void Vec2fMul(Vec2f *out, Vec2f *a, Vec2f *b);
135
147void Vec2fScale(Vec2f *out, Vec2f *v, f32 scale);
148
161
175void Vec3fScale(Vec3f *out, Vec3f *v, f32 scale);
176
190
204void Vec3fScaleByInverse(Vec3f *out, Vec3f *v, f32 divisor);
205
218void Vec3fDivideInPlace(Vec3f *v, f32 divisor);
219
232void Vec3fCopy(Vec3f *out, Vec3f *v);
233
247void Vec3fDirection(Vec3f *out, Vec3f *from, Vec3f *to);
248
260
274
288void Vec3fSubtract(Vec3f *out, const Vec3f *a, const Vec3f *b);
289
303
315void Vec2fAdd(Vec2f *out, Vec2f *a, Vec2f *b);
316
330void Vec3fAdd(Vec3f *out, Vec3f *a, Vec3f *b);
331
345
360void Vec3fLerp(Vec3f *out, Vec3f *a, Vec3f *b, f32 t);
361
376void Vec3fMulAdd(Vec3f *out, Vec3f *a, Vec3f *b, f32 scale);
377
391void Vec3fMulAddInPlace(Vec3f *v, Vec3f *b, f32 scale);
392
406void Vec3fMidpoint(Vec3f *out, Vec3f *a, Vec3f *b);
407
420
434#if TGR_BOSS_RALLY
435long double Vec2fDistance(Vec2f *a, Vec2f *b);
436#else
438#endif
439
440#if TGR_BOSS_RALLY
447long double Vec3fDistance(Vec3f *a, Vec3f *b);
448#else
461#endif /* TGR_BOSS_RALLY */
462
476#if TGR_BOSS_RALLY
477long double Vec3fDistanceSquared(Vec3f *a, Vec3f *b);
478#else
480#endif
481
494#if TGR_BOSS_RALLY
495long double Vec3fLength(Vec3f *v);
496#else
498#endif
499
512#if TGR_BOSS_RALLY
513long double Vec2fLength(Vec2f *v);
514#else
516#endif
517
529void Vec3fRotateAroundAxis(Vec3f *v, f32 angle, Vec3f *axis);
530
544void Mtx4x4ProjectPoint(Vec3f *out, Vec3f *in, f32 m[4][4]);
545
559void Vec3fTransformByMatrix(f32 out[4], const Vec3f *in, f32 m[4][4]);
560
572void Vec3sTransformToVec4f(f32 out[4], s16 in[3], f32 m[4][4]);
573
585void ProjectVec3fToScreen(Vec2f *out, Vec3f *in, f32 m[4][4]);
586
601
615void Mtx3x3TransformVec(Vec3f *out, Vec3f *in, f32 m[4][4]);
616
630void Mtx4x4Multiply(f32 out[4][4], f32 a[4][4], f32 b[4][4]);
631
642void Mtx4fTranspose(f32 out[4][4], f32 in[4][4]);
643
656#if TGR_BOSS_RALLY
657void CopyMatrix4x4(f32 in[4][4], f32 out[4][4]);
658#else
659void CopyMatrix4x4(f32 out[4][4], f32 in[4][4]);
660#endif
661
676s32 MtxInvert4x4(f32 out[4][4], f32 in[4][4]);
677
689#if TGR_BOSS_RALLY
690#if defined(_MSC_VER) && !defined(_WIN64)
691void __fastcall FinishFrameMatrix(f32 m[4][4]);
692#else
693void __thiscall FinishFrameMatrix(f32 m[4][4]);
694#endif
695#else
696void FinishFrameMatrix(f32 m[4][4]);
697#endif
698
713#if TGR_BOSS_RALLY
714long double Atan2f(f32 x, f32 y);
715#else
717#endif
718
735s32 PointInTriangle3D(Vec3f *point, Vec3f *v0, Vec3f *v1, Vec3f *v2, Vec3f *normal);
736
753 Vec3f *point, Vec3f *v0, Vec3f *v1, Vec3f *v2, Vec3f *normal, f32 tolerance);
754
771
788s32 SegmentCrossesLine2D(const Vec3f *a, const Vec3f *b, const Vec3f *p, const Vec3f *q);
789
801void SetRngSeed(u32 seed);
802
815
816#if TGR_BOSS_RALLY
825long double Vec3dLengthSquared(Vec3d *v);
826
835long double Vec3dLength(Vec3d *v);
836
845Vec3d *Vec3dNormalize(Vec3d *v);
846
856long double Vec3dDot(Vec3d *a, Vec3d *b);
857
867void Vec3dCross(Vec3d *a, Vec3d *b, Vec3d *out);
868#endif /* TGR_BOSS_RALLY */
869
870#ifdef __cplusplus
871}
872#endif
873
874#endif /* COASTLINE_VECMATH_H */
A point or direction in a plane.
Definition vecmath.h:24
f32 x
Definition vecmath.h:25
f32 y
Definition vecmath.h:26
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
The integer and floating-point types of the console, for headers shared with Windows.
unsigned int u32
Definition ultratypes.h:20
short s16
Definition ultratypes.h:24
float f32
Definition ultratypes.h:38
double f64
Definition ultratypes.h:39
int s32
Definition ultratypes.h:25
void Vec3fCopy(Vec3f *out, Vec3f *v)
Copy a vector.
void Vec3fScale(Vec3f *out, Vec3f *v, f32 scale)
Multiply a vector by a number.
u32 AdvanceRng(void)
Advance the random numbers by the multiplier 16807 and retain 27 bits.
void Mtx4fTranspose(f32 out[4][4], f32 in[4][4])
Transpose a matrix but its diagonal, which is copied unchanged into the result.
s32 IsPointInsideTriangle(Vec3f *point, Vec3f *v0, Vec3f *v1, Vec3f *v2, Vec3f *normal, f32 tolerance)
PointInTriangle3D() with a tolerance for each edge.
void Vec3fCross(Vec3f *out, Vec3f *a, Vec3f *b)
Take the cross product of two vectors.
void Vec3fLerp(Vec3f *out, Vec3f *a, Vec3f *b, f32 t)
The point a share of the way from b to a: b + (a - b) * t.
void Vec3fSubtract(Vec3f *out, const Vec3f *a, const Vec3f *b)
Subtract one vector from another.
void Vec3fDivideInPlace(Vec3f *v, f32 divisor)
Divide a vector by a number in place.
void Vec3fClear(Vec3f *v)
Set a vector to zero.
void Vec2fScale(Vec2f *out, Vec2f *v, f32 scale)
Multiply a vector by a number.
void FinishFrameMatrix(f32 m[4][4])
Set the last column of a matrix to that of an affine transform: 0, 0, 0 and 1.
void Mtx3x3TransformVec(Vec3f *out, Vec3f *in, f32 m[4][4])
Transform a direction by the 3 by 3 part of a matrix.
void Vec3fMidpoint(Vec3f *out, Vec3f *a, Vec3f *b)
The point halfway between two points.
void Vec3fNormalizeSafe(Vec3f *out, Vec3f *v)
The unit vector along a vector, or (0, 0, 1) for the zero vector.
void Vec3fRotateAroundAxis(Vec3f *v, f32 angle, Vec3f *axis)
Rotate a vector by an angle about a unit axis, clockwise as seen from the tip of the axis.
void Mtx4x4Multiply(f32 out[4][4], f32 a[4][4], f32 b[4][4])
Multiply two matrices.
s32 TestLineSegmentIntersection(Vec2f *p1, Vec2f *p2, Vec2f *q1, Vec2f *q2)
Whether two segments of the plane meet.
void Vec3fNegate(Vec3f *out, Vec3f *v)
Negate a vector.
u32 g_dwRandomSeed
The seed used by the game's pseudorandom number generator.
void Vec3fAddInPlace(Vec3f *v, Vec3f *b)
Add one vector to another in place.
s32 MtxInvert4x4(f32 out[4][4], f32 in[4][4])
Invert an affine matrix.
void Vec3fScaleByInverse(Vec3f *out, Vec3f *v, f32 divisor)
Multiply a vector by the reciprocal of a number.
void Vec3fAdd(Vec3f *out, Vec3f *a, Vec3f *b)
Add two vectors.
f32 Powf(f32 base, f32 exponent)
Raise a number to a power: by multiplication for the whole part of the exponent and by the binomial s...
f32 Atan2f(f32 x, f32 y)
The angle of a point counterclockwise from the x axis, from 0 to two pi, found by a search of the sin...
f32 Vec2fLength(Vec2f *v)
The length of a vector of the plane.
void Vec3sTransformToVec4f(f32 out[4], s16 in[3], f32 m[4][4])
Transform a point of short integers by a matrix into four components.
void ProjectVec3fToScreen(Vec2f *out, Vec3f *in, f32 m[4][4])
Transform a point by a matrix, divide by w, and retain x and y.
void Vec3fMulAddInPlace(Vec3f *v, Vec3f *b, f32 scale)
Add a scaled vector to another in place.
f32 Vec3fDistance(Vec3f *a, Vec3f *b)
The distance between two points.
void Vec3fNormalize(Vec3f *v)
Make a vector a unit vector, or (0, 0, 1) if it is the zero vector.
s32 PointInTriangle3D(Vec3f *point, Vec3f *v0, Vec3f *v1, Vec3f *v2, Vec3f *normal)
Whether a point lies within a triangle, on the side of each edge the normal gives.
void SetRngSeed(u32 seed)
Set the seed of the random numbers.
void Mtx4x4ProjectPoint(Vec3f *out, Vec3f *in, f32 m[4][4])
Transform a point by a matrix and divide by w.
f32 Vec2fDistance(Vec2f *a, Vec2f *b)
The distance between two points of the plane.
f32 Vec3fDot(const Vec3f *a, const Vec3f *b)
Take the dot product of two vectors.
void Vec3fSubtractInPlace(Vec3f *v, Vec3f *b)
Subtract one vector from another in place.
void Vec2fMul(Vec2f *out, Vec2f *a, Vec2f *b)
Multiply two vectors component by component.
void Vec3fTransformByMatrix(f32 out[4], const Vec3f *in, f32 m[4][4])
Transform a point by a matrix into four components.
void CopyMatrix4x4(f32 out[4][4], f32 in[4][4])
Copy a matrix.
f32 Vec3fDistanceSquared(Vec3f *a, Vec3f *b)
The square of the distance between two points.
void Mtx4x4TransformNoTranslation(Vec3f *out, Vec3f *in, f32 m[4][4])
Transform a direction by a matrix without its translation, and divide by w.
f32 Vec3fLength(Vec3f *v)
The length of a vector.
void Vec3fMulAdd(Vec3f *out, Vec3f *a, Vec3f *b, f32 scale)
Add a scaled vector to another.
void Vec2fAdd(Vec2f *out, Vec2f *a, Vec2f *b)
Add two vectors.
void Vec3fComponentProduct(Vec3f *out, Vec3f *a, Vec3f *b)
Multiply two vectors component by component.
void NegateVectorInPlace(Vec3f *v)
Negate a vector in place.
s32 SegmentCrossesLine2D(const Vec3f *a, const Vec3f *b, const Vec3f *p, const Vec3f *q)
Whether two points lie across the line through two others, seen from above: only x and y are read.
void Vec3fDirection(Vec3f *out, Vec3f *from, Vec3f *to)
The unit vector from one point towards another, or (0, 0, 1) when they coincide.
void Vec3fScaleInPlace(Vec3f *v, f32 scale)
Multiply a vector by a number in place.