Basic Types - MrShoor/AvalancheProject GitHub Wiki
There are a number of basic types used across Avalanche Project classes. These types are declare in mutils unit. (The Pascal compiler should support "advanced records" aka records with methods in order to compile the unit)
Variations
Most of types come in the three basic types:
- single - no suffix,
- integer (signed 32-bit) suffix "i"
- short (signed 16-bit integer) suffix "s"
- byte (unsigned 6-bit) suffix "b"
For example, vector type TVec3 (representing 3 coordinates vector) would be available in following variations:
- TVec3 - all 3 vector components are of single type
- TVec3i - all 3 vector components are of integer type
- TVec3s - all 3 vector components are of short type
- TVec3b - all 3 vector components of type byte.
Utility functions, provided for the type would not have a corresponding based type suffix. Some scalar functions however would return use the base type as a return type. For example SqlLen for a vector of type "short" would be returning "short" length,
For each type, there's always a declared pointer type available. The type name starts with "P", replacing the heading "T"
- PVec3
- PVec3i... etc...
Vector types
- TVec2
- TVec3
- TVec4
- Arrays of Vectors
Utility functions
-
function Vec(const a,b,c,d) - returns a vector with initialized values.
-
function Abs(const v) - returns a vector with absolute values for each vector component
-
function Min(const a, b) - returns the a new vector containing minimum of two vectors components
-
function Max(const a, b) - returns the a new vector containing maximum of two vectors components
-
function Clamp(const v; minval, maxval) - returns a vector with component values clamped to the specified minimum and maximum borders
-
function Sign(const v) - returns a vector with each component set to the value of a sign of the passed vector
-
function Dot(const v1, v2) - returns dot-product of two vectors
-
function Cross(const v1, v2) - returns cross-product of two vectors
-
function LenSqr(const v): TCompType; - returns the square length of a vector
-
function Equal(const v1, v2; AEPS = EPS ): Boolean - compares two data types and returns true, if they match close enough (the difference is below AEPS parameter).
-
procedure Swap(var v1, v2) - values of the vector variables
-
StreamReadVecArr - available for Vector types only - reads an array of vector from stream
-
StreamWriteVecArr - available for Vector types only - writes an array of vector to stream
Colors
A color is typically passed as float-point 4-components parameter, thus TVec4 class is used. The values are populated in the RGBA order.
Matix Types
- TMat2
- TMat3
- TMat4
- Arrays of Matrix
Utility functions
- function Transpose(const m1) - returns a transpose matrix of the given matrix
- function Det(const m1) - returns determinant for the given matrix
- function Equal(const v1, v2; AEPS = EPS ): Boolean - compares corresponding elements of matrix, returns true, if they match close enough (the difference is below AEPS parameter).
- procedure Swap(var v1, v2) - swaps values of matrix variables