From b2761ae673806df33831245a5f2208b7b49251c6 Mon Sep 17 00:00:00 2001 From: Ben Houston Date: Wed, 29 Jul 2020 12:28:13 -0400 Subject: [PATCH] feat: add mat2RotateDirection --- src/lib/shaders/includes/math/mat2.glsl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/shaders/includes/math/mat2.glsl b/src/lib/shaders/includes/math/mat2.glsl index 92a30ccd..bc699158 100644 --- a/src/lib/shaders/includes/math/mat2.glsl +++ b/src/lib/shaders/includes/math/mat2.glsl @@ -4,10 +4,16 @@ mat2 mat2Identity() { return mat2( 1., 0., 0., 1. ); } -// https://thebookofshaders.com/08/ +mat2 mat2RotateDirection( vec2 dir ){ + return mat2( dir.x, -dir.y, dir.y, dir.x ); +} + +// validated - this is the same as the TS makeMatrix3RotationFromAngle mat2 mat2Rotate(float angle){ - float c = cos(angle); - float s = sin(angle); + return mat2RotateDirection( vec2( cos(angle), sin(angle) ) ); +} - return mat2( c, -s, s, c ); +// validated - this is the same as the TS makeMatrix3Scale +mat2 mat2Scale(vec2 scale){ + return mat2( scale.x, 0., scale.y, 0 ); }