coastline 0.0.4
Loading...
Searching...
No Matches
vecmath.h File Reference

The vector and matrix arithmetic of the game, its arctangent and power, the triangle and segment tests, and its random numbers. More...

#include "common/types.h"
Include dependency graph for vecmath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Vec3f
 A point or direction in space. More...
struct  Vec2f
 A point or direction in a plane. More...

Functions

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 series for the rest.
void Vec3fCross (Vec3f *out, Vec3f *a, Vec3f *b)
 Take the cross product of two vectors.
f32 Vec3fDot (const Vec3f *a, const Vec3f *b)
 Take the dot product of two vectors.
void Vec3fNegate (Vec3f *out, Vec3f *v)
 Negate a vector.
void NegateVectorInPlace (Vec3f *v)
 Negate a vector in place.
void Vec2fMul (Vec2f *out, Vec2f *a, Vec2f *b)
 Multiply two vectors component by component.
void Vec2fScale (Vec2f *out, Vec2f *v, f32 scale)
 Multiply a vector by a number.
void Vec3fComponentProduct (Vec3f *out, Vec3f *a, Vec3f *b)
 Multiply two vectors component by component.
void Vec3fScale (Vec3f *out, Vec3f *v, f32 scale)
 Multiply a vector by a number.
void Vec3fScaleInPlace (Vec3f *v, f32 scale)
 Multiply a vector by a number in place.
void Vec3fScaleByInverse (Vec3f *out, Vec3f *v, f32 divisor)
 Multiply a vector by the reciprocal of a number.
void Vec3fDivideInPlace (Vec3f *v, f32 divisor)
 Divide a vector by a number in place.
void Vec3fCopy (Vec3f *out, Vec3f *v)
 Copy a vector.
void Vec3fDirection (Vec3f *out, Vec3f *from, Vec3f *to)
 The unit vector from one point towards another, or (0, 0, 1) when they coincide.
void Vec3fNormalizeSafe (Vec3f *out, Vec3f *v)
 The unit vector along a vector, or (0, 0, 1) for the zero vector.
void Vec3fNormalize (Vec3f *v)
 Make a vector a unit vector, or (0, 0, 1) if it is the zero vector.
void Vec3fSubtract (Vec3f *out, const Vec3f *a, const Vec3f *b)
 Subtract one vector from another.
void Vec3fSubtractInPlace (Vec3f *v, Vec3f *b)
 Subtract one vector from another in place.
void Vec2fAdd (Vec2f *out, Vec2f *a, Vec2f *b)
 Add two vectors.
void Vec3fAdd (Vec3f *out, Vec3f *a, Vec3f *b)
 Add two vectors.
void Vec3fAddInPlace (Vec3f *v, Vec3f *b)
 Add one vector to another in place.
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 Vec3fMulAdd (Vec3f *out, Vec3f *a, Vec3f *b, f32 scale)
 Add a scaled vector to another.
void Vec3fMulAddInPlace (Vec3f *v, Vec3f *b, f32 scale)
 Add a scaled vector to another in place.
void Vec3fMidpoint (Vec3f *out, Vec3f *a, Vec3f *b)
 The point halfway between two points.
void Vec3fClear (Vec3f *v)
 Set a vector to zero.
f32 Vec2fDistance (Vec2f *a, Vec2f *b)
 The distance between two points of the plane.
f32 Vec3fDistance (Vec3f *a, Vec3f *b)
 The distance between two points.
f32 Vec3fDistanceSquared (Vec3f *a, Vec3f *b)
 The square of the distance between two points.
f32 Vec3fLength (Vec3f *v)
 The length of a vector.
f32 Vec2fLength (Vec2f *v)
 The length of a vector of the plane.
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 Mtx4x4ProjectPoint (Vec3f *out, Vec3f *in, f32 m[4][4])
 Transform a point by a matrix and divide by w.
void Vec3fTransformByMatrix (f32 out[4], const Vec3f *in, f32 m[4][4])
 Transform a point by a matrix into four components.
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 Mtx4x4TransformNoTranslation (Vec3f *out, Vec3f *in, f32 m[4][4])
 Transform a direction by a matrix without its translation, and divide by w.
