Expand/Shrink

glmath

Definition: include pGUI.e
include opengl.e -- (see notes)

sequence res = m4_crossProduct(sequence a, b)
-- or --
sequence res = m4_inverse(sequence m)
-- or --
sequence res = m4_lookAt(sequence cPosn, tgt, up)
-- or --
sequence res = m4_multiply(sequence a, b)
-- or --
sequence res = m4_normalize(sequence v)
-- or --
sequence res = m4_perspective(atom fieldOfViewInRadians, aspect, near, far)
-- or --
sequence res = m4_subtractVectors(sequence a, b)
-- or --
sequence res = m4_xRotate(sequence m, atom angleInRadians)
-- or --
sequence res = m4_yRotate(sequence m, atom angleInRadians)
Description: A collection of matrix array maths routines, mostly (manually) translated from JavaScript as found on https://webglfundamentals.org into Phix, and then (automatically) back into JavaScript by pwa\p2js
pwa/p2js: Supported.
Description: Note that demo\pGUI\opengl.e includes builtins\glmath.e, and pwa\p2js understands enough to effect the same, and although it is not an autoinclude the latter treats it pretty much the same, in other words opengl.js is a hand-crafted replacement, but glmath.e is auto-transpiled.

sequence res = m4_crossProduct(sequence a, b)
Computes the cross product of 2 vectors (both of length 3), returns a new vector

sequence res = m4_inverse(sequence m)
Computes the inverse of a matrix.
m: matrix to compute inverse of (a 4x4 matrix represented as a flat 16-element sequence)
Returns a new 4x4 matrix represented as a flat 16-element sequence.

sequence res = m4_lookAt(sequence cPosn, tgt, up)
Creates a lookAt matrix, a world matrix for a camera.
In other words it will transform from the origin to a place and orientation in the world.
For a view matrix take the inverse of this.
cPosn: position of the camera (a vector of length 3)
tgt: position of the target ("")
up: direction ("")
Returns a new 4x4 matrix represented as a flat 16-element sequence.

sequence res = m4_multiply(sequence a, b)
Takes two 4-by-4 matrices, a and b (represented as flat 16-element sequences), and computes the product in the order that pre-composes b with a. In other words, the matrix returned will transform by b first and then a.
Note this is subtly different from just multiplying the matrices together.
For given a and b, this function returns the same object in both row-major and column-major mode.
Returns a new 4x4 matrix represented as a flat 16-element sequence.

sequence res = m4_normalize(sequence v)
Normalizes a vector.
v: vector (length 3) to normalize
Returns a new vector

sequence res = m4_perspective(atom fieldOfViewInRadians, aspect, near, far)
Computes a 4-by-4 perspective transformation matrix given the angular height of the frustum, the aspect ratio, and the near and far clipping planes.
The arguments define a frustum extending in the negative z direction.
The given angle is the vertical angle of the frustum, and the horizontal angle is determined to produce the given aspect ratio.
The arguments near and far are the distances to the near and far clipping planes.
Note that near and far are not z coordinates, but rather they are distances along the negative z-axis.
The matrix generated sends the viewing frustum to the unit box.
We assume a unit box extending from -1 to 1 in the x and y dimensions and from -1 to 1 in the z dimension.
fieldOfViewInRadians: field of view in y axis
aspect: aspect of viewport (width / height)
near: near Z clipping plane
far: far Z clipping plane
Returns a new 4x4 matrix represented as a flat 16-element sequence.

sequence res = m4_subtractVectors(sequence a, b)
Subtracts 2 vectors (both of length 3), returns a new vector.

sequence res = m4_xRotate(sequence m, atom angleInRadians)
Multiply by an x rotation matrix
m: matrix to multiply (a 4x4 matrix represented as a flat 16-element sequence)
angleInRadians: amount to rotate
Returns a new 4x4 matrix represented as a flat 16-element sequence.

sequence res = m4_yRotate(sequence m, atom angleInRadians)
Multiply by a y rotation matrix
m: matrix to multiply (a 4x4 matrix represented as a flat 16-element sequence)
angleInRadians: amount to rotate
Returns a new 4x4 matrix represented as a flat 16-element sequence.

Not much else to say about them really, but as usual improvements, bug fixes, extensions, suggestions, and so on are all welcome.

See Also: glUniform