summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod1
-rw-r--r--go.sum5
-rw-r--r--graphics.go16
-rw-r--r--stl.go8
4 files changed, 25 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index f966925..90ce7e5 100644
--- a/go.mod
+++ b/go.mod
@@ -5,4 +5,5 @@ go 1.16
require (
github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48
+ github.com/go-gl/mathgl v1.0.0
)
diff --git a/go.sum b/go.sum
index b443e1b..87a01c7 100644
--- a/go.sum
+++ b/go.sum
@@ -2,3 +2,8 @@ github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d h1:o81yRlBATU4PRn97lydmsq
github.com/go-gl/gl v0.0.0-20210315015930-ae072cafe09d/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48 h1:QrUfZrT8n72FUuiABt4tbu8PwDnOPAbnj3Mql1UhdRI=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
+github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68=
+github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
+golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f h1:FO4MZ3N56GnxbqxGKqh+YTzUWQ2sDwtFQEZgLOxh9Jc=
+golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/graphics.go b/graphics.go
index 91edcce..a5c7373 100644
--- a/graphics.go
+++ b/graphics.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/go-gl/gl/v4.6-core/gl"
+ "github.com/go-gl/mathgl/mgl32"
)
var (
@@ -23,9 +24,13 @@ const (
// vertex shader to draw points
VERTEX_SHADER = `
#version 410
+
+ uniform mat4 trafo;
+
in vec3 vp;
+
void main() {
- gl_Position = vec4(vp, 1.0);
+ gl_Position = trafo * vec4(vp, 1.0);
}
` + "\x00"
@@ -45,6 +50,8 @@ type Graphics struct {
vertexShader uint32
fragmentShader uint32
program uint32
+ trafo mgl32.Mat4
+ trafoUniform int32
}
func newGraphics() Graphics {
@@ -79,6 +86,11 @@ func newGraphics() Graphics {
// create VAO
graphics.vao = makeVao(triangle)
+ // create transformation matrix
+ graphics.trafo = mgl32.HomogRotate3D(float32(1.57), mgl32.Vec3{0, 1, 1}) // mgl32.Ident4()
+ graphics.trafoUniform = gl.GetUniformLocation(graphics.program, gl.Str("trafo\x00"))
+ gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
+
return graphics
}
@@ -86,6 +98,8 @@ func (graphics Graphics) draw() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.UseProgram(graphics.program)
+ gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
+
gl.BindVertexArray(graphics.vao)
gl.DrawArrays(gl.TRIANGLES, 0, int32(len(triangle)/3))
}
diff --git a/stl.go b/stl.go
index f1d0a60..d2a194d 100644
--- a/stl.go
+++ b/stl.go
@@ -14,21 +14,21 @@ import (
)
// representation of binary STL file content
-type BinaryStl struct {
+type StlModel struct {
header []byte
numberOfTriangles uint32
surface Surface
}
// read and parse a given binary STL file
-func ReadBinaryStlFile(filePath string) (BinaryStl, error) {
+func ReadBinaryStlFile(filePath string) (StlModel, error) {
fileContent, err := ioutil.ReadFile(filePath)
if err != nil {
- return BinaryStl{}, err
+ return StlModel{}, err
}
- model := BinaryStl{}
+ model := StlModel{}
model.surface = Surface{}
model.header = fileContent[0:80]