void Mtx3x3TransformVec (Vec3f *out, Vec3f *in, f32 m[4][4])
 Transform a direction by the 3 by 3 part of a matrix.
void Mtx4x4Multiply (f32 out[4][4], f32 a[4][4], f32 b[4][4])
 Multiply two matrices.
void Mtx4fTranspose (f32 out[4][4], f32 in[4][4])
 Transpose a matrix but its diagonal, which is copied unchanged into the result.
void CopyMatrix4x4 (f32 out[4][4], f32 in[4][4])
 Copy a matrix.
s32 MtxInvert4x4 (f32 out[4][4], f32 in[4][4])
 Invert an affine matrix.
void FinishFrameMatrix (f32 m[4][4])
 Set the last column of a matrix to that of an affine transform: 0, 0, 0 and 1.
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 sine.
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.
s32 IsPointInsideTriangle (Vec3f *point, Vec3f *v0, Vec3f *v1, Vec3f *v2, Vec3f *normal, f32 tolerance)
 PointInTriangle3D() with a tolerance for each edge.
s32 TestLineSegmentIntersection (Vec2f *p1, Vec2f *p2, Vec2f *q1, Vec2f *q2)
 Whether two segments of the plane meet.
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 SetRngSeed (u32 seed)
 Set the seed of the random numbers.
u32 AdvanceRng (void)
 Advance the random numbers by the multiplier 16807 and retain 27 bits.

Variables

u32 g_dwRandomSeed
 The seed used by the game's pseudorandom number generator.

Detailed Description

The vector and matrix arithmetic of the game, its arctangent and power, the triangle and segment tests, and its random numbers.

Function Documentation

◆ Powf()

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 series for the rest.

Parameters
baseThe number raised.
exponentThe power, at least 0.
Returns
The base raised to the exponent.
Ghidra address:
USA: 0x802242e0
Ghidra address:
Asia: 0x80223E30
Ghidra address:
EUR: 0x80225620
Ghidra address:
JPN: 0x80224e10

◆ Vec3fCross()

void Vec3fCross ( Vec3f * out,
Vec3f * a,
Vec3f * b )

Take the cross product of two vectors.

Parameters
outThe vector that receives the cross product of a and b.
aThe first vector.
bThe second vector.
Ghidra address:
USA: 0x8022439c
Ghidra address:
Asia: 0x80223EEC
Ghidra address:
EUR: 0x802256dc
Ghidra address:
JPN: 0x80224ecc
Ghidra address:
BRD3D: 0x1003ac30
Ghidra address:
BRGlide: 0x100342b0

◆ Vec3fDot()

f32 Vec3fDot ( const Vec3f * a,
const Vec3f * b )

Take the dot product of two vectors.

Parameters
aThe first vector.
bThe second vector.
Returns
The dot product of the vectors.
Ghidra address:
USA: 0x80224404
Ghidra address:
Asia: 0x80223F54
Ghidra address:
EUR: 0x80225744
Ghidra address:
JPN: 0x80224f34
Ghidra address:
BRD3D: 0x1003ac90
Ghidra address:
BRGlide: 0x10034310

◆ Vec3fNegate()

void Vec3fNegate ( Vec3f * out,
Vec3f * v )

Negate a vector.

Parameters
outThe vector that receives -v.
vThe vector negated.
Ghidra address:
USA: 0x80224434
Ghidra address:
Asia: 0x80223F84
Ghidra address:
EUR: 0x80225774
Ghidra address:
JPN: 0x80224f64
Ghidra address:
BRD3D: 0x1003acc0
Ghidra address:
BRGlide: 0x10034340

◆ NegateVectorInPlace()

void NegateVectorInPlace ( Vec3f * v)

Negate a vector in place.

Parameters
vThe vector negated.
Ghidra address:
USA: 0x8022445c
Ghidra address:
Asia: 0x80223FAC
Ghidra address:
EUR: 0x8022579c
Ghidra address:
JPN: 0x80224f8c

◆ Vec2fMul()

void Vec2fMul ( Vec2f * out,
Vec2f * a,
Vec2f * b )

Multiply two vectors component by component.

