# module Geode::Matrix4x4Transforms3DConstructors(T)

## Overview

Transformation that can be performed in three-dimensions with 4x4 matrices.

Multiplying a 3D object by the matrices produced by these methods will apply the operation to the object. The matrix must be on the right-hand-side of the multiplication operation.

``object * matrix``

Matrix multiplication is not commutative, therefore the ordering matters. If it's desired to have the matrix on the left-hand-side, transpose it before multiplying.

``matrix.transpose * object``

To combine multiple operations, multiply the matrices from these methods together.

This module should be extended.

## Defined in:

geode/matrices/transforms3d.cr

## Instance Method Detail

def look_at(eye : CommonVector(T, 3), target : CommonVector(T, 3), up : CommonVector(T, 3)) : self #

Creates a 3D view matrix oriented to look at a point.

The eye is the position of the camera. target is the point being looked at. The up vector indicates which direction is "up" for the camera.

The handedness is controlled by compiler flags. Right-handed orientation is the default (common in OpenGL). Specify `-Dleft_handed` to use a left-handed system.

``Matrix4F.look_at(Vector3F[1, 2, 3], Vector3F[0, 0, 0].Vector3F[0, 1, 0])``

TODO Support `Point` types for eye and target.

def look_at_lh(eye : CommonVector(T, 3), target : CommonVector(T, 3), up : CommonVector(T, 3)) : self #

Creates a 3D view matrix oriented to look at a point.

The eye is the position of the camera. target is the point being looked at. The up vector indicates which direction is "up" for the camera.

The matrix produced is for left-handed systems.

``Matrix4F.look_at(Vector3F[1, 2, 3], Vector3F[0, 0, 0].Vector3F[0, 1, 0])``

TODO Support `Point` types for eye and target.

def look_at_rh(eye : CommonVector(T, 3), target : CommonVector(T, 3), up : CommonVector(T, 3)) : self #

Creates a 3D view matrix oriented to look at a point.

The eye is the position of the camera. target is the point being looked at. The up vector indicates which direction is "up" for the camera.

The matrix produced is for right-handed systems.

``Matrix4F.look_at(Vector3F[1, 2, 3], Vector3F[0, 0, 0].Vector3F[0, 1, 0])``

TODO Support `Point` types for eye and target.

def reflect_x : self #

Creates a 3D reflecting matrix with space for translation.

Multiplying an object by this matrix will reflect it along the x-axis.

``````vector = Vector4[1, 2, 3, 1]
matrix = Matrix4(Int32).reflect_x
vector * matrix # => (-1, 2, 3, 1)``````

def reflect_y : self #

Creates a 3D reflective matrix with space for translation.

Multiplying an object by this matrix will reflect it along the y-axis.

``````vector = Vector4[1, 2, 3, 1]
matrix = Matrix4(Int32).reflect_y
vector * matrix # => (1, -2, 3, 1)``````

def reflect_z : self #

Creates a 3D reflecting matrix with space for translation.

Multiplying an object by this matrix will reflect it along the z-axis.

``````vector = Vector4[1, 2, 3, 1]
matrix = Matrix4(Int32).reflect_z
vector * matrix # => (1, 2, -3, 1)``````

def rotate(angle : Number | Angle, axis : CommonVector(T, 3)) : self #

Creates a 3D rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it the specified amount. The angle must be a `Number` in radians or an `Angle`. The object is rotated around the specified axis.

``````axis = Vector3[1, 1, 1].normalize
vector = Vector4[1, 2, 3, 1]
matrix = Matrix4(Float64).rotate(45.degrees, axis)
vector * matrix # => (1.701141509, 1.183503419, 3.115355072, 1.0)``````

def rotate_x(angle : Number | Angle) : self #

Creates a 3D rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it around the x-axis. The angle must be a `Number` in radians or an `Angle`.

``````vector = Vector4[1, 1, 1, 1]
matrix = Matrix4(Float64).rotate_x(45.degrees)
vector * matrix # => (1.0, 0.0, 1.414213562, 1.0)``````

def rotate_y(angle : Number | Angle) : self #

Creates a 3D rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it around the y-axis. The angle must be a `Number` in radians or an `Angle`.

``````vector = Vector4[1, 1, 1, 1]
matrix = Matrix4(Float64).rotate_y(45.degrees)
vector * matrix # => (1.414213562, 1.0, 0.0, 1.0)``````

def rotate_z(angle : Number | Angle) : self #

Creates a 3D rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it around the z-axis. The angle must be a `Number` in radians or an `Angle`.

``````vector = Vector4[1, 1, 1, 1]
matrix = Matrix4(Float64).rotate_z(45.degrees)
vector * matrix # => (0.0, 1.414213562, 1.0, 1.0)``````

def scale(x : T, y : T, z : T) : self #

Creates a 3D scaling matrix with space for translation.

Non-uniformly scales an object (squash and stretch). Multiplying an object by this matrix will scale it by x amount along the x-axis and y amount along the y-axis. Values for x and y smaller than 1 will shrink it. Values larger than 1 will enlarge it. Negative values will flip it.

``````vector = Vector4[2, 3, 4, 1]
matrix = Matrix4(Float64).scale(1.5, 2, 2.5)
vector * matrix # => (3.0, 6.0, 9.0, 1.0)``````

def scale(amount : T) : self #

Creates a 3D scaling matrix with space for translation.

Uniformly scales an object. Multiplying an object by this matrix will scale it by amount. Values for amount smaller than 1 will shrink it. Values larger than 1 will enlarge it. Negative values will flip it.

``````vector = Vector4[2, 3, 4, 1]
matrix = Matrix4(Float64).scale(2)
vector * matrix # => (4.0, 6.0, 8.0, 1.0)``````

def shear_x(y : T, z : T) : self #

Creates a 3D shearing matrix with space for translation.

Multiplying an object by this matrix will shear it along the y and z-axis based on the x-axis. For each unit along the x-axis, the y value will be adjusted by y and the z value will be adjusted by z.

``````vector = Vector4[2, 3, 4, 1]
matrix = Matrix4(Int32).shear_x(2, 3)
vector * matrix # => (2, 7, 10, 1)``````

def shear_y(x : T, z : T) : self #

Creates a 3D shearing matrix with space for translation.

Multiplying an object by this matrix will shear it along the x and z-axis based on the y-axis. For each unit along the y-axis, the x value will be adjusted by x and the z value will be adjusted by z.

``````vector = Vector4[2, 3, 4, 1]
matrix = Matrix4(Int32).shear_y(2, 3)
vector * matrix # => (8, 3, 13, 1)``````

def shear_z(x : T, y : T) : self #

Creates a 3D shearing matrix with space for translation.

Multiplying an object by this matrix will shear it along the x and y-axis based on the z-axis. For each unit along the z-axis, the x value will be adjusted by x and the y value will be adjusted by y.

``````vector = Vector4[2, 3, 4, 1]
matrix = Matrix4(Int32).shear_z(2, 3)
vector * matrix # => (10, 15, 4, 1)``````

def translate(x : T, y : T, z : T) : self #

Creates a 3D transform matrix.

``````vector = Vector4[3, 5, 7, 1]
matrix = Matrix4(Int32).translate(3, 2, 1)
vector * matrix # => (6, 7, 8, 1)``````