summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-05-21 15:11:50 +0200
committerxengineering <mail2xengineering@protonmail.com>2021-05-21 15:11:50 +0200
commitaad26e524922d144fd4ed023dc0d60fadb62f253 (patch)
tree862d5b1b813128f7912504f0261b11cc8eda9941
parent78a83df3572c7a91dbcbca21d74d8d11170d947c (diff)
downloadstlscope-aad26e524922d144fd4ed023dc0d60fadb62f253.tar
stlscope-aad26e524922d144fd4ed023dc0d60fadb62f253.tar.zst
stlscope-aad26e524922d144fd4ed023dc0d60fadb62f253.zip
First Rendering of an STL Model
-rw-r--r--graphics.go9
-rw-r--r--main.go3
-rw-r--r--stl.go22
3 files changed, 28 insertions, 6 deletions
diff --git a/graphics.go b/graphics.go
index 999b37d..87c21ed 100644
--- a/graphics.go
+++ b/graphics.go
@@ -13,8 +13,7 @@ import (
)
var (
- // a single triangle
- triangle = []float32{
+ vertices = []float32{
0.0, 0.5, 0.0,
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
@@ -24,7 +23,7 @@ var (
const (
// rotational speed and vector
- OMEGA = 6
+ OMEGA = 3
ROT_X = 0
ROT_Y = 1
ROT_Z = 1
@@ -92,7 +91,7 @@ func newGraphics() Graphics {
gl.LinkProgram(graphics.program)
// create VAO
- graphics.vao = makeVao(triangle)
+ graphics.vao = makeVao(vertices)
// create transformation matrix
graphics.trafo = mgl32.HomogRotate3D(float32(glfw.GetTime()) * OMEGA, mgl32.Vec3{ROT_X, ROT_Y, ROT_Z})
@@ -110,7 +109,7 @@ func (graphics Graphics) draw() {
gl.UniformMatrix4fv(graphics.trafoUniform, 1, false, &graphics.trafo[0])
gl.BindVertexArray(graphics.vao)
- gl.DrawArrays(gl.TRIANGLES, 0, int32(len(triangle)/3))
+ gl.DrawArrays(gl.TRIANGLES, 0, int32(len(vertices)/3))
}
// makeVao initializes and returns a vertex array from the points provided.
diff --git a/main.go b/main.go
index 8f2afcc..6444871 100644
--- a/main.go
+++ b/main.go
@@ -21,10 +21,11 @@ func main() {
parseFlags(&stlFilePath)
// parse STL file
- _, err := ReadBinaryStlFile(stlFilePath)
+ stl, err := ReadBinaryStlFile(stlFilePath)
if err != nil {
log.Fatal(err)
}
+ vertices = stl.toVertices()
// initialize application (includes GLFW/window)
var app App = newApp()
diff --git a/stl.go b/stl.go
index d2a194d..d024b13 100644
--- a/stl.go
+++ b/stl.go
@@ -75,3 +75,25 @@ func ParseBinaryStlTriangle(data []byte) *Triangle { // FIXME: This function sh
return triangle
}
+func (stl StlModel) toVertices() []float32 {
+
+ retval := make([]float32, stl.numberOfTriangles * 9)
+
+ for index,triangle := range(stl.surface.triangles) {
+
+ retval[index*9+0] = triangle.a.x
+ retval[index*9+1] = triangle.a.y
+ retval[index*9+2] = triangle.a.z
+
+ retval[index*9+3] = triangle.b.x
+ retval[index*9+4] = triangle.b.y
+ retval[index*9+5] = triangle.b.z
+
+ retval[index*9+6] = triangle.c.x
+ retval[index*9+7] = triangle.c.y
+ retval[index*9+8] = triangle.c.z
+
+ }
+
+ return retval
+}