Parameters
outThe vector that receives the product.
aThe first vector.
bThe second vector.
Ghidra address:
USA: 0x80224484
Ghidra address:
Asia: 0x80223FD4
Ghidra address:
EUR: 0x802257c4
Ghidra address:
JPN: 0x80224fb4

◆ Vec2fScale()

void Vec2fScale ( Vec2f * out,
Vec2f * v,
f32 scale )

Multiply a vector by a number.

Parameters
outThe vector that receives v * scale.
vThe vector scaled.
scaleThe factor.
Ghidra address:
USA: 0x802244a8
Ghidra address:
Asia: 0x80223FF8
Ghidra address:
EUR: 0x802257e8
Ghidra address:
JPN: 0x80224fd8

◆ Vec3fComponentProduct()

void Vec3fComponentProduct ( Vec3f * out,
Vec3f * a,
Vec3f * b )

Multiply two vectors component by component.

Parameters
outThe vector that receives the product.
aThe first vector.
bThe second vector.
Ghidra address:
USA: 0x802244c8
Ghidra address:
Asia: 0x80224018
Ghidra address:
EUR: 0x80225808
Ghidra address:
JPN: 0x80224ff8

◆ Vec3fScale()

void Vec3fScale ( Vec3f * out,
Vec3f * v,
f32 scale )

Multiply a vector by a number.

Parameters
outThe vector that receives v * scale.
vThe vector scaled.
scaleThe factor.
Ghidra address:
USA: 0x802244fc
Ghidra address:
Asia: 0x8022404C
Ghidra address:
EUR: 0x8022583c
Ghidra address:
JPN: 0x8022502c
Ghidra address:
BRD3D: 0x1003ace0
Ghidra address:
BRGlide: 0x10034360

◆ Vec3fScaleInPlace()

void Vec3fScaleInPlace ( Vec3f * v,
f32 scale )

Multiply a vector by a number in place.

Parameters
vThe vector scaled.
scaleThe factor.
Ghidra address:
USA: 0x80224528
Ghidra address:
Asia: 0x80224078
Ghidra address:
EUR: 0x80225868
Ghidra address:
JPN: 0x80225058
Ghidra address:
BRD3D: 0x1003ad10
Ghidra address:
BRGlide: 0x10034390

◆ Vec3fScaleByInverse()

void Vec3fScaleByInverse ( Vec3f * out,
Vec3f * v,
f32 divisor )

Multiply a vector by the reciprocal of a number.

Parameters
outThe vector that receives v / divisor.
vThe vector divided.
divisorThe number the vector is divided by.
Ghidra address:
USA: 0x8022455c
Ghidra address:
Asia: 0x802240AC
Ghidra address:
EUR: 0x8022589c
Ghidra address:
JPN: 0x8022508c
Ghidra address:
BRD3D: 0x1003ad40
Ghidra address:
BRGlide: 0x100343c0

◆ Vec3fDivideInPlace()

void Vec3fDivideInPlace ( Vec3f * v,
f32 divisor )

Divide a vector by a number in place.

Parameters
vThe vector divided.
divisorThe number the vector is divided by.
Ghidra address:
USA: 0x80224594
Ghidra address:
Asia: 0x802240E4
Ghidra address:
EUR: 0x802258d4
Ghidra address:
JPN: 0x802250c4
Ghidra address:
BRD3D: 0x1003ad70
Ghidra address:
BRGlide: 0x100343f0

◆ Vec3fCopy()

void Vec3fCopy ( Vec3f * out,
Vec3f * v )

Copy a vector.

Parameters
outThe vector that receives the copy.
vThe vector copied.
Ghidra address:
USA: 0x802245d4
Ghidra address:
Asia: 0x80224124
Ghidra address:
EUR: 0x80225914
Ghidra address:
JPN: 0x80225104
Ghidra address:
BRD3D: 0x10035c70
Ghidra address:
BRGlide: 0x1002f310

◆ Vec3fDirection()

void Vec3fDirection ( Vec3f * out,
Vec3f * from,
Vec3f * to )

The unit vector from one point towards another, or (0, 0, 1) when they coincide.

