VectR.lua

From Moondust Wiki
Revision as of 02:30, 7 August 2015 by Hoeloe (talk | contribs) (Created page with "'''THIS DOCUMENTATION IS A WORK IN PROGRESS. PLEASE COME BACK WHEN IT IS COMPLETE''' VectR is a library designed to simplify vector mathematics and matrix calculations. It su...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

THIS DOCUMENTATION IS A WORK IN PROGRESS. PLEASE COME BACK WHEN IT IS COMPLETE

VectR is a library designed to simplify vector mathematics and matrix calculations. It supports 2,3 and 4 dimensional vectors, as well as their equivalent square matrices.

Installation

Place the file vectr.lua into the LuaScriptsLib folder.


How to use

To enable the VectR library for a specific level, add this line to lunadll.lua:

local vectr = loadAPI("vectr");

This will load the VectR API.

Example

local vectr = loadAPI("vectr");
    
--Create a 3 dimensional vector
local v = vectr.v3(13,26,-3);
--Create a 3x3 matrix
local m = vectr.mat3({2,4,-1},{8,6,6},{0,1,7});

function onLoop()
    --Perform a matrix multiplication to transform the vector.
    Text.print(tostring(m*v),0,0);
end

This will transform the vector "v" by the matrix "m".

Documentation

Classes

These are classes contained within this library

Vector2

Values

Vector2.x The x value of the vector
Vector2.y The y value of the vector
Vector2.length The length of the vector
Vector2.sqrlength The squared length of the vector
Vector2._type A constant value that always contains the string "vector2"

Functions

Vector2:normalise
Calculates the normalised direction vector. Vector2
Vector2:normalize
Equivalent to "normalise". Vector2
Vector2:dot vector
Calculates the dot product between two vectors. Vector2 Vector2

The other vector.

Vector2:project vector
Projects the vector onto the line defined by the other vector. Vector2 Vector2

The other vector.

Vector2:rotate angle
Rotates the vector by a given angle. Vector2 number

The rotation angle in degrees.

Vector2:lookat vector
Rotates a vector to point in the direction of the other vector. Vector2 Vector2

The other vector.

Vector2:tov3
Converts a vector to a 3 dimensional vector. The z-value will be set to 0. Vector2
Vector2:tov4
Converts a vector to a 4 dimensional vector. The z-value and w-value will be set to 0. Vector2

External Use Functions

These are functions you will need to use the library

v2 x y
Creates a Vector2 object. Vector2 number

The X component.

number

The Y component.

v2 v
Copies a Vector2 object. Vector2 Vector2

The vector to copy.