Binding of Isaac - Afterbirth+ Lua Reference/Guide
Vector Class Reference

Public Member Functions

 Vector (float, float)
 
 Normalize ()
 
Vector Normalized ()
 
float Dot (Vector second)
 
float Cross (Vector second)
 
Vector Lerp (Vector first, Vector second, float t) *
 
float Distance (Vector first, Vector second)
 
float DistanceSquared (Vector first, Vector second)
 
Vector Rotated (float AngleDegrees)
 
float GetAngleDegrees ()
 
 Resize (float NewLength)
 
Vector Resized (float NewLength)
 
 Clamp (float MinX, float MinY, float MaxX, float MaxY)
 
Vector Clamped (float MinX, float MinY, float MaxX, float MaxY)
 
float Length ()
 
float LengthSquared ()
 
Vector __add (Vector Right)
 
Vector __sub (Vector Right)
 
Vector __mul (float Modifier)
 
Vector __div (float Modifier)
 
Vector __unm (Vector Right)
 

Static Public Member Functions

static Vector FromAngle (float AngleDegrees)
 

Public Attributes

float X
 Components of vector. More...
 
float Y
 

Constructor & Destructor Documentation

§ Vector()

Vector::Vector ( float  ,
float   
)

Member Function Documentation

§ __add()

Vector Vector::__add ( Vector  Right)

Addition operators

§ __div()

Vector Vector::__div ( float  Modifier)

Division operators

§ __mul()

Vector Vector::__mul ( float  Modifier)

Multiplication operators

§ __sub()

Vector Vector::__sub ( Vector  Right)

Subtraction operators

§ __unm()

Vector Vector::__unm ( Vector  Right)

Subtraction operators

§ Clamp()

Vector::Clamp ( float  MinX,
float  MinY,
float  MaxX,
float  MaxY 
)

Clamps the vector based on left, top, right, bottom boundings. Doesn't keep direction

§ Clamped()

Vector Vector::Clamped ( float  MinX,
float  MinY,
float  MaxX,
float  MaxY 
)

Returns a clamped version of the vector.

§ Cross()

float Vector::Cross ( Vector  second)

Cross product this is the 2x2 matrix determinant or the resulting z value for their 3D versions with z=0

§ Distance()

float Vector::Distance ( Vector  first,
Vector  second 
)

Returns distance between two vectors

local sqtDist = Vector(2,0):Distance(Vector(4,0))) --sqtDist = 2

§ DistanceSquared()

float Vector::DistanceSquared ( Vector  first,
Vector  second 
)

Returns squared distance between two vectors

local sqtDist = Vector(2,0):DistanceSquared(Vector(4,0))) --sqtDist = 4

§ Dot()

float Vector::Dot ( Vector  second)

Dot product

§ FromAngle()

static Vector Vector::FromAngle ( float  AngleDegrees)
static

Build a Vector from an angle, returns a normalized vector. Angle 0 will result in (1, 0). Angle 90 will result in (0, 1).

This code returns a vector that has a 45 degree angle
local vec = Vector.FromAngle(45)) --vec is now Vector(0.70711,0.70711)

§ GetAngleDegrees()

float Vector::GetAngleDegrees ( )

Returns the angle the vector is facing. The vector (1, 0) will be at 0 degrees. The vector (0, 1) will be at 90 degrees.

This code returns the angle between two positions.
local v1 = Vector(1,0) -- has angle 0.0
local v2 = Vector(0,1) -- has angle 90.0
local v3 = v2-v1 -- subtraction of 2 points is a vector connecting the two points
print(v3:GetAngleDegrees()) -- prints 45.0 

§ Length()

float Vector::Length ( )

Returns the length of the vector

§ LengthSquared()

float Vector::LengthSquared ( )

Returns the length squared of the vector

§ Lerp()

Vector Vector::Lerp ( Vector  first,
Vector  second,
float  t 
)

Linear interpolation between two vectors. For t = 0 it returns the first Vector, for t = 1 it returns the second.

This code will make v1 the vector 50% in between v1 and v2
local v1 = Vector(0,0)
local v2 = Vector(1,1)
v1:Lerp(v2,0.5) -- v1 equals  Vector(0.5,0.5)  now
This function does the same as Lerp, but will not alter the input vectors.
function Lerp(vec1, vec2, percent)
    return vec1 * (1 - percent) + vec2 * percent
end

§ Normalize()

Vector::Normalize ( )

Normalizes this vector

§ Normalized()

Vector Vector::Normalized ( )

Returns a normalized version of this vector

§ Resize()

Vector::Resize ( float  NewLength)

Resizes the vector length.

§ Resized()

Vector Vector::Resized ( float  NewLength)

Returns a resized version of the vector.

§ Rotated()

Vector Vector::Rotated ( float  AngleDegrees)

Returns a rotated version of the vector by AngleDegrees

Member Data Documentation

§ X

float Vector::X

Components of vector.

§ Y

float Vector::Y