Parameters
outThe vector that receives the direction.
fromThe point the direction starts at.
toThe point the direction runs towards.
Ghidra address:
USA: 0x802245f0
Ghidra address:
Asia: 0x80224140
Ghidra address:
EUR: 0x80225930
Ghidra address:
JPN: 0x80225120
Ghidra address:
BRD3D: 0x1003ada0
Ghidra address:
BRGlide: 0x10034420

◆ Vec3fNormalizeSafe()

void Vec3fNormalizeSafe ( Vec3f * out,
Vec3f * v )

The unit vector along a vector, or (0, 0, 1) for the zero vector.

Parameters
outThe vector that receives the unit vector.
vThe vector normalised.
Ghidra address:
USA: 0x802246bc
Ghidra address:
Asia: 0x8022420C
Ghidra address:
EUR: 0x802259fc
Ghidra address:
JPN: 0x802251ec

◆ Vec3fNormalize()

void Vec3fNormalize ( Vec3f * v)

Make a vector a unit vector, or (0, 0, 1) if it is the zero vector.

Windows also uses that direction when the length is unordered.

Parameters
vThe vector normalised in place.
Ghidra address:
USA: 0x80224760
Ghidra address:
Asia: 0x802242B0
Ghidra address:
EUR: 0x80225aa0
Ghidra address:
JPN: 0x80225290
Ghidra address:
BRD3D: 0x1003ae50
Ghidra address:
BRGlide: 0x100344d0

◆ Vec3fSubtract()

void Vec3fSubtract ( Vec3f * out,
const Vec3f * a,
const Vec3f * b )

Subtract one vector from another.

Parameters
outThe vector that receives a - b.
aThe vector subtracted from.
bThe vector subtracted.
Ghidra address:
USA: 0x80224808
Ghidra address:
Asia: 0x80224358
Ghidra address:
EUR: 0x80225b48
Ghidra address:
JPN: 0x80225338
Ghidra address:
BRD3D: 0x1003aee0
Ghidra address:
BRGlide: 0x10034560

◆ Vec3fSubtractInPlace()

void Vec3fSubtractInPlace ( Vec3f * v,
Vec3f * b )

Subtract one vector from another in place.

Parameters
vThe vector subtracted from, which receives v - b.
bThe vector subtracted.
Ghidra address:
USA: 0x8022483c
Ghidra address:
Asia: 0x8022438C
Ghidra address:
EUR: 0x80225b7c
Ghidra address:
JPN: 0x8022536c
Ghidra address:
BRD3D: 0x1003af10
Ghidra address:
BRGlide: 0x10034590

◆ Vec2fAdd()

void Vec2fAdd ( Vec2f * out,
Vec2f * a,
Vec2f * b )

Add two vectors.

Parameters
outThe vector that receives a + b.
aThe first vector.
bThe second vector.
Ghidra address:
USA: 0x80224870
Ghidra address:
Asia: 0x802243C0
Ghidra address:
EUR: 0x80225bb0
Ghidra address:
JPN: 0x802253a0

◆ Vec3fAdd()

void Vec3fAdd ( Vec3f * out,
Vec3f * a,
Vec3f * b )

Add two vectors.

Parameters
outThe vector that receives a + b.
aThe first vector.
bThe second vector.
Ghidra address:
USA: 0x80224894
Ghidra address:
Asia: 0x802243E4
Ghidra address:
EUR: 0x80225bd4
Ghidra address:
JPN: 0x802253c4
Ghidra address:
BRD3D: 0x1003af40
Ghidra address:
BRGlide: 0x100345c0

◆ Vec3fAddInPlace()

void Vec3fAddInPlace ( Vec3f * v,
Vec3f * b )

Add one vector to another in place.

Parameters
vThe vector added to, which receives v + b.
bThe vector added.
Ghidra address:
USA: 0x802248c8
Ghidra address:
Asia: 0x80224418
Ghidra address:
EUR: 0x80225c08
Ghidra address:
JPN: 0x802253f8
Ghidra address:
BRD3D: 0x1003af70
Ghidra address:
BRGlide: 0x100345f0

◆ Vec3fLerp()

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.

