Fixed-point trigonometry, matching the engine's own tables. Using these rather than Lua's math library guarantees a script places things exactly where the engine would. trx.math.Angle says what an angle is here.
trx.math.DEG_1 = 182 (trx.math.Angle)
One degree. Multiply by it to say an angle in degrees: 45 * trx.math.DEG_1.
trx.math.DEG_45 = 8192 (trx.math.Angle)
A 45-degree turn.
trx.math.DEG_90 = 16384 (trx.math.Angle)
A quarter turn. A full turn is four of these.
trx.math.WALL_L = 1024 (trx.math.Distance)
The size of one sector. Level geometry is laid out on this grid, so it is the step to take to move an item a sector over.
An angle in the engine's own units, where 65536 is a full turn rather than
2 pi. An angle counts in cycles, so one past the end of a turn wraps round
to name the same direction: adding a half turn to a rotation always works.
trx.math.DEG_1 converts from degrees.
A length in the units the engine measures the world in, where one sector is
trx.math.WALL_L. Y grows downwards, so a greater Y is further down.
A point or a direction in the world.
Properties:
x: trx.math.Distance. The east-west axis.y: trx.math.Distance. The up-down axis.z: trx.math.Distance. The north-south axis.An orientation, as three angles about the world axes.
Properties:
x: trx.math.Angle. Pitch, nose up and down.y: trx.math.Angle. Yaw, the direction it faces.z: trx.math.Angle. Roll, the tilt about its own length.An axis-aligned box. Whether it is placed in the world or in something's own frame is for the call that hands it over to say.
Properties:
max_x: trx.math.Distance. East edge.max_y: trx.math.Distance. Bottom edge.max_z: trx.math.Distance. North edge.min_x: trx.math.Distance. West edge.min_y: trx.math.Distance. Top edge.min_z: trx.math.Distance. South edge.trx.math.sin(angle)
Sine of an angle.
Parameters:
angle (trx.math.Angle).Returns: number. A value in [-1, 1].
trx.math.cos(angle)
Cosine of an angle.
Parameters:
angle (trx.math.Angle).Returns: number. A value in [-1, 1].
trx.math.atan(z, x)
Angle of the vector (x, z).
Parameters:
z (trx.math.Distance). How far the vector reaches north.x (trx.math.Distance). How far it reaches east.Returns: trx.math.Angle.
Example:
-- face an item towards Lara
local angle = trx.math.atan(lara.pos.z - pos.z, lara.pos.x - pos.x)
trx.math.round_to_sector(value)
Snaps a position back to the corner of the sector it stands in, the way the
level's own geometry is laid out. A whole position keeps its height: a sector
is a column, and rounding it is about the ground plan rather than how far up
the position sits. A single coordinate rounds on its own, which is what an axis
at a time needs.
The corner is always the one to the west and the south, on both sides of the origin, so two positions in the same sector always answer with the same corner.
Parameters:
value (trx.math.Vec3 or trx.math.Distance). A world position, or one coordinate of one.Returns: trx.math.Vec3 or trx.math.Distance. The corner of the sector, in whichever of the two came in.
Example:
-- a zone over the sector Lara stands on, a sector tall.
-- y grows downwards, so the ceiling of the box is the lesser y.
local corner = trx.math.round_to_sector(trx.lara.item.pos)
trx.zones.box(corner, {
x = corner.x + trx.math.WALL_L,
y = corner.y - trx.math.WALL_L,
z = corner.z + trx.math.WALL_L,
})