Vector4
Element category: Vector
Represents a 4D Vector.
OOP-Only Methods and Variables
create
Default constructor for the Vector4 class. Returns a Vector4 object.
Vector4(mixed vectorOrX[, float y, float z, float w])- vectorOrX:
float | table | vector4– Vector4, table, or floats indicating vector's coordinates - y:
float– If vectorOrX is a float, this is the Y coordinate - z:
float– If vectorOrX is a float, this is the Z coordinate - w:
float– If vectorOrX is a float, this is the W coordinate
dot
Calculates the dot (scalar) product of two vectors.
float Vector4:dot ( Vector4 vector )- vector:
Vector4– Vector to calculate the dot product with.
getX
Returns the X component of the vector.
float Vector4:getX ( )setX
Sets the X component of the vector.
nil Vector4:setX ( float x )- x:
float– The new X value.
getY
Returns the Y component of the vector.
float Vector4:getY ( )setY
Sets the Y component of the vector.
nil Vector4:setY ( float y )- y:
float– The new Y value.
getZ
Returns the Z component of the vector.
float Vector4:getZ ( )setZ
Sets the Z component of the vector.
nil Vector4:setZ ( float z )- z:
float– The new Z value.
getW
Returns the W component of the vector.
float Vector4:getW ( )setW
Sets the W component of the vector.
nil Vector4:setW ( float w )- w:
float– The new W value.
normalize
Normalizes the vector to a unit vector (length of 1). Modifies the original vector.
bool Vector4:normalize ( )getNormalized
Returns a normalized version of the vector without modifying the original.
Vector4 Vector4:getNormalized ( )getLength
Returns the length (magnitude) of the vector.
float Vector4:getLength ( )getSquaredLength
Returns the squared length of the vector (useful to anil square root operations).
float Vector4:getSquaredLength ( )Code Examples
This example adds a command called "/garage", allowing you to get any garage bounding box.
function garageBoundingBox( _, garageID) if not garageID then outputChatBox("[Usage] /garage <id>") return end if tonumber(garageID) then if tonumber(garageID) > 0 and tonumber(garageID) < 50 then local boundingBox = Vector4(getGarageBoundingBox (garageID)) outputChatBox("West: "..boundingBox.x..", East: " ..boundingBox.y..", South: "..boundingBox.z.." North: "..boundingBox.w) else outputChatBox("Garage ID must be between 1 and 49") end endendaddCommandHandler ("garage",garageBoundingBox)