Parameters
outThe vector that receives the point.
aThe point reached when t is 1.
bThe point reached when t is 0.
tThe share of the way from b to a.
Ghidra address:
USA: 0x802248fc
Ghidra address:
Asia: 0x8022444C
Ghidra address:
EUR: 0x80225c3c
Ghidra address:
JPN: 0x8022542c
Ghidra address:
BRD3D: 0x1003afa0
Ghidra address:
BRGlide: 0x10034620

◆ Vec3fMulAdd()

void Vec3fMulAdd ( Vec3f * out,
Vec3f * a,
Vec3f * b,
f32 scale )

Add a scaled vector to another.

Parameters
outThe vector that receives a + b * scale.
aThe vector added to.
bThe vector scaled and added.
scaleThe factor for b.
Ghidra address:
USA: 0x8022494c
Ghidra address:
Asia: 0x8022449C
Ghidra address:
EUR: 0x80225c8c
Ghidra address:
JPN: 0x8022547c
Ghidra address:
BRD3D: 0x1003afe0
Ghidra address:
BRGlide: 0x10034660

◆ Vec3fMulAddInPlace()

void Vec3fMulAddInPlace ( Vec3f * v,
Vec3f * b,
f32 scale )

Add a scaled vector to another in place.

Parameters
vThe vector added to, which receives v + b * scale.
bThe vector scaled and added.
scaleThe factor for b.
Ghidra address:
USA: 0x80224990
Ghidra address:
Asia: 0x802244E0
Ghidra address:
EUR: 0x80225cd0
Ghidra address:
JPN: 0x802254c0
Ghidra address:
BRD3D: 0x1003b020
Ghidra address:
BRGlide: 0x100346a0

◆ Vec3fMidpoint()

void Vec3fMidpoint ( Vec3f * out,
Vec3f * a,
Vec3f * b )

The point halfway between two points.

Parameters
outThe vector that receives the midpoint.
aThe first point.
bThe second point.
Ghidra address:
USA: 0x802249d4
Ghidra address:
Asia: 0x80224524
Ghidra address:
EUR: 0x80225d14
Ghidra address:
JPN: 0x80225504
Ghidra address:
BRD3D: 0x1003b050
Ghidra address:
BRGlide: 0x100346d0

◆ Vec3fClear()

void Vec3fClear ( Vec3f * v)

Set a vector to zero.

Parameters
vThe vector cleared.
Ghidra address:
USA: 0x80224a1c
Ghidra address:
Asia: 0x8022456C
Ghidra address:
EUR: 0x80225d5c
Ghidra address:
JPN: 0x8022554c
Ghidra address:
BRD3D: 0x1003b090
Ghidra address:
BRGlide: 0x10034710

◆ Vec2fDistance()

f32 Vec2fDistance ( Vec2f * a,
Vec2f * b )

The distance between two points of the plane.

Parameters
aThe first point.
bThe second point.
Returns
The distance between the points.
Ghidra address:
USA: 0x80224a34
Ghidra address:
Asia: 0x80224584
Ghidra address:
EUR: 0x80225d74
Ghidra address:
JPN: 0x80225564
Ghidra address:
BRD3D: 0x1003b0a0
Ghidra address:
BRGlide: 0x10034720

◆ Vec3fDistance()

f32 Vec3fDistance ( Vec3f * a,
Vec3f * b )

The distance between two points.

Parameters
aThe first point.
bThe second point.
Returns
The distance between the points.
Ghidra address:
USA: 0x80224a78
Ghidra address:
Asia: 0x802245C8
Ghidra address:
EUR: 0x80225db8
Ghidra address:
JPN: 0x802255a8

◆ Vec3fDistanceSquared()

f32 Vec3fDistanceSquared ( Vec3f * a,
Vec3f * b )

The square of the distance between two points.

Parameters
aThe first point.
bThe second point.
Returns
The squared distance between the points.
Ghidra address:
USA: 0x80224acc
Ghidra address:
Asia: 0x8022461C
Ghidra address:
EUR: 0x80225e0c
Ghidra address:
JPN: 0x802255fc
Ghidra address:
BRD3D: 0x1003b130
Ghidra address:
BRGlide: 0x100347b0

◆ Vec3fLength()

f32 Vec3fLength ( Vec3f * v)

The length of a vector.

