Next: , Previous: LocalState, Up: Functions



12.6 Maths

These functions are optimised for 3D graphics, and the collision of computer science and maths is apparent here, so vectors representing "vectors" are in this context taken to be 3 elements long, quaternions are vectors of length 4, and matrices are vectors of 16 elements long.

Example
     

12.6.1 (vmul vector number)

Returns

result-vector

Description

Multiplies a vector by a number

Example
      (vmul (vector 1 2 3) 2)
     

12.6.2 (vadd vector vector)

Returns

result-vector

Description

Adds two vectors together

Example
      (vadd (vector 1 2 3) (vector 1 2 3))
     

12.6.3 (vsub vector vector)

Returns

result-vector

Description

Subtracts a vector from another

Example
      (vsub (vector 1 2 3) (vector 1 2 3))
     

12.6.4 (vdiv vector number)

Returns

result-vector

Description

Divides a vector by a number

Example
      (vdiv (vector 1 2 3) 2)
     

12.6.5 (vtransform vector matrix)

Returns

result-vector

Description

Multiplies (transforms) a vector by a matrix

Example
      (vtransform (vector 0 1 0) (mrotate (vector 90 0 0)))
     

12.6.6 (vtransform-rot vector matrix)

Returns

result-vector

Description

Multiplies (transforms) a vector by a matrix, but leaves out the translation part. For operations involving normals.

Example
      (vtransform-rot (vector 0 1 0) (mrotate (vector 90 0 0)))
     

12.6.7 (vnormalise vector)

Returns

result-vector

Description

Returns the normalised form of the vector (length=1)

Example
      (vtransform-rot (vector 0 1 0) (mrotate (vector 90 0 0)))
     

12.6.8 (vdot vector vector)

Returns

result-number

Description

Returns the dot product of two vectors

Example
      (vdot (vector 0 1 0) (vector 1 0 0))
     

12.6.9 (vmag vector)

Returns

result-number

Description

Returns the magnitude, or length of the vector

Example
      (vmag (vector 0 1 1))
     

12.6.10 (vdist vector vector)

Returns

result-number

Description

Treating the vectors as points, returns the distance between them

Example
      (vdist (vector 100 100 0) (vector 0 0 100))
     

12.6.11 (vcross vector vector)

Returns

result-vector

Description

Returns the cross product of two vectors

Example
      (vcross (vector 100 100 0) (vector 0 0 100))
     

12.6.12 (mmul matrix-vector matrix-vector)

Returns

matrix-vector

Description

Multiplies two matrices together

Example
      (vmul (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
     

12.6.13 (madd matrix-vector matrix-vector)

Returns

matrix-vector

Description

Adds two matrices together

Example
      (vadd (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
     

12.6.14 (msub matrix-vector matrix-vector)

Returns

matrix-vector

Description

Subtracts a matrix from another

Example
      (vsub (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
     

12.6.15 (mdiv matrix-vector matrix-vector)

Returns

matrix-vector

Description

Divides a matrix by another

Example
      (vdiv (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
     

12.6.16 (mident)

Returns

matrix-vector

Description

Returns the identity matrix

Example
      (mident)
     

12.6.17 (mtranslate vector)

Returns

matrix-vector

Description

Returns a matrix representing the specified transform

Example
      (mtransform (vector 100 0 0))
     

12.6.18 (mrotate vector)

Returns

matrix-vector

Description

Returns a matrix representing the specified rotation. Accepts a vector of euler angles, or a quaternion.

Example
      (mrotate (vector 0 45 0))
     

12.6.19 (mscale vector)

Returns

matrix-vector

Description

Returns a matrix representing the specified scaling.

Example
      (mscale (vector 0.5 2 0.5))
     

12.6.20 (mtranspose matrix-vector)

Returns

matrix-vector

Description

Returns the transpose of the input vector

Example
      (mtranspose (mident))
     

12.6.21 (minverse matrix-vector)

Returns

matrix-vector

Description

Returns the inverse of the input vector

Example
      (minverse (mscale (vector 0.5 2 0.5)))
     

12.6.22 (maim aim-vector up-vector)

Returns

matrix-vector

Description

Returns a matrix representing an aiming rotation so that the x axis points down the aim direction, and the y axis points up the up vector. Probably suffers from gimbal lock.

Example
      (maim (vector 0 0 1) (vector 0 1 0))
     

12.6.23 (qaxisangle axis-vector angle-number)

Returns

quaternion-vector

Description

Returns the quaternion representing rotation of angle degrees about the specified axis.

Example
      (qaxisangle (vector 0 1 0) 45)
     

12.6.24 (qmul quaternion-vector quaternion-vector)

Returns

quaternion-vector

Description

Multiplies two quaternions together.

Example
      (qmul (qaxisangle (vector 0 1 0) 45) (qaxisangle (vector 0 0 1) 180))
     

12.6.25 (qnormalise quaternion-vector)

Returns

quaternion-vector

Description

Normalises a quaternion.

Example
      (qnormalise (qaxisangle (vector 0 19 0) 45))
     

12.6.26 (qtomatrix quaternion-vector)

Returns

matrix-vector

Description

Converts a quaternion into a rotation matrix.

Example
      (qtomatrix (qaxisangle (vector 0 1 0) 45))
     

12.6.27 (qconjugate quaternion-vector)

Returns

quaternion-vector

Description

Conjugatea a quaternion.

Example
      (qconjugate (qaxisangle (vector 0 1 0) 45))