EAGL.Math (eagl v0.1.0)
View SourcePort of the OpenGL GLM header files to Elixir. Note that Erlang wx OpenGL represents matricies and vectors as flat tuples nested in lists.
Summary
Functions
Absolute value.
Calculate angle between two vectors in radians.
Clamp value between min and max.
Compute the cross product of two 3D vectors.
Convert radians to degrees.
Calculate the distance between two points (vectors).
Calculate the squared distance between two points (avoids sqrt).
Compute the dot product of two vectors (2D, 3D, or 4D).
Calculate face normal from three vertices (assumes counter-clockwise winding).
Fractional part of x (x - floor(x)).
Fast inverse square root approximation.
Compute the squared length of a vector (avoids sqrt for performance).
Linear interpolation between two values.
Create a 2x2 matrix.
Create a 2x2 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create a 3x3 matrix.
Create a 3x3 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply two 3x3 matrices. All matrices are in column-major order for OpenGL compatibility.
Transpose a 3x3 matrix. Input and output matrices are in column-major order for OpenGL compatibility.
Create a 4x4 matrix.
Create a 4x4 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create the inverse of a 4x4 matrix using the adjugate method. Returns the original matrix if it's not invertible (determinant is zero). Input and output matrices are in column-major order for OpenGL compatibility. Note this is the only function not from the original OpenGl GLM library.
Create a look-at view matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply two 4x4 matrices. All matrices are in column-major order for OpenGL compatibility.
Create an orthographic projection matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create a perspective projection matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix from axis and angle.
Create a rotation matrix around the X axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix around the Y axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix around the Z axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a scale matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply a 3D vector by a 4x4 matrix (treating vector as point with w=1). Returns a 3D vector with the w component divided out.
Multiply a 4D vector by a 4x4 matrix.
Multiply a 3D vector by a 4x4 matrix (treating vector as direction with w=0). Used for transforming direction vectors (normals, etc.) where translation should be ignored.
Create a translation matrix. Matrix is stored in column-major order for OpenGL compatibility.
Transpose a 4x4 matrix. Input and output matrices are in column-major order for OpenGL compatibility.
Mix (linear interpolation) between two values.
Modulo operation that works with floats.
Normalize a vector to unit length (2D, 3D, or 4D).
Check if two vectors are parallel (dot product close to ±1).
Check if two vectors are perpendicular (dot product close to 0).
Project vector a onto vector b.
Create a quaternion. Quaternions are represented as {x, y, z, w} where w is the scalar component. This follows the (x, y, z, w) convention commonly used in graphics programming.
Conjugate a quaternion (negate x, y, z components).
Create a quaternion from axis-angle representation.
Create a quaternion from Euler angles (pitch, yaw, roll in radians).
Create an identity quaternion (no rotation).
Multiply two quaternions.
Normalize a quaternion.
Rotate a 3D vector by a quaternion.
Spherical linear interpolation between two quaternions.
Convert quaternion to rotation matrix (3x3). Matrix is stored in column-major order for OpenGL compatibility.
Convert quaternion to rotation matrix (4x4). Matrix is stored in column-major order for OpenGL compatibility.
Convert degrees to radians.
Reflect a vector around a normal.
Refract a vector around a normal with given refractive index ratio.
Reject vector a from vector b (perpendicular component).
Sign function (-1, 0, or 1).
Smooth step function (Hermite interpolation).
Step function (returns 0.0 if x < edge, 1.0 otherwise).
Create a 2D vector.
Create a zero vector (2D).
Create a 3D vector.
Create a 3D vector with all components set to 1.
Create the X unit vector (1, 0, 0).
Create the Y unit vector (0, 1, 0).
Create the Z unit vector (0, 0, 1).
Create a zero vector (3D).
Create a 4D vector.
Create a zero vector (4D).
Add two vectors component-wise.
Compute the length (magnitude) of a vector (2D, 3D, or 4D).
Linear interpolation between two vectors.
Negate a vector (multiply by -1).
Multiply a vector by a scalar.
Subtract two vectors component-wise.
Types
Functions
Absolute value.
Calculate angle between two vectors in radians.
Clamp value between min and max.
Compute the cross product of two 3D vectors.
Convert radians to degrees.
@spec distance(vec2(), vec2()) :: float()
@spec distance(vec3(), vec3()) :: float()
@spec distance(vec4(), vec4()) :: float()
Calculate the distance between two points (vectors).
@spec distance_squared(vec2(), vec2()) :: float()
@spec distance_squared(vec3(), vec3()) :: float()
@spec distance_squared(vec4(), vec4()) :: float()
Calculate the squared distance between two points (avoids sqrt).
@spec dot(vec2(), vec2()) :: float()
@spec dot(vec3(), vec3()) :: float()
@spec dot(vec4(), vec4()) :: float()
Compute the dot product of two vectors (2D, 3D, or 4D).
Calculate face normal from three vertices (assumes counter-clockwise winding).
Fractional part of x (x - floor(x)).
Fast inverse square root approximation.
@spec length_squared(vec2()) :: float()
@spec length_squared(vec3()) :: float()
@spec length_squared(vec4()) :: float()
Compute the squared length of a vector (avoids sqrt for performance).
Linear interpolation between two values.
Create a 2x2 matrix.
@spec mat2_identity() :: mat2()
Create a 2x2 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
@spec mat3( float(), float(), float(), float(), float(), float(), float(), float(), float() ) :: mat3()
Create a 3x3 matrix.
@spec mat3_identity() :: mat3()
Create a 3x3 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply two 3x3 matrices. All matrices are in column-major order for OpenGL compatibility.
Transpose a 3x3 matrix. Input and output matrices are in column-major order for OpenGL compatibility.
@spec mat4( float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float(), float() ) :: mat4()
Create a 4x4 matrix.
@spec mat4_identity() :: mat4()
Create a 4x4 identity matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create the inverse of a 4x4 matrix using the adjugate method. Returns the original matrix if it's not invertible (determinant is zero). Input and output matrices are in column-major order for OpenGL compatibility. Note this is the only function not from the original OpenGl GLM library.
Create a look-at view matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply two 4x4 matrices. All matrices are in column-major order for OpenGL compatibility.
Create an orthographic projection matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create a perspective projection matrix. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix from axis and angle.
Create a rotation matrix around the X axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix around the Y axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a rotation matrix around the Z axis. Matrix is stored in column-major order for OpenGL compatibility.
Create a scale matrix. Matrix is stored in column-major order for OpenGL compatibility.
Multiply a 3D vector by a 4x4 matrix (treating vector as point with w=1). Returns a 3D vector with the w component divided out.
Multiply a 4D vector by a 4x4 matrix.
Multiply a 3D vector by a 4x4 matrix (treating vector as direction with w=0). Used for transforming direction vectors (normals, etc.) where translation should be ignored.
Create a translation matrix. Matrix is stored in column-major order for OpenGL compatibility.
Transpose a 4x4 matrix. Input and output matrices are in column-major order for OpenGL compatibility.
Mix (linear interpolation) between two values.
Modulo operation that works with floats.
@spec normalize(vec2()) :: vec2()
@spec normalize(vec3()) :: vec3()
@spec normalize(vec4()) :: vec4()
Normalize a vector to unit length (2D, 3D, or 4D).
Check if two vectors are parallel (dot product close to ±1).
Check if two vectors are perpendicular (dot product close to 0).
Project vector a onto vector b.
Create a quaternion. Quaternions are represented as {x, y, z, w} where w is the scalar component. This follows the (x, y, z, w) convention commonly used in graphics programming.
Conjugate a quaternion (negate x, y, z components).
Create a quaternion from axis-angle representation.
Create a quaternion from Euler angles (pitch, yaw, roll in radians).
@spec quat_identity() :: quat()
Create an identity quaternion (no rotation).
Multiply two quaternions.
Normalize a quaternion.
Rotate a 3D vector by a quaternion.
Spherical linear interpolation between two quaternions.
Convert quaternion to rotation matrix (3x3). Matrix is stored in column-major order for OpenGL compatibility.
Convert quaternion to rotation matrix (4x4). Matrix is stored in column-major order for OpenGL compatibility.
Convert degrees to radians.
Reflect a vector around a normal.
Refract a vector around a normal with given refractive index ratio.
Reject vector a from vector b (perpendicular component).
Sign function (-1, 0, or 1).
Smooth step function (Hermite interpolation).
Step function (returns 0.0 if x < edge, 1.0 otherwise).
Create a 2D vector.
@spec vec2_zero() :: vec2()
Create a zero vector (2D).
Create a 3D vector.
@spec vec3_one() :: vec3()
Create a 3D vector with all components set to 1.
@spec vec3_unit_x() :: vec3()
Create the X unit vector (1, 0, 0).
@spec vec3_unit_y() :: vec3()
Create the Y unit vector (0, 1, 0).
@spec vec3_unit_z() :: vec3()
Create the Z unit vector (0, 0, 1).
@spec vec3_zero() :: vec3()
Create a zero vector (3D).
Create a 4D vector.
@spec vec4_zero() :: vec4()
Create a zero vector (4D).
@spec vec_add(vec2(), vec2()) :: vec2()
@spec vec_add(vec3(), vec3()) :: vec3()
@spec vec_add(vec4(), vec4()) :: vec4()
Add two vectors component-wise.
@spec vec_length(vec2()) :: float()
@spec vec_length(vec3()) :: float()
@spec vec_length(vec4()) :: float()
Compute the length (magnitude) of a vector (2D, 3D, or 4D).
@spec vec_lerp(vec2(), vec2(), float()) :: vec2()
@spec vec_lerp(vec3(), vec3(), float()) :: vec3()
@spec vec_lerp(vec4(), vec4(), float()) :: vec4()
Linear interpolation between two vectors.
@spec vec_negate(vec2()) :: vec2()
@spec vec_negate(vec3()) :: vec3()
@spec vec_negate(vec4()) :: vec4()
Negate a vector (multiply by -1).
@spec vec_scale(vec2(), float()) :: vec2()
@spec vec_scale(vec3(), float()) :: vec3()
@spec vec_scale(vec4(), float()) :: vec4()
Multiply a vector by a scalar.
@spec vec_sub(vec2(), vec2()) :: vec2()
@spec vec_sub(vec3(), vec3()) :: vec3()
@spec vec_sub(vec4(), vec4()) :: vec4()
Subtract two vectors component-wise.