Parameters
vThe vector measured.
Returns
The length of the vector.
Ghidra address:
USA: 0x80224b08
Ghidra address:
Asia: 0x80224658
Ghidra address:
EUR: 0x80225e48
Ghidra address:
JPN: 0x80225638
Ghidra address:
BRD3D: 0x1003b170
Ghidra address:
BRGlide: 0x100347f0

◆ Vec2fLength()

f32 Vec2fLength ( Vec2f * v)

The length of a vector of the plane.

Parameters
vThe vector measured.
Returns
The length of the vector.
Ghidra address:
USA: 0x80224b48
Ghidra address:
Asia: 0x80224698
Ghidra address:
EUR: 0x80225e88
Ghidra address:
JPN: 0x80225678
Ghidra address:
BRD3D: 0x1003b1c0
Ghidra address:
BRGlide: 0x10034840

◆ Vec3fRotateAroundAxis()

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.

Parameters
vThe vector rotated in place.
angleThe angle of the rotation, in radians.
axisThe unit axis of the rotation.
Ghidra address:
USA: 0x80224b7c
Ghidra address:
Asia: 0x802246CC
Ghidra address:
EUR: 0x80225ebc
Ghidra address:
JPN: 0x802256ac

◆ Mtx4x4ProjectPoint()

void Mtx4x4ProjectPoint ( Vec3f * out,
Vec3f * in,
f32 m[4][4] )

Transform a point by a matrix and divide by w.

Parameters
outThe vector that receives the transformed point.
inThe point transformed.
mThe matrix, applied to a row vector with its translation in the last row.
Ghidra address:
USA: 0x80224d00
Ghidra address:
Asia: 0x80224850
Ghidra address:
EUR: 0x80226040
Ghidra address:
JPN: 0x80225830
Ghidra address:
BRD3D: 0x1003b1f0
Ghidra address:
BRGlide: 0x10034870

◆ Vec3fTransformByMatrix()

void Vec3fTransformByMatrix ( f32 out[4],
const Vec3f * in,
f32 m[4][4] )

Transform a point by a matrix into four components.

Parameters
outThe x, y, z, and w of the transformed point.
inThe point transformed.
mThe matrix, applied to a row vector with its translation in the last row.
Ghidra address:
USA: 0x80224ddc
Ghidra address:
Asia: 0x8022492C
Ghidra address:
EUR: 0x8022611c
Ghidra address:
JPN: 0x8022590c
Ghidra address:
BRD3D: 0x1003b2a0
Ghidra address:
BRGlide: 0x10034920

◆ Vec3sTransformToVec4f()

void Vec3sTransformToVec4f ( f32 out[4],
s16 in[3],
f32 m[4][4] )

Transform a point of short integers by a matrix into four components.

Parameters
outThe x, y, z, and w of the transformed point.
inThe x, y, and z of the point transformed.
mThe matrix, applied to a row vector with its translation in the last row.
Ghidra address:
USA: 0x80224ea8
Ghidra address:
Asia: 0x802249F8
Ghidra address:
EUR: 0x802261e8
Ghidra address:
JPN: 0x802259d8

◆ ProjectVec3fToScreen()

void ProjectVec3fToScreen ( Vec2f * out,
Vec3f * in,
f32 m[4][4] )

Transform a point by a matrix, divide by w, and retain x and y.

Parameters
outThe vector that receives the x and y of the transformed point.
inThe point transformed.
mThe matrix, applied to a row vector with its translation in the last row.
Ghidra address:
USA: 0x80224f90
Ghidra address:
Asia: 0x80224AE0
Ghidra address:
EUR: 0x802262d0
Ghidra address:
JPN: 0x80225ac0

◆ Mtx4x4TransformNoTranslation()

void Mtx4x4TransformNoTranslation ( Vec3f * out,
Vec3f * in,
f32 m[4][4] )

Transform a direction by a matrix without its translation, and divide by w.

Parameters
outThe vector that receives the transformed direction.
inThe direction transformed.
mThe matrix, applied to a row vector.
Ghidra address:
USA: 0x80225038
Ghidra address:
Asia: 0x80224B88
Ghidra address:
EUR: 0x80226378
Ghidra address:
JPN: 0x80225b68
Ghidra address:
BRD3D: 0x1003b340
Ghidra address:
BRGlide: 0x100349c0

