From 78a83df3572c7a91dbcbca21d74d8d11170d947c Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 21 May 2021 14:55:33 +0200 Subject: Animated Rotation --- graphics.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/graphics.go b/graphics.go index a5c7373..999b37d 100644 --- a/graphics.go +++ b/graphics.go @@ -9,6 +9,7 @@ import ( "github.com/go-gl/gl/v4.6-core/gl" "github.com/go-gl/mathgl/mgl32" + "github.com/go-gl/glfw/v3.3/glfw" ) var ( @@ -21,6 +22,13 @@ var ( ) const ( + + // rotational speed and vector + OMEGA = 6 + ROT_X = 0 + ROT_Y = 1 + ROT_Z = 1 + // vertex shader to draw points VERTEX_SHADER = ` #version 410 @@ -87,7 +95,7 @@ func newGraphics() Graphics { graphics.vao = makeVao(triangle) // create transformation matrix - graphics.trafo = mgl32.HomogRotate3D(float32(1.57), mgl32.Vec3{0, 1, 1}) // mgl32.Ident4() + graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z}) graphics.trafoUniform = gl.GetUniformLocation(graphics.program, gl.Str("trafo\x00")) gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0]) @@ -98,6 +106,7 @@ func (graphics Graphics) draw() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.UseProgram(graphics.program) + graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z}) gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0]) gl.BindVertexArray(graphics.vao) -- cgit v1.2.3-70-g09d2