From 9e9fb83bb1a667c12e7b11168a7c3a7284cab994 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 29 Sep 2025 19:12:39 -0500 Subject: [PATCH] vertex: rotate around x axis --- src/vertex.glsl | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/vertex.glsl b/src/vertex.glsl index 1ef571c..9e8995f 100644 --- a/src/vertex.glsl +++ b/src/vertex.glsl @@ -7,9 +7,55 @@ attribute vec4 position; varying float fade_factor; varying vec2 texcoord; + +mat4 view_frustum(float angle_of_view, + float aspect_ratio, + float z_near, + float z_far) +{ + return mat4(vec4(1.0/tan(angle_of_view), 0.0, 0.0, 0.0), + vec4(0.0, aspect_ratio/tan(angle_of_view), 0.0, 0.0), + vec4(0.0, 0.0, (z_far+z_near)/(z_far-z_near), 1.0), + vec4(0.0, 0.0, -2.0*z_far*z_near/(z_far-z_near), 0.0) + ); +} + +mat4 scale(float x, float y, float z) +{ + return mat4( + vec4(x, 0.0, 0.0, 0.0), + vec4(0.0, y, 0.0, 0.0), + vec4(0.0, 0.0, z, 0.0), + vec4(0.0, 0.0, 0.0, 1.0) + ); +} + +mat4 translate(float x, float y, float z) +{ + return mat4(vec4(1.0, 0.0, 0.0, 0.0), + vec4(0.0, 1.0, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(x, y, z, 1.0) + ); +} + +mat4 rotate_x(float theta) +{ + return mat4(vec4(1.0, 0.0, 0.0, 0.0), + vec4(0.0, cos(time), sin(time), 0.0), + vec4(0.0, -sin(time), cos(time), 0.0), + vec4(0.0, 0.0, 0.0, 1.0) + ); +} + void main() { - gl_Position = position; + + gl_Position = view_frustum(radians(45.0), 4.0/3.0, 0.5, 5.0) + * translate(cos(time), 0.0, 3.0+sin(time)) + * rotate_x(time) + * scale(4.0/3.0, 1.0, 1.0) + * position; vec2 tex = position.xy * vec2(0.5) + vec2(0.5);