◆ Mtx3x3TransformVec()

void Mtx3x3TransformVec ( Vec3f * out,
Vec3f * in,
f32 m[4][4] )

Transform a direction by the 3 by 3 part of a matrix.

Parameters
outThe vector that receives the transformed direction.
inThe direction transformed.
mThe matrix, applied to a row vector.
Ghidra address:
USA: 0x802250fc
Ghidra address:
Asia: 0x80224C4C
Ghidra address:
EUR: 0x8022643c
Ghidra address:
JPN: 0x80225c2c
Ghidra address:
BRD3D: 0x1003b3f0
Ghidra address:
BRGlide: 0x10034a70

◆ Mtx4x4Multiply()

void Mtx4x4Multiply ( f32 out[4][4],
f32 a[4][4],
f32 b[4][4] )

Multiply two matrices.

The result may replace either of them.

Parameters
outThe matrix that receives a * b.
aThe matrix on the left.
bThe matrix on the right.
Ghidra address:
USA: 0x80225180
Ghidra address:
Asia: 0x80224CD0
Ghidra address:
EUR: 0x802264c0
Ghidra address:
JPN: 0x80225cb0
Ghidra address:
BRD3D: 0x1003b470
Ghidra address:
BRGlide: 0x10034af0

◆ Mtx4fTranspose()

void Mtx4fTranspose ( f32 out[4][4],
f32 in[4][4] )

Transpose a matrix but its diagonal, which is copied unchanged into the result.

Parameters
outThe matrix that receives the transpose.
inThe matrix transposed.
Ghidra address:
USA: 0x802252ec
Ghidra address:
Asia: 0x80224E3C
Ghidra address:
EUR: 0x8022662c
Ghidra address:
JPN: 0x80225e1c

◆ CopyMatrix4x4()

void CopyMatrix4x4 ( f32 out[4][4],
f32 in[4][4] )

Copy a matrix.

Parameters
outThe matrix that receives the copy.
inThe matrix copied.
Ghidra address:
USA: 0x80225350
Ghidra address:
Asia: 0x80224EA0
Ghidra address:
EUR: 0x80226690
Ghidra address:
JPN: 0x80225e80
Ghidra address:
BRD3D: 0x100307a0
Ghidra address:
BRGlide: 0x10029e50

◆ MtxInvert4x4()

s32 MtxInvert4x4 ( f32 out[4][4],
f32 in[4][4] )

Invert an affine matrix.

On the N64 a singular matrix is reported on the debug display and out is not written. On the PC a singular matrix inverts to the identity.

Parameters
outThe matrix that receives the inverse.
inThe matrix inverted.
Returns
1 once inverted. On the N64, 0 for a singular matrix.
Ghidra address:
USA: 0x80225370
Ghidra address:
Asia: 0x80224EC0
Ghidra address:
EUR: 0x802266b0
Ghidra address:
JPN: 0x80225ea0
Ghidra address:
BRD3D: 0x1003b4f0
Ghidra address:
BRGlide: 0x10034b70

◆ FinishFrameMatrix()

void FinishFrameMatrix ( f32 m[4][4])

Set the last column of a matrix to that of an affine transform: 0, 0, 0 and 1.

Parameters
mThe matrix completed in place.
Ghidra address:
USA: 0x8021eb30
Ghidra address:
Asia: 0x8021E680
Ghidra address:
EUR: 0x8021fe30
Ghidra address:
JPN: 0x8021f620
Ghidra address:
BRD3D: 0x10075340
Ghidra address:
BRGlide: 0x1006e5a0

◆ Atan2f()

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 sine.

Unlike atan2() of the C library, it takes x first.

Parameters
xThe x of the point.
yThe y of the point.
Returns
The angle in radians, or 0 for the origin.
Ghidra address:
USA: 0x8022576c
Ghidra address:
Asia: 0x802252BC
Ghidra address:
EUR: 0x80226aac
Ghidra address:
JPN: 0x8022629c
Ghidra address:
BRD3D: 0x1003b7b0
Ghidra address:
BRGlide: 0x10034e30

