struct
Eagle::Mat4
- Eagle::Mat4
- Struct
- Value
- Object
Overview
A 4x4 matrix in column-major order, matching OpenGL. Index it as m[col, row].
Eagle builds matrices for you: Node3D#transform, Camera3D#view and
Camera3D#projection. You need Mat4 directly for custom shaders, or when you
place things by hand in Scene3D space.
model = Mat4.trs(v3(0, 1, 0), Quat.from_axis_angle(Vec3::UP, 0.5), Vec3.new(2))
world = model.transform_point(v3(1, 0, 0)) # local point to world
back = model.inverse.transform_point(world)
view = Mat4.look_at(v3(0, 3, 8), Vec3::ZERO)
proj = Mat4.perspective(Mathf.deg2rad(60), 16 / 9, 0.1, 100)
mvp = proj * view * model # what a vertex shader needs
Defined in:
eagle/math/mat4.crConstant Summary
-
IDENTITY =
identity -
The identity matrix, as a constant.
Constructors
-
.identity : Mat4
The identity matrix.
-
.look_at(eye : Vec3, target : Vec3, up : Vec3 = Vec3::UP) : Mat4
A view matrix for a camera at eye looking at target.
-
.new(m : StaticArray(Float32, 16))
Wraps 16 floats in column-major order.
-
.new
Creates the zero matrix.
-
.orthographic(left : Number, right : Number, bottom : Number, top : Number, near : Number = -1, far : Number = 1) : Mat4
An orthographic projection: no perspective, so parallel lines stay parallel.
-
.perspective(fov_y_rad : Number, aspect : Number, near : Number, far : Number) : Mat4
A perspective projection with a vertical field of view in radians.
-
.rotation(axis : Vec3, rad : Number) : Mat4
Rotation of rad radians around an arbitrary axis.
-
.rotation_x(rad : Number) : Mat4
Rotation around the X axis (pitch).
-
.rotation_y(rad : Number) : Mat4
Rotation around the Y axis (yaw).
-
.rotation_z(rad : Number) : Mat4
Rotation around the Z axis (roll).
-
.scale(v : Vec3) : Mat4
A scale matrix.
-
.scale(s : Number) : Mat4
A uniform scale matrix.
-
.translation(x : Number, y : Number, z : Number = 0) : Mat4
A translation matrix from components.
-
.translation(v : Vec3) : Mat4
A translation matrix.
-
.trs(t : Vec3, r : Quat, s : Vec3) : Mat4
Translation * rotation * scale, the usual model matrix.
Instance Method Summary
-
#*(o : Mat4) : Mat4
Composes matrices:
(a * b)applies b first, then a. -
#*(v : Vec4) : Vec4
Transforms a
Vec4. -
#==(o : Mat4) : Bool
Exact equality.
-
#[](col : Int, row : Int) : Float32
Reads the element at col, row.
-
#[]=(col : Int, row : Int, v : Number)
Writes the element at col, row.
-
#approx?(o : Mat4, eps = 1e-4) : Bool
True when all elements are within eps.
-
#data : StaticArray(Float32, 16)
The raw column-major storage.
-
#determinant : Float32
The determinant.
-
#inverse : Mat4
The inverse matrix, for going from world space back to local space.
-
#to_a : Array(Float32)
The 16 floats as an array.
-
#to_mat3 : Mat3
The upper-left 3x3, used to build normal matrices.
-
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#to_unsafe : Pointer(Float32)
Pointer to the 16 floats, for passing to OpenGL.
-
#transform_dir(v : Vec3) : Vec3
Transforms a direction (w = 0), which ignores translation.
-
#transform_point(v : Vec3) : Vec3
Transforms a point (w = 1) and performs the perspective divide.
-
#translation : Vec3
The translation part.
-
#transposed : Mat4
Rows and columns swapped.
Constructor Detail
A view matrix for a camera at eye looking at target.
An orthographic projection: no perspective, so parallel lines stay parallel. Used for 2D and for directional-light shadow maps.
A perspective projection with a vertical field of view in radians.
Rotation of rad radians around an arbitrary axis.
A translation matrix from components.
Translation * rotation * scale, the usual model matrix.
Instance Method Detail
Transforms a point (w = 1) and performs the perspective divide.