<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://df-21.net/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lucius</id>
	<title>DF21 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://df-21.net/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lucius"/>
	<link rel="alternate" type="text/html" href="https://df-21.net/wiki/?title=Special:Contributions/Lucius"/>
	<updated>2026-05-12T08:28:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1463</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1463"/>
		<updated>2024-12-15T02:29:37Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&lt;br /&gt;
float2x2 rot2x2 = math.rotationMatrix2x2(angle);&lt;br /&gt;
float3x3 rot3x3 = math.rotationMatrix3x3(pitch, yaw, roll);&lt;br /&gt;
// Transform a 2D point.&lt;br /&gt;
float2 point;&lt;br /&gt;
float2 pivot; // center point of rotation.&lt;br /&gt;
float2 rotatedPoint = rot2x2 * (point - pivot) + pivot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!Constant&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|float pi&lt;br /&gt;
|value of π&lt;br /&gt;
|-&lt;br /&gt;
|float twoPi&lt;br /&gt;
|value of 2*π&lt;br /&gt;
|-&lt;br /&gt;
|float e&lt;br /&gt;
|value of the natural number e&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Math Functions ==&lt;br /&gt;
=== countBits(x) ===&lt;br /&gt;
Counts the number of bits in an integer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int countBits(uint)&lt;br /&gt;
int countBits(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== findLSB(x) ===&lt;br /&gt;
Return the Least Significant Bit of the integer &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int findLSB(uint)&lt;br /&gt;
int findLSB(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== findMSB(x) ===&lt;br /&gt;
Return the Most Significant Bit of the integer &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int findMSB(uint)&lt;br /&gt;
int findMSB(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== abs(x) ===&lt;br /&gt;
Returns the absolute value of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int abs(int)&lt;br /&gt;
float abs(float)&lt;br /&gt;
float2 abs(float2)&lt;br /&gt;
float3 abs(float3)&lt;br /&gt;
float4 abs(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== all(x) ===&lt;br /&gt;
Returns true if all components are non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool all(float)&lt;br /&gt;
bool all(float2)&lt;br /&gt;
bool all(float3)&lt;br /&gt;
bool all(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== any(x) ===&lt;br /&gt;
Returns true if any component is non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool any(float)&lt;br /&gt;
bool any(float2)&lt;br /&gt;
bool any(float3)&lt;br /&gt;
bool any(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== acos(x) ===&lt;br /&gt;
Arccosine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float acos(float)&lt;br /&gt;
float2 acos(float2)&lt;br /&gt;
float3 acos(float3)&lt;br /&gt;
float4 acos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== asin(x) ===&lt;br /&gt;
Arcsine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float asin(float)&lt;br /&gt;
float2 asin(float2)&lt;br /&gt;
float3 asin(float3)&lt;br /&gt;
float4 asin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan(x) ===&lt;br /&gt;
Arctangent of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan(float)&lt;br /&gt;
float2 atan(float2)&lt;br /&gt;
float3 atan(float3)&lt;br /&gt;
float4 atan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan2(y, x) ===&lt;br /&gt;
Returns the angle θ between the positive x-axis and the ray from the origin to the point (x, y), confined to (−π, π].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan2(float, float)&lt;br /&gt;
float2 atan2(float2, float2)&lt;br /&gt;
float3 atan2(float3, float3)&lt;br /&gt;
float4 atan2(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cos(x) ===&lt;br /&gt;
Computes the cosine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float cos(float)&lt;br /&gt;
float2 cos(float2)&lt;br /&gt;
float3 cos(float3)&lt;br /&gt;
float4 cos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sin(x) ===&lt;br /&gt;
Computes the sine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sin(float)&lt;br /&gt;
float2 sin(float2)&lt;br /&gt;
float3 sin(float3)&lt;br /&gt;
float4 sin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tan(x) ===&lt;br /&gt;
Computes the tangent of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float tan(float)&lt;br /&gt;
float2 tan(float2)&lt;br /&gt;
float3 tan(float3)&lt;br /&gt;
float4 tan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sincos(x) ===&lt;br /&gt;
Compute the sine of the input angle and store it in x, and cosine of the angle in y.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 sincos(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== degrees(x) ===&lt;br /&gt;
Converts from radians to degrees, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float degrees(float)&lt;br /&gt;
float2 degrees(float2)&lt;br /&gt;
float3 degrees(float3)&lt;br /&gt;
float4 degrees(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== radians(x) ===&lt;br /&gt;
Converts from degrees to radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float radians(float)&lt;br /&gt;
float2 radians(float2)&lt;br /&gt;
float3 radians(float3)&lt;br /&gt;
float4 radians(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp(x) ===&lt;br /&gt;
Computes the natural number &#039;&#039;&#039;e&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp(float)&lt;br /&gt;
float2 exp(float2)&lt;br /&gt;
float3 exp(float3)&lt;br /&gt;
float4 exp(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp2(x) ===&lt;br /&gt;
Computes &#039;&#039;&#039;2&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp2(float)&lt;br /&gt;
float2 exp2(float2)&lt;br /&gt;
float3 exp2(float3)&lt;br /&gt;
float4 exp2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log(x) ===&lt;br /&gt;
Computes the natural (base &#039;&#039;&#039;e&#039;&#039;&#039;) logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log(float)&lt;br /&gt;
float2 log(float2)&lt;br /&gt;
float3 log(float3)&lt;br /&gt;
float4 log(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log2(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;2&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log2(float)&lt;br /&gt;
float2 log2(float2)&lt;br /&gt;
float3 log2(float3)&lt;br /&gt;
float4 log2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log10(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;10&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log10(float)&lt;br /&gt;
float2 log10(float2)&lt;br /&gt;
float3 log10(float3)&lt;br /&gt;
float4 log10(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== pow(x, y) ===&lt;br /&gt;
Compute the power of &#039;&#039;&#039;x&#039;&#039;&#039; to the power of &#039;&#039;&#039;y&#039;&#039;&#039; (x^y).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float pow(float, float)&lt;br /&gt;
float2 pow(float2, float)&lt;br /&gt;
float2 pow(float2, float2)&lt;br /&gt;
float3 pow(float3, float)&lt;br /&gt;
float3 pow(float3, float3)&lt;br /&gt;
float4 pow(float4, float)&lt;br /&gt;
float4 pow(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== floor(x) ===&lt;br /&gt;
Rounds the input down to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float floor(float)&lt;br /&gt;
float2 floor(float2)&lt;br /&gt;
float3 floor(float3)&lt;br /&gt;
float4 floor(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ceil(x) ===&lt;br /&gt;
Rounds the input up to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float ceil(float)&lt;br /&gt;
float2 ceil(float2)&lt;br /&gt;
float3 ceil(float3)&lt;br /&gt;
float4 ceil(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== fract(x) ===&lt;br /&gt;
Extract the signed fractional part of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float fract(float)&lt;br /&gt;
float2 fract(float2)&lt;br /&gt;
float3 fract(float3)&lt;br /&gt;
float4 fract(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== max(x, y) ===&lt;br /&gt;
Returns the maximum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float max(float, float)&lt;br /&gt;
float2 max(float2, float)&lt;br /&gt;
float2 max(float2, float2)&lt;br /&gt;
float3 max(float3, float)&lt;br /&gt;
float3 max(float3, float3)&lt;br /&gt;
float4 max(float4, float)&lt;br /&gt;
float4 max(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== min(x, y) ===&lt;br /&gt;
Returns the minimum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float min(float, float)&lt;br /&gt;
float2 min(float2, float)&lt;br /&gt;
float2 min(float2, float2)&lt;br /&gt;
float3 min(float3, float)&lt;br /&gt;
float3 min(float3, float3)&lt;br /&gt;
float4 min(float4, float)&lt;br /&gt;
float4 min(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== clamp(x, a, b) ===&lt;br /&gt;
Returns &#039;&#039;&#039;x&#039;&#039;&#039; clamped to the range of &#039;&#039;&#039;[a,b]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float clamp(float, float, float)&lt;br /&gt;
float2 clamp(float2, float, float)&lt;br /&gt;
float2 clamp(float2, float2, float2)&lt;br /&gt;
float3 clamp(float3, float, float)&lt;br /&gt;
float3 clamp(float3, float3, float3)&lt;br /&gt;
float4 clamp(float4, float, float)&lt;br /&gt;
float4 clamp(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== saturate(x) ===&lt;br /&gt;
Clamps the &#039;&#039;&#039;x&#039;&#039;&#039; to the range of &#039;&#039;&#039;[0,1]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float saturate(float)&lt;br /&gt;
float2 saturate(float2)&lt;br /&gt;
float3 saturate(float3)&lt;br /&gt;
float4 saturate(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mix(x, y, a) ===&lt;br /&gt;
Uses &#039;&#039;&#039;a&#039;&#039;&#039; to linearly interpolate between &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;, if &#039;&#039;&#039;a == 0&#039;&#039;&#039; the result is &#039;&#039;&#039;x&#039;&#039;&#039;, if &#039;&#039;&#039;a == 1&#039;&#039;&#039; the result is &#039;&#039;&#039;y&#039;&#039;&#039;, in-between is a mix of &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;. Operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float mix(float, float, float)&lt;br /&gt;
float2 mix(float2, float2, float)&lt;br /&gt;
float2 mix(float2, float2, float2)&lt;br /&gt;
float3 mix(float3, float3, float)&lt;br /&gt;
float3 mix(float3, float3, float3)&lt;br /&gt;
float4 mix(float4, float4, float)&lt;br /&gt;
float4 mix(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== step(edge, x) ===&lt;br /&gt;
A step function comparing &#039;&#039;&#039;x&#039;&#039;&#039; to &#039;&#039;&#039;edge&#039;&#039;&#039;, if &#039;&#039;&#039;x &amp;lt; edge&#039;&#039;&#039; return &#039;&#039;&#039;0&#039;&#039;&#039; otherwise return &#039;&#039;&#039;1&#039;&#039;&#039;. Operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int step(int, int)&lt;br /&gt;
float step(float, float)&lt;br /&gt;
float2 step(float, float2)&lt;br /&gt;
float2 step(float2, float2)&lt;br /&gt;
float3 step(float, float3)&lt;br /&gt;
float3 step(float3, float3)&lt;br /&gt;
float4 step(float, float4)&lt;br /&gt;
float4 step(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== smoothstep(edge0, edge1, x) ===&lt;br /&gt;
Performs smooth Hermite interpolation between &#039;&#039;&#039;0&#039;&#039;&#039; and &#039;&#039;&#039;1&#039;&#039;&#039; when &#039;&#039;&#039;edge0 &amp;lt; x &amp;lt; edge1&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float smoothstep(float, float, float)&lt;br /&gt;
float2 smoothstep(float, float, float2)&lt;br /&gt;
float2 smoothstep(float2, float2, float)&lt;br /&gt;
float2 smoothstep(float2, float2, float2)&lt;br /&gt;
float3 smoothstep(float, float, float3)&lt;br /&gt;
float3 smoothstep(float3, float3, float)&lt;br /&gt;
float3 smoothstep(float3, float3, float3)&lt;br /&gt;
float4 smoothstep(float, float, float4)&lt;br /&gt;
float4 smoothstep(float4, float4, float)&lt;br /&gt;
float4 smoothstep(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sign(x) ===&lt;br /&gt;
Returns the sign of &#039;&#039;&#039;x&#039;&#039;&#039;, -1 if &#039;&#039;&#039;x &amp;lt; 0&#039;&#039;&#039;, 1 if &#039;&#039;&#039;x &amp;gt; 0&#039;&#039;&#039;, 0 if &#039;&#039;&#039;x == 0&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int sign(int)&lt;br /&gt;
float sign(float)&lt;br /&gt;
float2 sign(float2)&lt;br /&gt;
float3 sign(float3)&lt;br /&gt;
float4 sign(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sqrt(x) ===&lt;br /&gt;
Returns the square root of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sqrt(float)&lt;br /&gt;
float2 sqrt(float2)&lt;br /&gt;
float3 sqrt(float3)&lt;br /&gt;
float4 sqrt(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mod(x, y) ===&lt;br /&gt;
The floating-point remainder of the division operation &#039;&#039;&#039;x / y&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float mod(float, float)&lt;br /&gt;
float2 mod(float2, float)&lt;br /&gt;
float2 mod(float2, float2)&lt;br /&gt;
float3 mod(float3, float)&lt;br /&gt;
float3 mod(float3, float3)&lt;br /&gt;
float4 mod(float4, float)&lt;br /&gt;
float4 mod(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== distance(x, y) ===&lt;br /&gt;
Computes the (unsigned) distance between points &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float distance(float, float)&lt;br /&gt;
float distance(float2, float2)&lt;br /&gt;
float distance(float3, float3)&lt;br /&gt;
float distance(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dot(x, y) ===&lt;br /&gt;
Computes the dot product of &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039; (also known as the inner product).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float dot(float, float)&lt;br /&gt;
float dot(float2, float2)&lt;br /&gt;
float dot(float3, float3)&lt;br /&gt;
float dot(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== length(x) ===&lt;br /&gt;
Returns the length of the input vector.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float length(float)&lt;br /&gt;
float length(float2)&lt;br /&gt;
float length(float3)&lt;br /&gt;
float length(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== normalize(x) ===&lt;br /&gt;
Returns the normalized (unit) vector of &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float normalize(float)&lt;br /&gt;
float2 normalize(float2)&lt;br /&gt;
float3 normalize(float3)&lt;br /&gt;
float4 normalize(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== perp(x, y) ===&lt;br /&gt;
Computes the perp product of two 2D vectors, &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;. This is similar to the cross product in 2D, where &#039;&#039;&#039;perp(x, y) = |x| * |y| * sin(angle)&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float perp(float2, float2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cross(x, y) ===&lt;br /&gt;
Computes the cross product of two 3D vectors, &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float3 cross(float3, float3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== transpose(x) ===&lt;br /&gt;
Return the transpose of matrix &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 transpose(float2x2)&lt;br /&gt;
float3x3 transpose(float3x3)&lt;br /&gt;
float4x4 transpose(float4x4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rotationMatrix2x2(angle) ===&lt;br /&gt;
Builds a 2x2 rotation matrix based on angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 rotationMatrix2x2(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rotationMatrix3x3(pitch, yaw, roll) ===&lt;br /&gt;
Builds a 3x3 rotation matrix based on yaw, pitch, roll angles in radians. Note that roll = 0.0 by default.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float3x3 rotationMatrix3x3(float, float, float = 0.0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1462</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1462"/>
		<updated>2024-12-15T02:26:03Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&lt;br /&gt;
float2x2 rot2x2 = math.rotationMatrix2x2(angle);&lt;br /&gt;
float3x3 rot3x3 = math.rotationMatrix3x3(pitch, yaw, roll);&lt;br /&gt;
// Transform a 2D point.&lt;br /&gt;
float2 point;&lt;br /&gt;
float2 pivot; // center point of rotation.&lt;br /&gt;
float2 rotatedPoint = rot2x2 * (point - pivot) + pivot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!Constant&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|float pi&lt;br /&gt;
|value of π&lt;br /&gt;
|-&lt;br /&gt;
|float twoPi&lt;br /&gt;
|value of 2*π&lt;br /&gt;
|-&lt;br /&gt;
|float e&lt;br /&gt;
|value of the natural number e&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Math Functions ==&lt;br /&gt;
=== countBits(x) ===&lt;br /&gt;
Counts the number of bits in an integer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
uint countBits(uint)&lt;br /&gt;
int countBits(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== abs(x) ===&lt;br /&gt;
Returns the absolute value of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int abs(int)&lt;br /&gt;
float abs(float)&lt;br /&gt;
float2 abs(float2)&lt;br /&gt;
float3 abs(float3)&lt;br /&gt;
float4 abs(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== all(x) ===&lt;br /&gt;
Returns true if all components are non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool all(float)&lt;br /&gt;
bool all(float2)&lt;br /&gt;
bool all(float3)&lt;br /&gt;
bool all(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== any(x) ===&lt;br /&gt;
Returns true if any component is non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool any(float)&lt;br /&gt;
bool any(float2)&lt;br /&gt;
bool any(float3)&lt;br /&gt;
bool any(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== acos(x) ===&lt;br /&gt;
Arccosine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float acos(float)&lt;br /&gt;
float2 acos(float2)&lt;br /&gt;
float3 acos(float3)&lt;br /&gt;
float4 acos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== asin(x) ===&lt;br /&gt;
Arcsine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float asin(float)&lt;br /&gt;
float2 asin(float2)&lt;br /&gt;
float3 asin(float3)&lt;br /&gt;
float4 asin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan(x) ===&lt;br /&gt;
Arctangent of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan(float)&lt;br /&gt;
float2 atan(float2)&lt;br /&gt;
float3 atan(float3)&lt;br /&gt;
float4 atan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan2(y, x) ===&lt;br /&gt;
Returns the angle θ between the positive x-axis and the ray from the origin to the point (x, y), confined to (−π, π].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan2(float, float)&lt;br /&gt;
float2 atan2(float2, float2)&lt;br /&gt;
float3 atan2(float3, float3)&lt;br /&gt;
float4 atan2(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cos(x) ===&lt;br /&gt;
Computes the cosine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float cos(float)&lt;br /&gt;
float2 cos(float2)&lt;br /&gt;
float3 cos(float3)&lt;br /&gt;
float4 cos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sin(x) ===&lt;br /&gt;
Computes the sine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sin(float)&lt;br /&gt;
float2 sin(float2)&lt;br /&gt;
float3 sin(float3)&lt;br /&gt;
float4 sin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tan(x) ===&lt;br /&gt;
Computes the tangent of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float tan(float)&lt;br /&gt;
float2 tan(float2)&lt;br /&gt;
float3 tan(float3)&lt;br /&gt;
float4 tan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sincos(x) ===&lt;br /&gt;
Compute the sine of the input angle and store it in x, and cosine of the angle in y.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 sincos(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== degrees(x) ===&lt;br /&gt;
Converts from radians to degrees, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float degrees(float)&lt;br /&gt;
float2 degrees(float2)&lt;br /&gt;
float3 degrees(float3)&lt;br /&gt;
float4 degrees(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== radians(x) ===&lt;br /&gt;
Converts from degrees to radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float radians(float)&lt;br /&gt;
float2 radians(float2)&lt;br /&gt;
float3 radians(float3)&lt;br /&gt;
float4 radians(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp(x) ===&lt;br /&gt;
Computes the natural number &#039;&#039;&#039;e&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp(float)&lt;br /&gt;
float2 exp(float2)&lt;br /&gt;
float3 exp(float3)&lt;br /&gt;
float4 exp(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp2(x) ===&lt;br /&gt;
Computes &#039;&#039;&#039;2&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp2(float)&lt;br /&gt;
float2 exp2(float2)&lt;br /&gt;
float3 exp2(float3)&lt;br /&gt;
float4 exp2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log(x) ===&lt;br /&gt;
Computes the natural (base &#039;&#039;&#039;e&#039;&#039;&#039;) logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log(float)&lt;br /&gt;
float2 log(float2)&lt;br /&gt;
float3 log(float3)&lt;br /&gt;
float4 log(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log2(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;2&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log2(float)&lt;br /&gt;
float2 log2(float2)&lt;br /&gt;
float3 log2(float3)&lt;br /&gt;
float4 log2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log10(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;10&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log10(float)&lt;br /&gt;
float2 log10(float2)&lt;br /&gt;
float3 log10(float3)&lt;br /&gt;
float4 log10(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== pow(x, y) ===&lt;br /&gt;
Compute the power of &#039;&#039;&#039;x&#039;&#039;&#039; to the power of &#039;&#039;&#039;y&#039;&#039;&#039; (x^y).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float pow(float, float)&lt;br /&gt;
float2 pow(float2, float)&lt;br /&gt;
float2 pow(float2, float2)&lt;br /&gt;
float3 pow(float3, float)&lt;br /&gt;
float3 pow(float3, float3)&lt;br /&gt;
float4 pow(float4, float)&lt;br /&gt;
float4 pow(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== floor(x) ===&lt;br /&gt;
Rounds the input down to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float floor(float)&lt;br /&gt;
float2 floor(float2)&lt;br /&gt;
float3 floor(float3)&lt;br /&gt;
float4 floor(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ceil(x) ===&lt;br /&gt;
Rounds the input up to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float ceil(float)&lt;br /&gt;
float2 ceil(float2)&lt;br /&gt;
float3 ceil(float3)&lt;br /&gt;
float4 ceil(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== fract(x) ===&lt;br /&gt;
Extract the signed fractional part of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float fract(float)&lt;br /&gt;
float2 fract(float2)&lt;br /&gt;
float3 fract(float3)&lt;br /&gt;
float4 fract(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== max(x, y) ===&lt;br /&gt;
Returns the maximum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float max(float, float)&lt;br /&gt;
float2 max(float2, float)&lt;br /&gt;
float2 max(float2, float2)&lt;br /&gt;
float3 max(float3, float)&lt;br /&gt;
float3 max(float3, float3)&lt;br /&gt;
float4 max(float4, float)&lt;br /&gt;
float4 max(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== min(x, y) ===&lt;br /&gt;
Returns the minimum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float min(float, float)&lt;br /&gt;
float2 min(float2, float)&lt;br /&gt;
float2 min(float2, float2)&lt;br /&gt;
float3 min(float3, float)&lt;br /&gt;
float3 min(float3, float3)&lt;br /&gt;
float4 min(float4, float)&lt;br /&gt;
float4 min(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== clamp(x, a, b) ===&lt;br /&gt;
Returns &#039;&#039;&#039;x&#039;&#039;&#039; clamped to the range of &#039;&#039;&#039;[a,b]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float clamp(float, float, float)&lt;br /&gt;
float2 clamp(float2, float, float)&lt;br /&gt;
float2 clamp(float2, float2, float2)&lt;br /&gt;
float3 clamp(float3, float, float)&lt;br /&gt;
float3 clamp(float3, float3, float3)&lt;br /&gt;
float4 clamp(float4, float, float)&lt;br /&gt;
float4 clamp(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== saturate(x) ===&lt;br /&gt;
Clamps the &#039;&#039;&#039;x&#039;&#039;&#039; to the range of &#039;&#039;&#039;[0,1]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float saturate(float)&lt;br /&gt;
float2 saturate(float2)&lt;br /&gt;
float3 saturate(float3)&lt;br /&gt;
float4 saturate(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mix(x, y, a) ===&lt;br /&gt;
Uses &#039;&#039;&#039;a&#039;&#039;&#039; to linearly interpolate between &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;, if &#039;&#039;&#039;a == 0&#039;&#039;&#039; the result is &#039;&#039;&#039;x&#039;&#039;&#039;, if &#039;&#039;&#039;a == 1&#039;&#039;&#039; the result is &#039;&#039;&#039;y&#039;&#039;&#039;, in-between is a mix of &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;. Operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float mix(float, float, float)&lt;br /&gt;
float2 mix(float2, float2, float)&lt;br /&gt;
float2 mix(float2, float2, float2)&lt;br /&gt;
float3 mix(float3, float3, float)&lt;br /&gt;
float3 mix(float3, float3, float3)&lt;br /&gt;
float4 mix(float4, float4, float)&lt;br /&gt;
float4 mix(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== step(edge, x) ===&lt;br /&gt;
A step function comparing &#039;&#039;&#039;x&#039;&#039;&#039; to &#039;&#039;&#039;edge&#039;&#039;&#039;, if &#039;&#039;&#039;x &amp;lt; edge&#039;&#039;&#039; return &#039;&#039;&#039;0&#039;&#039;&#039; otherwise return &#039;&#039;&#039;1&#039;&#039;&#039;. Operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int step(int, int)&lt;br /&gt;
float step(float, float)&lt;br /&gt;
float2 step(float, float2)&lt;br /&gt;
float2 step(float2, float2)&lt;br /&gt;
float3 step(float, float3)&lt;br /&gt;
float3 step(float3, float3)&lt;br /&gt;
float4 step(float, float4)&lt;br /&gt;
float4 step(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== smoothstep(edge0, edge1, x) ===&lt;br /&gt;
Performs smooth Hermite interpolation between &#039;&#039;&#039;0&#039;&#039;&#039; and &#039;&#039;&#039;1&#039;&#039;&#039; when &#039;&#039;&#039;edge0 &amp;lt; x &amp;lt; edge1&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float smoothstep(float, float, float)&lt;br /&gt;
float2 smoothstep(float, float, float2)&lt;br /&gt;
float2 smoothstep(float2, float2, float)&lt;br /&gt;
float2 smoothstep(float2, float2, float2)&lt;br /&gt;
float3 smoothstep(float, float, float3)&lt;br /&gt;
float3 smoothstep(float3, float3, float)&lt;br /&gt;
float3 smoothstep(float3, float3, float3)&lt;br /&gt;
float4 smoothstep(float, float, float4)&lt;br /&gt;
float4 smoothstep(float4, float4, float)&lt;br /&gt;
float4 smoothstep(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sign(x) ===&lt;br /&gt;
Returns the sign of &#039;&#039;&#039;x&#039;&#039;&#039;, -1 if &#039;&#039;&#039;x &amp;lt; 0&#039;&#039;&#039;, 1 if &#039;&#039;&#039;x &amp;gt; 0&#039;&#039;&#039;, 0 if &#039;&#039;&#039;x == 0&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int sign(int)&lt;br /&gt;
float sign(float)&lt;br /&gt;
float2 sign(float2)&lt;br /&gt;
float3 sign(float3)&lt;br /&gt;
float4 sign(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sqrt(x) ===&lt;br /&gt;
Returns the square root of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sqrt(float)&lt;br /&gt;
float2 sqrt(float2)&lt;br /&gt;
float3 sqrt(float3)&lt;br /&gt;
float4 sqrt(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mod(x, y) ===&lt;br /&gt;
The floating-point remainder of the division operation &#039;&#039;&#039;x / y&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float mod(float, float)&lt;br /&gt;
float2 mod(float2, float)&lt;br /&gt;
float2 mod(float2, float2)&lt;br /&gt;
float3 mod(float3, float)&lt;br /&gt;
float3 mod(float3, float3)&lt;br /&gt;
float4 mod(float4, float)&lt;br /&gt;
float4 mod(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== distance(x, y) ===&lt;br /&gt;
Computes the (unsigned) distance between points &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float distance(float, float)&lt;br /&gt;
float distance(float2, float2)&lt;br /&gt;
float distance(float3, float3)&lt;br /&gt;
float distance(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== dot(x, y) ===&lt;br /&gt;
Computes the dot product of &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039; (also known as the inner product).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float dot(float, float)&lt;br /&gt;
float dot(float2, float2)&lt;br /&gt;
float dot(float3, float3)&lt;br /&gt;
float dot(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== length(x) ===&lt;br /&gt;
Returns the length of the input vector.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float length(float)&lt;br /&gt;
float length(float2)&lt;br /&gt;
float length(float3)&lt;br /&gt;
float length(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== normalize(x) ===&lt;br /&gt;
Returns the normalized (unit) vector of &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float normalize(float)&lt;br /&gt;
float2 normalize(float2)&lt;br /&gt;
float3 normalize(float3)&lt;br /&gt;
float4 normalize(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== perp(x, y) ===&lt;br /&gt;
Computes the perp product of two 2D vectors, &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;. This is similar to the cross product in 2D, where &#039;&#039;&#039;perp(x, y) = |x| * |y| * sin(angle)&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float perp(float2, float2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cross(x, y) ===&lt;br /&gt;
Computes the cross product of two 3D vectors, &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float3 cross(float3, float3)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== transpose(x) ===&lt;br /&gt;
Return the transpose of matrix &#039;&#039;&#039;x&#039;&#039;&#039;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 transpose(float2x2)&lt;br /&gt;
float3x3 transpose(float3x3)&lt;br /&gt;
float4x4 transpose(float4x4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rotationMatrix2x2(angle) ===&lt;br /&gt;
Builds a 2x2 rotation matrix based on angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 rotationMatrix2x2(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== rotationMatrix3x3(pitch, yaw, roll) ===&lt;br /&gt;
Builds a 3x3 rotation matrix based on yaw, pitch, roll angles in radians. Note that roll = 0.0 by default.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float3x3 rotationMatrix3x3(float, float, float = 0.0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1461</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1461"/>
		<updated>2024-12-15T02:14:06Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&lt;br /&gt;
float2x2 rot2x2 = math.rotationMatrix2x2(angle);&lt;br /&gt;
float3x3 rot3x3 = math.rotationMatrix3x3(pitch, yaw, roll);&lt;br /&gt;
// Transform a 2D point.&lt;br /&gt;
float2 point;&lt;br /&gt;
float2 pivot; // center point of rotation.&lt;br /&gt;
float2 rotatedPoint = rot2x2 * (point - pivot) + pivot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!Constant&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|float pi&lt;br /&gt;
|value of π&lt;br /&gt;
|-&lt;br /&gt;
|float twoPi&lt;br /&gt;
|value of 2*π&lt;br /&gt;
|-&lt;br /&gt;
|float e&lt;br /&gt;
|value of the natural number e&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Math Functions ==&lt;br /&gt;
=== countBits(x) ===&lt;br /&gt;
Counts the number of bits in an integer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
uint countBits(uint)&lt;br /&gt;
int countBits(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== abs(x) ===&lt;br /&gt;
Returns the absolute value of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int abs(int)&lt;br /&gt;
float abs(float)&lt;br /&gt;
float2 abs(float2)&lt;br /&gt;
float3 abs(float3)&lt;br /&gt;
float4 abs(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== all(x) ===&lt;br /&gt;
Returns true if all components are non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool all(float)&lt;br /&gt;
bool all(float2)&lt;br /&gt;
bool all(float3)&lt;br /&gt;
bool all(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== any(x) ===&lt;br /&gt;
Returns true if any component is non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool any(float)&lt;br /&gt;
bool any(float2)&lt;br /&gt;
bool any(float3)&lt;br /&gt;
bool any(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== acos(x) ===&lt;br /&gt;
Arccosine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float acos(float)&lt;br /&gt;
float2 acos(float2)&lt;br /&gt;
float3 acos(float3)&lt;br /&gt;
float4 acos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== asin(x) ===&lt;br /&gt;
Arcsine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float asin(float)&lt;br /&gt;
float2 asin(float2)&lt;br /&gt;
float3 asin(float3)&lt;br /&gt;
float4 asin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan(x) ===&lt;br /&gt;
Arctangent of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan(float)&lt;br /&gt;
float2 atan(float2)&lt;br /&gt;
float3 atan(float3)&lt;br /&gt;
float4 atan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan2(y, x) ===&lt;br /&gt;
Returns the angle θ between the positive x-axis and the ray from the origin to the point (x, y), confined to (−π, π].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan2(float, float)&lt;br /&gt;
float2 atan2(float2, float2)&lt;br /&gt;
float3 atan2(float3, float3)&lt;br /&gt;
float4 atan2(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cos(x) ===&lt;br /&gt;
Computes the cosine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float cos(float)&lt;br /&gt;
float2 cos(float2)&lt;br /&gt;
float3 cos(float3)&lt;br /&gt;
float4 cos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sin(x) ===&lt;br /&gt;
Computes the sine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sin(float)&lt;br /&gt;
float2 sin(float2)&lt;br /&gt;
float3 sin(float3)&lt;br /&gt;
float4 sin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tan(x) ===&lt;br /&gt;
Computes the tangent of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float tan(float)&lt;br /&gt;
float2 tan(float2)&lt;br /&gt;
float3 tan(float3)&lt;br /&gt;
float4 tan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sincos(x) ===&lt;br /&gt;
Compute the sine of the input angle and store it in x, and cosine of the angle in y.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 sincos(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== degrees(x) ===&lt;br /&gt;
Converts from radians to degrees, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float degrees(float)&lt;br /&gt;
float2 degrees(float2)&lt;br /&gt;
float3 degrees(float3)&lt;br /&gt;
float4 degrees(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== radians(x) ===&lt;br /&gt;
Converts from degrees to radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float radians(float)&lt;br /&gt;
float2 radians(float2)&lt;br /&gt;
float3 radians(float3)&lt;br /&gt;
float4 radians(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp(x) ===&lt;br /&gt;
Computes the natural number &#039;&#039;&#039;e&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp(float)&lt;br /&gt;
float2 exp(float2)&lt;br /&gt;
float3 exp(float3)&lt;br /&gt;
float4 exp(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp2(x) ===&lt;br /&gt;
Computes &#039;&#039;&#039;2&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp2(float)&lt;br /&gt;
float2 exp2(float2)&lt;br /&gt;
float3 exp2(float3)&lt;br /&gt;
float4 exp2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log(x) ===&lt;br /&gt;
Computes the natural (base &#039;&#039;&#039;e&#039;&#039;&#039;) logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log(float)&lt;br /&gt;
float2 log(float2)&lt;br /&gt;
float3 log(float3)&lt;br /&gt;
float4 log(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log2(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;2&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log2(float)&lt;br /&gt;
float2 log2(float2)&lt;br /&gt;
float3 log2(float3)&lt;br /&gt;
float4 log2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log10(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;10&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log10(float)&lt;br /&gt;
float2 log10(float2)&lt;br /&gt;
float3 log10(float3)&lt;br /&gt;
float4 log10(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== pow(x, y) ===&lt;br /&gt;
Compute the power of &#039;&#039;&#039;x&#039;&#039;&#039; to the power of &#039;&#039;&#039;y&#039;&#039;&#039; (x^y).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float pow(float, float)&lt;br /&gt;
float2 pow(float2, float)&lt;br /&gt;
float2 pow(float2, float2)&lt;br /&gt;
float3 pow(float3, float)&lt;br /&gt;
float3 pow(float3, float3)&lt;br /&gt;
float4 pow(float4, float)&lt;br /&gt;
float4 pow(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== floor(x) ===&lt;br /&gt;
Rounds the input down to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float floor(float)&lt;br /&gt;
float2 floor(float2)&lt;br /&gt;
float3 floor(float3)&lt;br /&gt;
float4 floor(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ceil(x) ===&lt;br /&gt;
Rounds the input up to the nearest integer, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float ceil(float)&lt;br /&gt;
float2 ceil(float2)&lt;br /&gt;
float3 ceil(float3)&lt;br /&gt;
float4 ceil(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== fract(x) ===&lt;br /&gt;
Extract the signed fractional part of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float fract(float)&lt;br /&gt;
float2 fract(float2)&lt;br /&gt;
float3 fract(float3)&lt;br /&gt;
float4 fract(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== max(x, y) ===&lt;br /&gt;
Returns the maximum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float max(float, float)&lt;br /&gt;
float2 max(float2, float)&lt;br /&gt;
float2 max(float2, float2)&lt;br /&gt;
float3 max(float3, float)&lt;br /&gt;
float3 max(float3, float3)&lt;br /&gt;
float4 max(float4, float)&lt;br /&gt;
float4 max(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== min(x, y) ===&lt;br /&gt;
Returns the minimum of two values, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float min(float, float)&lt;br /&gt;
float2 min(float2, float)&lt;br /&gt;
float2 min(float2, float2)&lt;br /&gt;
float3 min(float3, float)&lt;br /&gt;
float3 min(float3, float3)&lt;br /&gt;
float4 min(float4, float)&lt;br /&gt;
float4 min(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== clamp(x, a, b) ===&lt;br /&gt;
Returns &#039;&#039;&#039;x&#039;&#039;&#039; clamped to the range of &#039;&#039;&#039;[a,b]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float clamp(float, float, float)&lt;br /&gt;
float2 clamp(float2, float, float)&lt;br /&gt;
float2 clamp(float2, float2, float2)&lt;br /&gt;
float3 clamp(float3, float, float)&lt;br /&gt;
float3 clamp(float3, float3, float3)&lt;br /&gt;
float4 clamp(float4, float, float)&lt;br /&gt;
float4 clamp(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== saturate(x) ===&lt;br /&gt;
Clamps the &#039;&#039;&#039;x&#039;&#039;&#039; to the range of &#039;&#039;&#039;[0,1]&#039;&#039;&#039;, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float saturate(float)&lt;br /&gt;
float2 saturate(float2)&lt;br /&gt;
float3 saturate(float3)&lt;br /&gt;
float4 saturate(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mix(x, y, a) ===&lt;br /&gt;
Uses &#039;&#039;&#039;a&#039;&#039;&#039; to linearly interpolate between &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;, if &#039;&#039;&#039;a == 0&#039;&#039;&#039; the result is &#039;&#039;&#039;x&#039;&#039;&#039;, if &#039;&#039;&#039;a == 1&#039;&#039;&#039; the result is &#039;&#039;&#039;y&#039;&#039;&#039;, in-between is a mix of &#039;&#039;&#039;x&#039;&#039;&#039; and &#039;&#039;&#039;y&#039;&#039;&#039;. Operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float mix(float, float, float)&lt;br /&gt;
float2 mix(float2, float2, float)&lt;br /&gt;
float2 mix(float2, float2, float2)&lt;br /&gt;
float3 mix(float3, float3, float)&lt;br /&gt;
float3 mix(float3, float3, float3)&lt;br /&gt;
float4 mix(float4, float4, float)&lt;br /&gt;
float4 mix(float4, float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1460</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1460"/>
		<updated>2024-12-15T00:55:47Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&lt;br /&gt;
float2x2 rot2x2 = math.rotationMatrix2x2(angle);&lt;br /&gt;
float3x3 rot3x3 = math.rotationMatrix3x3(pitch, yaw, roll);&lt;br /&gt;
// Transform a 2D point.&lt;br /&gt;
float2 point;&lt;br /&gt;
float2 pivot; // center point of rotation.&lt;br /&gt;
float2 rotatedPoint = rot2x2 * (point - pivot) + pivot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!Constant&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|float pi&lt;br /&gt;
|value of π&lt;br /&gt;
|-&lt;br /&gt;
|float twoPi&lt;br /&gt;
|value of 2*π&lt;br /&gt;
|-&lt;br /&gt;
|float e&lt;br /&gt;
|value of the natural number e&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Math Functions ==&lt;br /&gt;
=== countBits(x) ===&lt;br /&gt;
Counts the number of bits in an integer.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
uint countBits(uint)&lt;br /&gt;
int countBits(int)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== abs(x) ===&lt;br /&gt;
Returns the absolute value of the input, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int abs(int)&lt;br /&gt;
float abs(float)&lt;br /&gt;
float2 abs(float2)&lt;br /&gt;
float3 abs(float3)&lt;br /&gt;
float4 abs(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== all(x) ===&lt;br /&gt;
Returns true if all components are non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool all(float)&lt;br /&gt;
bool all(float2)&lt;br /&gt;
bool all(float3)&lt;br /&gt;
bool all(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== any(x) ===&lt;br /&gt;
Returns true if any component is non-zero.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool any(float)&lt;br /&gt;
bool any(float2)&lt;br /&gt;
bool any(float3)&lt;br /&gt;
bool any(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== acos(x) ===&lt;br /&gt;
Arccosine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float acos(float)&lt;br /&gt;
float2 acos(float2)&lt;br /&gt;
float3 acos(float3)&lt;br /&gt;
float4 acos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== asin(x) ===&lt;br /&gt;
Arcsine of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float asin(float)&lt;br /&gt;
float2 asin(float2)&lt;br /&gt;
float3 asin(float3)&lt;br /&gt;
float4 asin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan(x) ===&lt;br /&gt;
Arctangent of angles in radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan(float)&lt;br /&gt;
float2 atan(float2)&lt;br /&gt;
float3 atan(float3)&lt;br /&gt;
float4 atan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== atan2(y, x) ===&lt;br /&gt;
Returns the angle θ between the positive x-axis and the ray from the origin to the point (x, y), confined to (−π, π].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float atan2(float, float)&lt;br /&gt;
float2 atan2(float2, float2)&lt;br /&gt;
float3 atan2(float3, float3)&lt;br /&gt;
float4 atan2(float4, float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== cos(x) ===&lt;br /&gt;
Computes the cosine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float cos(float)&lt;br /&gt;
float2 cos(float2)&lt;br /&gt;
float3 cos(float3)&lt;br /&gt;
float4 cos(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sin(x) ===&lt;br /&gt;
Computes the sine of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float sin(float)&lt;br /&gt;
float2 sin(float2)&lt;br /&gt;
float3 sin(float3)&lt;br /&gt;
float4 sin(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tan(x) ===&lt;br /&gt;
Computes the tangent of the input angle in radians.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float tan(float)&lt;br /&gt;
float2 tan(float2)&lt;br /&gt;
float3 tan(float3)&lt;br /&gt;
float4 tan(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== sincos(x) ===&lt;br /&gt;
Compute the sine of the input angle and store it in x, and cosine of the angle in y.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 sincos(float)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== degrees(x) ===&lt;br /&gt;
Converts from radians to degrees, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float degrees(float)&lt;br /&gt;
float2 degrees(float2)&lt;br /&gt;
float3 degrees(float3)&lt;br /&gt;
float4 degrees(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== radians(x) ===&lt;br /&gt;
Converts from degrees to radians, operates per-component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float radians(float)&lt;br /&gt;
float2 radians(float2)&lt;br /&gt;
float3 radians(float3)&lt;br /&gt;
float4 radians(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp(x) ===&lt;br /&gt;
Computes the natural number &#039;&#039;&#039;e&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp(float)&lt;br /&gt;
float2 exp(float2)&lt;br /&gt;
float3 exp(float3)&lt;br /&gt;
float4 exp(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== exp2(x) ===&lt;br /&gt;
Computes &#039;&#039;&#039;2&#039;&#039;&#039; to the power of &#039;&#039;&#039;x&#039;&#039;&#039;, and operates per component.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float exp2(float)&lt;br /&gt;
float2 exp2(float2)&lt;br /&gt;
float3 exp2(float3)&lt;br /&gt;
float4 exp2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log(x) ===&lt;br /&gt;
Computes the natural (base &#039;&#039;&#039;e&#039;&#039;&#039;) logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log(float)&lt;br /&gt;
float2 log(float2)&lt;br /&gt;
float3 log(float3)&lt;br /&gt;
float4 log(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log2(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;2&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log2(float)&lt;br /&gt;
float2 log2(float2)&lt;br /&gt;
float3 log2(float3)&lt;br /&gt;
float4 log2(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== log10(x) ===&lt;br /&gt;
Computes the base &#039;&#039;&#039;10&#039;&#039;&#039; logarithm of the input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float log10(float)&lt;br /&gt;
float2 log10(float2)&lt;br /&gt;
float3 log10(float3)&lt;br /&gt;
float4 log10(float4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1459</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1459"/>
		<updated>2024-12-15T00:44:46Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&lt;br /&gt;
float2x2 rot2x2 = math.rotationMatrix2x2(angle);&lt;br /&gt;
float3x3 rot3x3 = math.rotationMatrix3x3(pitch, yaw, roll);&lt;br /&gt;
// Transform a 2D point.&lt;br /&gt;
float2 point;&lt;br /&gt;
float2 pivot; // center point of rotation.&lt;br /&gt;
float2 rotatedPoint = rot2x2 * (point - pivot) + pivot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!Constant&lt;br /&gt;
!Description&lt;br /&gt;
|-&lt;br /&gt;
|float pi&lt;br /&gt;
|value of π&lt;br /&gt;
|-&lt;br /&gt;
|float twoPi&lt;br /&gt;
|value of 2*π&lt;br /&gt;
|-&lt;br /&gt;
|float e&lt;br /&gt;
|value of the natural number e&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1458</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1458"/>
		<updated>2024-12-15T00:37:55Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of Array Access:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v2(2,3);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[0]);  // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v2[1]);  // 3&lt;br /&gt;
&lt;br /&gt;
float4 v4(1, 2, 3, 4);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[1]); // 2&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v4[3]); // 4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Example of mathematical operations, basic operations are supported:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 a(1,2);&lt;br /&gt;
float2 b(2,3);&lt;br /&gt;
float4 a4(1,2,3,4);&lt;br /&gt;
float2 c = a + b;   // c = (1,2) + (2,3) = (3,5)&lt;br /&gt;
float2 d = a * b;   // d = (1,2) * (2,3) = (2,6)&lt;br /&gt;
float2 e = a * 2.0; // e = (1,2) * 2 = (2,4)&lt;br /&gt;
float3 f = a4.xyz * a.y; // f = (1,2,3) * (2) = (2,4,6)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Matrix Operations ==&lt;br /&gt;
Matrices are stored as a series of vectors, which can be accessed using array syntax. Matrix types support matrix/matrix and matrix/vector multiplication, as well as matrix/float scaling.&lt;br /&gt;
The following types are supported: float2x2, float3x3, float4x4.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2x2 m2x2(1, 0, 0, 1); // 2x2 matrix: [1 0]&lt;br /&gt;
                                          [0 1]&lt;br /&gt;
float3x3 m0(float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)); // 3x3 identity.&lt;br /&gt;
float3x3 m1;&lt;br /&gt;
&lt;br /&gt;
float3x3 m2 = m0 * m1; // concatenate matrices m0 and m1.&lt;br /&gt;
float3 pos;&lt;br /&gt;
float3 r = m2 * pos;  // multiply &#039;pos&#039; by matrix m2.&lt;br /&gt;
&lt;br /&gt;
float3 v = m0[1]; // v = (0, 1, 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Examples ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 s(2, 3);&lt;br /&gt;
float2 t(4, 5);&lt;br /&gt;
float2 q(3, 4);&lt;br /&gt;
float3 r(4, 5, 6);&lt;br /&gt;
float3 color0(1.0, 0.5, 0.5);&lt;br /&gt;
float3 color1(0.25, 0.25, 1.0);&lt;br /&gt;
float dist = math.distance(s, q);  // distance between (2,3) and (3,4).&lt;br /&gt;
float blend = math.smoothstep(0, 5, dist);  // produce a blend factor between [0,1]&lt;br /&gt;
float2 value = math.mix(s, t, blend);&lt;br /&gt;
float2 sum = r.xy + r.yz;&lt;br /&gt;
float3 unit = math.normalize(r);&lt;br /&gt;
float3 color = math.mix(color0, color1, blend);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Math Constants ==&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1457</id>
		<title>Math Script API</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Math_Script_API&amp;diff=1457"/>
		<updated>2024-12-15T00:34:35Z</updated>

		<summary type="html">&lt;p&gt;Lucius: Created page with &amp;quot;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.  == Basic Types == Basic math types available to the script system include:  * int - 32-bit signed integer * uint - 32-bit unsigned integer * float - 32-bit floating point value  == Vector and Matrix Types ==  * &amp;#039;&amp;#039;&amp;#039;float2, float3, float4&amp;#039;&amp;#039;&amp;#039; - vector types of the indicated size. A float3, for example,...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Core math API used by the script system. It can be accessed using the math interface and consists of a number of constants, functions, and built-in vector and matrix types.&lt;br /&gt;
&lt;br /&gt;
== Basic Types ==&lt;br /&gt;
Basic math types available to the script system include:&lt;br /&gt;
&lt;br /&gt;
* int - 32-bit signed integer&lt;br /&gt;
* uint - 32-bit unsigned integer&lt;br /&gt;
* float - 32-bit floating point value&lt;br /&gt;
&lt;br /&gt;
== Vector and Matrix Types ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;float2, float3, float4&#039;&#039;&#039; - vector types of the indicated size. A float3, for example, consists of 3 floats in vector format. Components can be accessed as x, y, z, w or by index (see the examples below). GLSL style swizzling is supported, as well as array syntax. Swizzling can be used to copy out smaller vectors as well.&lt;br /&gt;
* &#039;&#039;&#039;float2x2, float3x3, float4x4&#039;&#039;&#039; - matrix types of the indicated size (2x2, 3x3, or 4x4 matrix). Rows can be accessed using the array syntax and are of the associated vector type (float2x2 = 2 x float2).&lt;br /&gt;
&lt;br /&gt;
== Vector Operations ==&lt;br /&gt;
Vector types (&#039;&#039;&#039;float, float2, float3, float4&#039;&#039;&#039;) can be referenced using array and component syntax. Swizzling is supported.&lt;br /&gt;
&lt;br /&gt;
Example Swizzles:&amp;lt;pre&amp;gt;&lt;br /&gt;
float2 v(1, 2);&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v);    // (1, 2)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.yx); // (2, 1)&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, v.xx); // (1, 1)&lt;br /&gt;
float a = v.y;&lt;br /&gt;
system.print(&amp;quot;{}&amp;quot;, a); // 2&lt;br /&gt;
&lt;br /&gt;
float3 v3(1, 2, 3);&lt;br /&gt;
float2 v2 = v3.xz;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1456</id>
		<title>TFE Level Script</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1456"/>
		<updated>2024-12-15T00:24:50Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
TFE Level scripts have two major functions:&lt;br /&gt;
&lt;br /&gt;
* Enable script based level interactivity.&lt;br /&gt;
* Extend INF functionality with new script-based functions using ScriptCall directly from INF.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
To include a Level Script with your mod, simply create a &#039;&#039;&#039;LevelScript.fs&#039;&#039;&#039; file and include it in the same ZIP or folder as your GOB file. This is a simple text file that can be edited in Notepad-like applications, such as Notepad++.&lt;br /&gt;
&lt;br /&gt;
== Minimal Script Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// Level Script.&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
// Level Start!&lt;br /&gt;
void levelStart(string levelName)&lt;br /&gt;
{&lt;br /&gt;
	// Prints out the levelName and sector count.&lt;br /&gt;
	// This is just an example and should be replaced by your own code.&lt;br /&gt;
	// **Important** Script state is persistant across levels, use this function&lt;br /&gt;
	// to reset any necessary state on level load.&lt;br /&gt;
	system.print(&amp;quot;Start Level {}, Sector Count {}&amp;quot;, levelName, level.sectorCount);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is called once per game update.&lt;br /&gt;
void levelUpdate(float dt)&lt;br /&gt;
{&lt;br /&gt;
	// This is called once per **game** update, dt is the delta time in&lt;br /&gt;
	// seconds since the last game update.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// You can write internal helper functions as well.&lt;br /&gt;
&lt;br /&gt;
// Finally, you can write functions called by `ScriptCall` from INF.&lt;br /&gt;
// ScriptCall functions can have up to 4 parameters in addition to the final&lt;br /&gt;
// parameter which will always be the elevator or trigger ID that called it.&lt;br /&gt;
void InfScriptCallExample(int elevID)&lt;br /&gt;
{&lt;br /&gt;
	// Given the elevator ID, get the elevator from `level`. IDs don&#039;t change&lt;br /&gt;
	// during level execution, so elev will remain valid while in the same level.&lt;br /&gt;
	Elevator elev = level.getElevator(elevID);&lt;br /&gt;
	// It is possible for a scriptCall function to keep running using &#039;yield&#039;&lt;br /&gt;
	// Keep running while the elevator is active, for example.&lt;br /&gt;
	float prevTime = game.getGameTime();&lt;br /&gt;
	while (elev.master)&lt;br /&gt;
	{&lt;br /&gt;
		// Do stuff while the elevator is active (master is on).&lt;br /&gt;
		// Use game.getGameTime() to get the current game time to stay synced.&lt;br /&gt;
		// This is an example of computing a delta time.&lt;br /&gt;
		float curTime = game.getGameTime();&lt;br /&gt;
		float dt = curTime - prevTime;&lt;br /&gt;
		prevTime = curTime;&lt;br /&gt;
	&lt;br /&gt;
		// Return control to the system. A delay in seconds can be passed in&lt;br /&gt;
		// to handle timing.&lt;br /&gt;
		// The script will resume after the yield with the call stack and local&lt;br /&gt;
		// variables preserved.&lt;br /&gt;
		yield();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
* [[Math Script API]]&lt;br /&gt;
* [[System Script API]]&lt;br /&gt;
* [[Game Script API]]&lt;br /&gt;
* [[Level Script API]]&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1455</id>
		<title>TFE Level Script</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1455"/>
		<updated>2024-12-15T00:23:10Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
TFE Level scripts have two major functions:&lt;br /&gt;
&lt;br /&gt;
* Enable script based level interactivity.&lt;br /&gt;
* Extend INF functionality with new script-based functions using ScriptCall directly from INF.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
To include a Level Script with your mod, simply create a &#039;&#039;&#039;LevelScript.fs&#039;&#039;&#039; file and include it in the same ZIP or folder as your GOB file. This is a simple text file that can be edited in Notepad-like applications, such as Notepad++.&lt;br /&gt;
&lt;br /&gt;
== Minimal Script Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// Level Script.&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
// Level Start!&lt;br /&gt;
void levelStart(string levelName)&lt;br /&gt;
{&lt;br /&gt;
	// Prints out the levelName and sector count.&lt;br /&gt;
	// This is just an example and should be replaced by your own code.&lt;br /&gt;
	// **Important** Script state is persistant across levels, use this function&lt;br /&gt;
	// to reset any necessary state on level load.&lt;br /&gt;
	system.print(&amp;quot;Start Level {}, Sector Count {}&amp;quot;, levelName, level.sectorCount);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is called once per game update.&lt;br /&gt;
void levelUpdate(float dt)&lt;br /&gt;
{&lt;br /&gt;
	// This is called once per **game** update, dt is the delta time in&lt;br /&gt;
	// seconds since the last game update.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// You can write internal helper functions as well.&lt;br /&gt;
&lt;br /&gt;
// Finally, you can write functions called by `ScriptCall` from INF.&lt;br /&gt;
// ScriptCall functions can have up to 4 parameters in addition to the final&lt;br /&gt;
// parameter which will always be the elevator or trigger ID that called it.&lt;br /&gt;
void InfScriptCallExample(int elevID)&lt;br /&gt;
{&lt;br /&gt;
	// Given the elevator ID, get the elevator from `level`. IDs don&#039;t change&lt;br /&gt;
	// during level execution, so elev will remain valid while in the same level.&lt;br /&gt;
	Elevator elev = level.getElevator(elevID);&lt;br /&gt;
	// It is possible for a scriptCall function to keep running using &#039;yield&#039;&lt;br /&gt;
	// Keep running while the elevator is active, for example.&lt;br /&gt;
	float prevTime = game.getGameTime();&lt;br /&gt;
	while (elev.master)&lt;br /&gt;
	{&lt;br /&gt;
		// Do stuff while the elevator is active (master is on).&lt;br /&gt;
		// Use game.getGameTime() to get the current game time to stay synced.&lt;br /&gt;
		// This is an example of computing a delta time.&lt;br /&gt;
		float curTime = game.getGameTime();&lt;br /&gt;
		float dt = curTime - prevTime;&lt;br /&gt;
		prevTime = curTime;&lt;br /&gt;
	&lt;br /&gt;
		// Return control to the system. A delay in seconds can be passed in&lt;br /&gt;
		// to handle timing.&lt;br /&gt;
		// The script will resume after the yield with the call stack and local&lt;br /&gt;
		// variables preserved.&lt;br /&gt;
		yield();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1454</id>
		<title>TFE Level Script</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1454"/>
		<updated>2024-12-15T00:21:45Z</updated>

		<summary type="html">&lt;p&gt;Lucius: /* inimal Script Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
TFE Level scripts have two major functions:&lt;br /&gt;
&lt;br /&gt;
* Enable script based level interactivity.&lt;br /&gt;
* Extend INF functionality with new script-based functions using ScriptCall directly from INF.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
To include a Level Script with your mod, simply create a &#039;&#039;&#039;LevelScript.fs&#039;&#039;&#039; file and include it in the same ZIP or folder as your GOB file. This is a simple text file that can be edited in Notepad-like applications, such as Notepad++.&lt;br /&gt;
&lt;br /&gt;
== Minimal Script Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// Level Script.&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
// Level Start!&lt;br /&gt;
void levelStart(string levelName)&lt;br /&gt;
{&lt;br /&gt;
	// Prints out the levelName and sector count.&lt;br /&gt;
	// This is just an example and should be replaced by your own code.&lt;br /&gt;
	// **Important** Script state is persistant across levels, use this function&lt;br /&gt;
	// to reset any necessary state on level load.&lt;br /&gt;
	system.print(&amp;quot;Start Level {}, Sector Count {}&amp;quot;, levelName, level.sectorCount);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is called once per game update.&lt;br /&gt;
void levelUpdate(float dt)&lt;br /&gt;
{&lt;br /&gt;
	// This is called once per **game** update, dt is the delta time in&lt;br /&gt;
	// seconds since the last game update.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// You can write internal helper functions as well.&lt;br /&gt;
&lt;br /&gt;
// Finally, you can write functions called by `ScriptCall` from INF.&lt;br /&gt;
// ScriptCall functions can have up to 4 parameters in addition to the final&lt;br /&gt;
// parameter which will always be the elevator or trigger ID that called it.&lt;br /&gt;
void InfScriptCallExample(int elevID)&lt;br /&gt;
{&lt;br /&gt;
	// Given the elevator ID, get the elevator from `level`. IDs don&#039;t change&lt;br /&gt;
	// during level execution, so elev will remain valid while in the same level.&lt;br /&gt;
	Elevator elev = level.getElevator(elevID);&lt;br /&gt;
	// It is possible for a scriptCall function to keep running using &#039;yield&#039;&lt;br /&gt;
	// Keep running while the elevator is active, for example.&lt;br /&gt;
	float prevTime = game.getGameTime();&lt;br /&gt;
	while (elev.master)&lt;br /&gt;
	{&lt;br /&gt;
		// Do stuff while the elevator is active (master is on).&lt;br /&gt;
		// Use game.getGameTime() to get the current game time to stay synced.&lt;br /&gt;
		// This is an example of computing a delta time.&lt;br /&gt;
		float curTime = game.getGameTime();&lt;br /&gt;
		float dt = curTime - prevTime;&lt;br /&gt;
		prevTime = curTime;&lt;br /&gt;
	&lt;br /&gt;
		// Return control to the system. A delay in seconds can be passed in&lt;br /&gt;
		// to handle timing.&lt;br /&gt;
		// The script will resume after the yield with the call stack and local&lt;br /&gt;
		// variables preserved.&lt;br /&gt;
		yield();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1453</id>
		<title>TFE Level Script</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1453"/>
		<updated>2024-12-15T00:21:15Z</updated>

		<summary type="html">&lt;p&gt;Lucius: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Purpose ==&lt;br /&gt;
TFE Level scripts have two major functions:&lt;br /&gt;
&lt;br /&gt;
* Enable script based level interactivity.&lt;br /&gt;
* Extend INF functionality with new script-based functions using ScriptCall directly from INF.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
To include a Level Script with your mod, simply create a &#039;&#039;&#039;LevelScript.fs&#039;&#039;&#039; file and include it in the same ZIP or folder as your GOB file. This is a simple text file that can be edited in Notepad-like applications, such as Notepad++.&lt;br /&gt;
&lt;br /&gt;
== inimal Script Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// Level Script.&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
// Level Start!&lt;br /&gt;
void levelStart(string levelName)&lt;br /&gt;
{&lt;br /&gt;
	// Prints out the levelName and sector count.&lt;br /&gt;
	// This is just an example and should be replaced by your own code.&lt;br /&gt;
	// **Important** Script state is persistant across levels, use this function&lt;br /&gt;
	// to reset any necessary state on level load.&lt;br /&gt;
	system.print(&amp;quot;Start Level {}, Sector Count {}&amp;quot;, levelName, level.sectorCount);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is called once per game update.&lt;br /&gt;
void levelUpdate(float dt)&lt;br /&gt;
{&lt;br /&gt;
	// This is called once per **game** update, dt is the delta time in&lt;br /&gt;
	// seconds since the last game update.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// You can write internal helper functions as well.&lt;br /&gt;
&lt;br /&gt;
// Finally, you can write functions called by `ScriptCall` from INF.&lt;br /&gt;
// ScriptCall functions can have up to 4 parameters in addition to the final&lt;br /&gt;
// parameter which will always be the elevator or trigger ID that called it.&lt;br /&gt;
void InfScriptCallExample(int elevID)&lt;br /&gt;
{&lt;br /&gt;
	// Given the elevator ID, get the elevator from `level`. IDs don&#039;t change&lt;br /&gt;
	// during level execution, so elev will remain valid while in the same level.&lt;br /&gt;
	Elevator elev = level.getElevator(elevID);&lt;br /&gt;
	// It is possible for a scriptCall function to keep running using &#039;yield&#039;&lt;br /&gt;
	// Keep running while the elevator is active, for example.&lt;br /&gt;
	float prevTime = game.getGameTime();&lt;br /&gt;
	while (elev.master)&lt;br /&gt;
	{&lt;br /&gt;
		// Do stuff while the elevator is active (master is on).&lt;br /&gt;
		// Use game.getGameTime() to get the current game time to stay synced.&lt;br /&gt;
		// This is an example of computing a delta time.&lt;br /&gt;
		float curTime = game.getGameTime();&lt;br /&gt;
		float dt = curTime - prevTime;&lt;br /&gt;
		prevTime = curTime;&lt;br /&gt;
	&lt;br /&gt;
		// Return control to the system. A delay in seconds can be passed in&lt;br /&gt;
		// to handle timing.&lt;br /&gt;
		// The script will resume after the yield with the call stack and local&lt;br /&gt;
		// variables preserved.&lt;br /&gt;
		yield();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1452</id>
		<title>TFE Level Script</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=TFE_Level_Script&amp;diff=1452"/>
		<updated>2024-12-15T00:13:43Z</updated>

		<summary type="html">&lt;p&gt;Lucius: Created page with &amp;quot;To include a Level Script with your mod, simply create a &amp;#039;&amp;#039;&amp;#039;LevelScript.fs&amp;#039;&amp;#039;&amp;#039; file and include it in the same ZIP or folder as your GOB file.  Minimal script example: &amp;lt;pre&amp;gt; ////////////////////////////////// // Level Script. //////////////////////////////////  // Level Start! void levelStart(string levelName) { 	// Prints out the levelName and sector count. 	// This is just an example and should be replaced by your own code. 	// **Important** Script state is persistant a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To include a Level Script with your mod, simply create a &#039;&#039;&#039;LevelScript.fs&#039;&#039;&#039; file and include it in the same ZIP or folder as your GOB file.&lt;br /&gt;
&lt;br /&gt;
Minimal script example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// Level Script.&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
// Level Start!&lt;br /&gt;
void levelStart(string levelName)&lt;br /&gt;
{&lt;br /&gt;
	// Prints out the levelName and sector count.&lt;br /&gt;
	// This is just an example and should be replaced by your own code.&lt;br /&gt;
	// **Important** Script state is persistant across levels, use this function&lt;br /&gt;
	// to reset any necessary state on level load.&lt;br /&gt;
	system.print(&amp;quot;Start Level {}, Sector Count {}&amp;quot;, levelName, level.sectorCount);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is called once per game update.&lt;br /&gt;
void levelUpdate(float dt)&lt;br /&gt;
{&lt;br /&gt;
	// This is called once per **game** update, dt is the delta time in&lt;br /&gt;
	// seconds since the last game update.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// You can write internal helper functions as well.&lt;br /&gt;
&lt;br /&gt;
// Finally, you can write functions called by `ScriptCall` from INF.&lt;br /&gt;
// ScriptCall functions can have up to 4 parameters in addition to the final&lt;br /&gt;
// parameter which will always be the elevator or trigger ID that called it.&lt;br /&gt;
void InfScriptCallExample(int elevID)&lt;br /&gt;
{&lt;br /&gt;
	// Given the elevator ID, get the elevator from `level`. IDs don&#039;t change&lt;br /&gt;
	// during level execution, so elev will remain valid while in the same level.&lt;br /&gt;
	Elevator elev = level.getElevator(elevID);&lt;br /&gt;
	// It is possible for a scriptCall function to keep running using &#039;yield&#039;&lt;br /&gt;
	// Keep running while the elevator is active, for example.&lt;br /&gt;
	float prevTime = game.getGameTime();&lt;br /&gt;
	while (elev.master)&lt;br /&gt;
	{&lt;br /&gt;
		// Do stuff while the elevator is active (master is on).&lt;br /&gt;
		// Use game.getGameTime() to get the current game time to stay synced.&lt;br /&gt;
		// This is an example of computing a delta time.&lt;br /&gt;
		float curTime = game.getGameTime();&lt;br /&gt;
		float dt = curTime - prevTime;&lt;br /&gt;
		prevTime = curTime;&lt;br /&gt;
	&lt;br /&gt;
		// Return control to the system. A delay in seconds can be passed in&lt;br /&gt;
		// to handle timing.&lt;br /&gt;
		// The script will resume after the yield with the call stack and local&lt;br /&gt;
		// variables preserved.&lt;br /&gt;
		yield();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
	<entry>
		<id>https://df-21.net/wiki/index.php?title=Dark_Forces_Wiki&amp;diff=1451</id>
		<title>Dark Forces Wiki</title>
		<link rel="alternate" type="text/html" href="https://df-21.net/wiki/index.php?title=Dark_Forces_Wiki&amp;diff=1451"/>
		<updated>2024-12-15T00:05:40Z</updated>

		<summary type="html">&lt;p&gt;Lucius: /* The Force Engine Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;text-align: center; font-size: x-large; padding: 1em;&amp;quot;&amp;gt;[[File:WikiLogo.png|center|frameless|561x561px]]&#039;&#039;&#039;Welcome to the {{SITENAME}}!&#039;&#039;&#039;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This community is dedicated to the 1995 game &#039;&#039;Star Wars: Dark Forces&#039;&#039; with an emphasis on modding and map making .  &lt;br /&gt;
&lt;br /&gt;
If you would like to contribute please create an account and help expand this wiki. &lt;br /&gt;
&lt;br /&gt;
=== Dark Forces Editors ===&lt;br /&gt;
&lt;br /&gt;
# &#039;&#039;&#039;[[WDFUSE]]&#039;&#039;&#039; - (&#039;&#039;&#039;The original Dark Forces Editor)&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;[https://theforceengine.github.io/ The Force Engine Editor]&#039;&#039;&#039; - &#039;&#039;&#039;(Under Development - Coming Soon in  2024)&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;[https://df-21.net/downloads/utilities.php CYBERDARK] - (Obsolete)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== How To Guides ===&lt;br /&gt;
* [https://df-21.net/wiki/?title=DF-21_Mission_Components Submitting DF-21 Missions]&lt;br /&gt;
* [https://df-21.net/wiki/?title=Converting_Classic_Maps Converting Old DF-21 Missions]&lt;br /&gt;
* [https://df-21.net/wiki/?title=How_To:_Good_MIDI How to get good sounding MIDI in Dark Forces]&lt;br /&gt;
* [https://df-21.net/wiki/?title=WAX_File_Generator How to generate an Enemy WAX file with Blender]]&lt;br /&gt;
* [https://df-21.net/wiki/?title=Blender_3DO_Guide How to create a 3DO file with Blender]]&lt;br /&gt;
* [[Level creation tips]]&lt;br /&gt;
&lt;br /&gt;
=== Dark Forces Reference ===&lt;br /&gt;
* [[Dark Forces Unofficial Specifications]]&lt;br /&gt;
* [[Dark Forces Remaster Unofficial Specs]]&lt;br /&gt;
&lt;br /&gt;
* [[Teleporter Basic]]&lt;br /&gt;
* [[VUE Camera transforms]]&lt;br /&gt;
&lt;br /&gt;
* [[Logics and AI reference]]&lt;br /&gt;
* [[Weapons reference]]&lt;br /&gt;
&lt;br /&gt;
=== The Force Engine Reference ===&lt;br /&gt;
* [[TFE_Mod_Overrides|Mod Overrides with MOD_CONF]]&lt;br /&gt;
* [[TFE Custom Logics]]&lt;br /&gt;
* [[TFE Projectile Data]]&lt;br /&gt;
* [[TFE Pickup Data]]&lt;br /&gt;
* [[TFE Level Script]]&lt;br /&gt;
&lt;br /&gt;
=== Vault ===&lt;br /&gt;
* [[:Category:Demo Assets|Assets included with the Dark Forces demo]]&lt;br /&gt;
&lt;br /&gt;
 [[Category:{{SITENAME}}]]&lt;/div&gt;</summary>
		<author><name>Lucius</name></author>
	</entry>
</feed>