◆ PointInTriangle3D()

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.

Parameters
pointThe point tested.
v0The first corner of the triangle.
v1The second corner of the triangle.
v2The third corner of the triangle.
normalThe normal of the triangle.
Returns
TRUE if the point lies within the triangle, FALSE otherwise.
Ghidra address:
USA: 0x8022591c
Ghidra address:
Asia: 0x8022546C
Ghidra address:
EUR: 0x80226c5c
Ghidra address:
JPN: 0x8022644c
Ghidra address:
BRD3D: 0x1003b940
Ghidra address:
BRGlide: 0x10034fc0

◆ IsPointInsideTriangle()

s32 IsPointInsideTriangle ( Vec3f * point,
Vec3f * v0,
Vec3f * v1,
Vec3f * v2,
Vec3f * normal,
f32 tolerance )

PointInTriangle3D() with a tolerance for each edge.

Parameters
pointThe point tested.
v0The first corner of the triangle.
v1The second corner of the triangle.
v2The third corner of the triangle.
normalThe normal of the triangle.
toleranceThe least value of the test against each edge for the point to pass it.
Returns
TRUE if the point passes the test against every edge, FALSE otherwise.
Ghidra address:
USA: 0x80225a40
Ghidra address:
Asia: 0x80225590
Ghidra address:
EUR: 0x80226d80
Ghidra address:
JPN: 0x80226570

◆ TestLineSegmentIntersection()

s32 TestLineSegmentIntersection ( Vec2f * p1,
Vec2f * p2,
Vec2f * q1,
Vec2f * q2 )

Whether two segments of the plane meet.

Parameters
p1The first end of the first segment.
p2The second end of the first segment.
q1The first end of the second segment.
q2The second end of the second segment.
Returns
0 if they do not, 2 if they lie along one line, and 1 if they cross.
Ghidra address:
USA: 0x80225b64
Ghidra address:
Asia: 0x802256B4
Ghidra address:
EUR: 0x80226ea4
Ghidra address:
JPN: 0x80226694
Ghidra address:
BRD3D: 0x1003ba70
Ghidra address:
BRGlide: 0x100350f0

◆ SegmentCrossesLine2D()

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.

Parameters
aThe first point of the line.
bThe second point of the line.
pThe first point tested.
qThe second point tested.
Returns
0 if they lie strictly on one side, 2 if both lie on the line, and 1 otherwise.
Ghidra address:
USA: 0x80225e1c
Ghidra address:
Asia: 0x8022596C
Ghidra address:
EUR: 0x8022715c
Ghidra address:
JPN: 0x8022694c
Ghidra address:
BRD3D: 0x1003bc90
Ghidra address:
BRGlide: 0x10035310

◆ SetRngSeed()

void SetRngSeed ( u32 seed)

Set the seed of the random numbers.

Parameters
seedThe new seed.
Ghidra address:
USA: 0x80225ed8
Ghidra address:
Asia: 0x80225A28
Ghidra address:
EUR: 0x80227218
Ghidra address:
JPN: 0x80226a08
Ghidra address:
BRD3D: 0x1003bd40
Ghidra address:
BRGlide: 0x100353c0

◆ AdvanceRng()

u32 AdvanceRng ( void )

Advance the random numbers by the multiplier 16807 and retain 27 bits.

Returns
The new seed, from 0 to 0x7ffffff.
Ghidra address:
USA: 0x80225ee4
Ghidra address:
Asia: 0x80225A34
Ghidra address:
EUR: 0x80227224
Ghidra address:
JPN: 0x80226a14
Ghidra address:
BRD3D: 0x1003bd50
Ghidra address:
BRGlide: 0x100353d0

Variable Documentation

◆ g_dwRandomSeed

u32 g_dwRandomSeed
extern

The seed used by the game's pseudorandom number generator.

Ghidra address:
USA: 0x8028b790
Ghidra address:
Asia: 0x8028B2E0
Ghidra address:
EUR: 0x8028da40
Ghidra address:
JPN: 0x8028d470
Ghidra address:
BRD3D: 0x10a9bfd0
Ghidra address:
BRGlide: 0x10ac3060