Skip to content

KAI_Math

inkoalawetrust edited this page Jun 20, 2024 · 6 revisions

KAI_Math

KAI_Math is a non-mixin container class, that has several math-related functions stored into it. These functions are all clearscoped and static, allowing them to be called from nearly anywhere in ZScript as needed.

LerpValue()

Parameters:

  • V1, V2: The two values to interpolate between.
  • Time: The span of time to interpolate V1 into V2 over time.

Return type(s):

  • Returns the interpolated value between V1 and V2.

Function:

Linearly interpolates between two values, produce a smoothed blend of the two.

LinearMap()

Parameters:

  • Val: The value to map.
  • O_Min, O_Max, N_Min, N_Max: Information needed.

Return type(s):

  • Returns a linear mapped value as a double.

Function:

Remap Val from the <o_min, o_max> range to the <n_min, n_max> range. (This was written by RaveYard, not me (inkoalwetrust), so I don't know what it means.)

Distance3DLine()

Parameters:

  • A, B: The two Vector3s the line is made out of.
  • C: The coordinate point to check.

Return type(s):

  • How far away C is from the line formed by A and B.

Function:

Creates a line using A and B as the ends. Then calculates the lines' distance from C.

Vec3OffsetRelative()

Parameters:

  • Other: The actor to offset from.
  • Offs: The offsets relative to the Other actor.
  • NoPortal: Should the function not account for static portals ? Default is false.
  • Flags: The flags to pass to the function.
    • V3R_NOANGLE: Do not account for the Other's angle.
    • V3R_NOPITCH: Do not account for the Other's pitch.
    • V3R_NOROLL: Do not account for the Other's roll.
    • V3R_ANGLEONLY: Implies V3R_NOPITCH and V3R_NOROLL. This is what vehicle turrets use to keep themselves attached on their vehicles.

Return type(s):

  • Returns a position coordinate that was offset relative to Other's facing direction.

Function:

This function returns a position relative to the angle that Other is facing, with the specified offsets. This function behaves similarly to the offsets in A_Warp(). In fact, the function is primarily used by the KAI library to act like a cheaper A_Warp() alongside SetOrigin().

Example

If this code is put on an actor class, and the actor has a master, then it will attach itself on top of its' masters' hitbox, 128 units forward relative to the masters' origin, effectively attaching in front of it.

	Override Void Tick()
	{
		Super.Tick();
		If (IsFrozen()) Return;
		If (Master) SetOrigin (KAI_Math.Vec3OffsetRelative(Master,(128,0,Master.Height)),True);
	}

Vec3OffsetRelative2()

Parameters:

  • OtherPos: The actor to offset from.
  • Offs: The offsets relative to OtherPos.
  • Angles: The angle, pitch, roll (In that vector member order) that OtherPos is aimed at towards Offs.
  • NoPortal: Should the function not account for static portals ? Default is false.

Return type(s):

  • Returns a position coordinate that was offset relative to OtherPos and the Angles vector passed to it..

Function:

Works like Vec3OffsetRelative, except that it only works with vector positions, and the aiming direction of OtherPos is directly specified by passing values to Angles.

AngleToVector3D()

Parameters:

  • Angle: The angle to check at.
  • Pitch: The pitch to check at.
  • Len: How far the check extends, default is 1.0.

Return type(s):

  • Returns the Vector3 position that Angle and Pitch are facing at Length map units away.

Function:

Works like the native AngleToVector(), but also accounts for pitch.

IsEmptyVector3()

Parameters:

  • Vec: The vector variable to check

Return type(s):

  • Returns true if Vec is null/NaN, false otherwise.

Function:

This function checks if Vec is null, that is to say, its' value is (Double.NaN,Double.NaN,Double.NaN), or -2147483647 on each member, NOT (0,0,0).

IsZeroVector3()

Parameters:

  • Vec: The vector variable to check

Return type(s):

  • Returns true if all members of Vec are 0, false otherwise.

Function:

Checks if Vec is (0,0,0).

RotateAround()

Parameters:

  • Origin: The non (0,0) origin to rotate Vec around.
  • Vec: The vector to rotate around Origin.
  • Angle: The angle to rotate Vec by.

Return type(s):

  • The Vec rotated X angles around Origin

Function:

Rotates a vector around a relative origin, as opposed to RotateVector(), which only rotates vectors relative to the world origin itself, and which this function is a wrapper for.

Clone this wiki locally