Returns

Examples

vmath.cross

vmath.cross(v1, v2)

Given two linearly independent vectors P and Q, the cross product,
P × Q, is a vector that is perpendicular to both P and Q and
therefore normal to the plane containing them.

If the two vectors have the same direction (or have the exact
opposite direction from one another, i.e. are not linearly independent)
or if either one has zero length, then their cross product is zero.

vmath.length

If you are comparing the lengths of vectors or quaternions, you should compare
the length squared instead as it is slightly more efficient to calculate
(it eliminates a square root calculation).

Parameters

v

vector3 | vector4 | quat value of which to calculate the length

v

vector3 | vector4 | quat value of which to calculate the length

Returns

n

number length

n

number length

Examples

ifvmath.length(self.velocity)<max_velocitythen-- The speed (velocity vector) is below max.-- TODO: max_velocity can be expressed as squared-- so we can compare with length_sqr() instead....end

vmath.length_sqr

vmath.length_sqr(v)

Returns the squared length of the supplied vector or quaternion.

Parameters

v

vector3 | vector4 | quat value of which to calculate the squared length

v

vector3 | vector4 | quat value of which to calculate the squared length

Returns

n

number squared length

n

number squared length

Examples

ifvmath.length_sqr(vector1)<vmath.length_sqr(vector2)then-- Vector 1 has less magnitude than vector 2...end

vmath.lerp

vmath.lerp(t, v1, v2)

Linearly interpolate between two vectors. The function
treats the vectors as positions and interpolates between
the positions in a straight line. Lerp is useful to describe
transitions from one place to another over time.

Examples

vmath.matrix4_frustum

vmath.matrix4_frustum(left, right, bottom, top, near, far)

Constructs a frustum matrix from the given values. The left, right,
top and bottom coordinates of the view cone are expressed as distances
from the center of the near clipping plane. The near and far coordinates
are expressed as distances from the tip of the view frustum cone.

Parameters

left

number coordinate for left clipping plane

right

number coordinate for right clipping plane

bottom

number coordinate for bottom clipping plane

top

number coordinate for top clipping plane

near

number coordinate for near clipping plane

far

number coordinate for far clipping plane

left

number coordinate for left clipping plane

right

number coordinate for right clipping plane

bottom

number coordinate for bottom clipping plane

top

number coordinate for top clipping plane

near

number coordinate for near clipping plane

far

number coordinate for far clipping plane

Returns

m

matrix4 matrix representing the frustum

m

matrix4 matrix representing the frustum

Examples

-- Construct a projection frustum with a vertical and horizontal-- FOV of 45 degrees. Useful for rendering a square view.localproj=vmath.matrix4_frustum(-1,1,-1,1,1,1000)render.set_projection(proj)

vmath.matrix4_look_at

vmath.matrix4_look_at(eye, look_at, up)

The resulting matrix is created from the supplied look-at parameters.
This is useful for constructing a view matrix for a camera or
rendering in general.

vmath.matrix4_orthographic

Creates an orthographic projection matrix.
This is useful to construct a projection matrix for a camera or rendering in general.

Parameters

left

number coordinate for left clipping plane

right

number coordinate for right clipping plane

bottom

number coordinate for bottom clipping plane

top

number coordinate for top clipping plane

near

number coordinate for near clipping plane

far

number coordinate for far clipping plane

left

number coordinate for left clipping plane

right

number coordinate for right clipping plane

bottom

number coordinate for bottom clipping plane

top

number coordinate for top clipping plane

near

number coordinate for near clipping plane

far

number coordinate for far clipping plane

Returns

m

matrix4 orthographic projection matrix

m

matrix4 orthographic projection matrix

Examples

-- Set up an orthographic projection based on the width and height-- of the game window.localw=render.get_width()localh=render.get_height()localproj=vmath.matrix4_orthographic(-w/2,w/2,-h/2,h/2,-1000,1000)render.set_projection(proj)

vmath.matrix4_perspective

vmath.matrix4_perspective(fov, aspect, near, far)

Creates a perspective projection matrix.
This is useful to construct a projection matrix for a camera or rendering in general.

vmath.slerp

vmath.slerp(t, q1, q2)

Slerp travels the torque-minimal path maintaining constant
velocity, which means it travels along the straightest path along
the rounded surface of a sphere. Slerp is useful for interpolation
of rotations.

Slerp travels the torque-minimal path, which means it travels
along the straightest path the rounded surface of a sphere.