These functions are optimised for 3D graphics, and the collision of computer science and maths is apparent here, so scheme vectors representing maths 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.
Returns result-vector
Multiplies a vector by a number. Deprecated C version, the Scheme version is faster and more flexible.
Example
(vmulc (vector 1 2 3) 2)
Returns result-vector
Adds two vectors together. Deprecated C version, the Scheme version is faster and more flexible.
Example
(vaddc (vector 1 2 3) (vector 1 2 3))
Returns result-vector
Subtracts a vector from another. Deprecated C version, the Scheme version is faster and more flexible.
Example
(vsubc (vector 1 2 3) (vector 1 2 3))
Returns result-vector
Divides a vector by a number. Deprecated C version, the Scheme version is faster and more flexible.
Example
(vdivc (vector 1 2 3) 2)
Returns result-vector
Multiplies (transforms) a vector by a matrix
Example
(vtransform (vector 0 1 0) (mrotate (vector 90 0 0)))
Returns result-vector
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)))
Returns result-vector
Returns the normalised form of the vector (length=1)
Example
(vnormalise (vector 3 4 5))
Returns result-number
Returns the dot product of two vectors
Example
(vdot (vector 0 1 0) (vector 1 0 0))
Returns result-number
Returns the magnitude, or length of the vector
Example
(vmag (vector 0 1 1))
Returns result-vector
Returns the reflection of one vector against another.
Example
(vreflect (vector 0 1 1) (vector 1 0 1))
Returns result-number
Treating the vectors as points, returns the distance between them.
Example
(vdist (vector 100 100 0) (vector 0 0 100))
Returns result-number
Treating the vectors as points, returns the squared distance between them. Faster than vdist.
Example
(vdist-sq (vector 100 100 0) (vector 0 0 100))
Returns result-vector
Returns the cross product of two vectors, resulting in a vector that is perpendicular to the crossed ones.
Example
(vcross (vector 100 100 0) (vector 0 0 100))
Returns matrix-vector
Multiplies two matrices together
Example
(mmul (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
Returns matrix-vector
Adds two matrices together
Example
(madd (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
Returns matrix-vector
Subtracts a matrix from another.
Example
(msub (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
Returns matrix-vector
Divides a matrix by another
Example
(mdiv (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0)))
Returns matrix-vector
Returns the identity matrix
Example
(mident)
Returns matrix-vector
Returns a matrix representing the specified transform
Example
(mtranslate (vector 100 0 0))
Returns matrix-vector
Returns a matrix representing the specified rotation. Accepts a vector of euler angles, or a quaternion.
Example
(mrotate (vector 0 45 0))
Returns matrix-vector
Returns a matrix representing the specified scaling.
Example
(mscale (vector 0.5 2 0.5))
Returns matrix-vector
Returns the transpose of the input vector
Example
(mtranspose (mident))
Returns matrix-vector
Returns the inverse of the input vector.
Example
(minverse (mscale (vector 0.5 2 0.5)))
Returns matrix-vector
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))
Returns vector
Returns the euler angles extracted from the matrix.
Example
(matrix->euler (mrotate (vector 15 0 0)))
Returns quaternion-vector
Returns the quaternion representing rotation of angle degrees about the specified axis.
Example
(qaxisangle (vector 0 1 0) 45)
Returns quaternion-vector
Multiplies two quaternions together.
Example
(qmul (qaxisangle (vector 0 1 0) 45) (qaxisangle (vector 0 0 1) 180))
Returns quaternion-vector
Normalises a quaternion.
Example
(qnormalise (qaxisangle (vector 0 19 0) 45))
Returns matrix-vector
Converts a quaternion into a rotation matrix.
Example
(qtomatrix (qaxisangle (vector 0 1 0) 45))
Returns quaternion-vector
Conjugatea a quaternion.
Example
(qconjugate (qaxisangle (vector 0 1 0) 45))
Returns real-number
Returns the floating-point remainder of numerator/denominator.
Example
(fmod 14.4 10)
Returns real-number
Returns 1D/2D/3D/4D Simplex Noise in the range -1->1 depending on the number of parameters.
Example
(snoise 1.0 2.0) ; 2D noise (snoise 6.1 2.4 .5 1.3) ; 4D noise ; example on a pixel prim (clear) (with-primitive (build-pixels 100 100) (pdata-index-map! (lambda (i c) (snoise (* 0.1 (modulo i (pixels-width))) (* 0.1 (quotient i (pixels-height))))) "c") (pixels-upload))
Returns real-number
Returns the Perlin Noise value at specified coordinates.
Example
(noise 1.0 2.0) ; 2D noise (noise 6.1 2.4 .5) ; 3D noise ; example on a pixel prim (clear) (with-primitive (build-pixels 100 100) (pdata-index-map! (lambda (i c) (noise (* 0.1 (modulo i (pixels-width))) (* 0.1 (quotient i (pixels-height))))) "c") (pixels-upload))
Returns void
Sets the seed value for noise.
Example
(noise-seed 1)
Returns void
Adjusts the character and level of detail produced by the Perlin noise function.
Example
(noise-detail 4) ; noise with 4 octaves (noise-detail 4 .5) ; noise with 4 octaves and .5 falloff