diff --git a/learning/hello_world/main.frag b/learning/hello_world/main.frag index 7d0b166..465e796 100644 --- a/learning/hello_world/main.frag +++ b/learning/hello_world/main.frag @@ -6,8 +6,6 @@ uniform float u_time; uniform vec2 u_resolution; uniform vec2 u_mouse; - - vec4 col() { vec2 st = gl_FragCoord.xy/u_resolution; vec2 mt = u_mouse/u_resolution; diff --git a/snippets/rotate/rotate.frag b/snippets/rotate/rotate.frag new file mode 100644 index 0000000..ccde4fb --- /dev/null +++ b/snippets/rotate/rotate.frag @@ -0,0 +1,3 @@ +vec2 rotate(vec2 st, float a) { + return mat2(cos(a),-sin(a),sin(a),cos(a))*(st); +} diff --git a/snippets/rotate/rotate.md b/snippets/rotate/rotate.md new file mode 100644 index 0000000..52e54c1 --- /dev/null +++ b/snippets/rotate/rotate.md @@ -0,0 +1,14 @@ +# Rotate + +as far as i understand this function, it functions by multiplying a 2d vector by a mat2 (2x2 matrix as far as i can tell) like this: + +[[cos(angle),-sin(angle)], [x, +[sin(angle),-cos(angle)]] x y] + +creating something like this: +``` +st.x = cos(angle)*st.x - sin(angle)*st.x +st.y = sin(angle)*st.y - cos(angle)*st.y +``` +although i don't fully understand cos and sin's effect on these values, i feel like i'm a step closer to understand these functions +