more mat3

This commit is contained in:
Ryan Oldenburg 2020-11-29 23:45:57 -06:00
parent 1fe7cc09de
commit d8582e6bdd

View file

@ -572,35 +572,30 @@ proc scale*(a: Mat3, v: Vec3): Mat3 =
result[7] = v.z * a[7] result[7] = v.z * a[7]
result[8] = v.z * a[8] result[8] = v.z * a[8]
proc translate*(v: Vec2): Mat3 = proc translate*(v: Vec2): Mat3 {.inline.} =
result[0, 0] = 1 [
result[1, 1] = 1 1.float32, 0, 0,
result[2, 0] = v.x 0, 1, 0,
result[2, 1] = v.y v.x, v.y, 1
result[2, 2] = 1 ]
proc scale*(v: Vec2): Mat3 = proc scale*(v: Vec2): Mat3 {.inline.} =
result[0, 0] = v.x [
result[1, 1] = v.y v.x, 0, 0,
result[2, 2] = 1 0, v.y, 0,
0, 0, 1
]
proc rotationMat3*(angle: float32): Mat3 = proc rotationMat3*(angle: float32): Mat3 {.inline.} =
# Create a matrix from an angle. # Create a matrix from an angle.
let let
sin = sin(angle) sin = sin(angle)
cos = cos(angle) cos = cos(angle)
result = [
result[0, 0] = cos cos, -sin, 0,
result[0, 1] = -sin sin, cos, 0,
result[0, 2] = 0 0, 0, 1
]
result[1, 0] = sin
result[1, 1] = cos
result[1, 2] = 0
result[2, 0] = 0
result[2, 1] = 0
result[2, 2] = 1
proc rotate*(a: Mat3, angle: float32): Mat3 {.inline.} = proc rotate*(a: Mat3, angle: float32): Mat3 {.inline.} =
# Rotates a matrix by an angle. # Rotates a matrix by an angle.