diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-05-25 11:40:23 +0200 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-05-25 11:40:23 +0200 |
commit | e03455a979abf4444d4362dacbbf55c6915d3b69 (patch) | |
tree | 9aacd6948a4ab86d7ff2ecfb71dc17a1a9260cc4 | |
parent | d6828f4039352a44a1389313ba856369932732e4 (diff) | |
download | stlscope-e03455a979abf4444d4362dacbbf55c6915d3b69.tar stlscope-e03455a979abf4444d4362dacbbf55c6915d3b69.tar.zst stlscope-e03455a979abf4444d4362dacbbf55c6915d3b69.zip |
Make Geometry Types iterable
-rw-r--r-- | app.go | 5 | ||||
-rw-r--r-- | geometry.go | 8 | ||||
-rw-r--r-- | graphics.go | 2 | ||||
-rw-r--r-- | stl.go | 42 |
4 files changed, 27 insertions, 30 deletions
@@ -50,8 +50,11 @@ func newApp() App { func (application *App) handle() { glfw.PollEvents() application.window.SwapBuffers() - trafo := mgl32.HomogRotate3D(float32(glfw.GetTime()) * 3, mgl32.Vec3{0, 1, 1}) + + // generate and set transformation var scale float32 = 0.01 + trafo := mgl32.Ident4() + trafo = trafo.Mul4(mgl32.HomogRotate3D(float32(glfw.GetTime()) * 3, mgl32.Vec3{0, 1, 1})) trafo = trafo.Mul4(mgl32.Scale3D(scale, scale, scale)) application.graphics.setTrafo(trafo) } diff --git a/geometry.go b/geometry.go index 3c3ba83..04896dc 100644 --- a/geometry.go +++ b/geometry.go @@ -4,16 +4,12 @@ package main // representation of a three-dimensional point in space type Point struct { - x float32 - y float32 - z float32 + scalars [3]float32 // x = scalars[0], y = scalars[1], z = scalars[2] } // a triangle consists of three points type Triangle struct { - a *Point - b *Point - c *Point + points [3]*Point } // a surface is made of a slice of triangles diff --git a/graphics.go b/graphics.go index 66b8274..0aacdb7 100644 --- a/graphics.go +++ b/graphics.go @@ -147,7 +147,7 @@ func compileShader(source string, shaderType uint32) (uint32, error) { log := strings.Repeat("\x00", int(logLength+1)) gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log)) - return 0, fmt.Errorf("failed to compile %v: %v", source, log) + return 0, fmt.Errorf("Failed to compile %v: %v", source, log) } return shader, nil @@ -53,24 +53,24 @@ func ParseBinaryStlTriangle(data []byte) *Triangle { // FIXME: This function sh // allocate a new triangle and three corner points on the heap triangle := new(Triangle) - triangle.a = new(Point) // corner point a - triangle.b = new(Point) // corner point b - triangle.c = new(Point) // corner point c + triangle.points[0] = new(Point) + triangle.points[1] = new(Point) + triangle.points[2] = new(Point) // parse x, y and z coordinate for corner point a - triangle.a.x = math.Float32frombits(binary.LittleEndian.Uint32(data[12:16])) - triangle.a.y = math.Float32frombits(binary.LittleEndian.Uint32(data[16:20])) - triangle.a.z = math.Float32frombits(binary.LittleEndian.Uint32(data[20:24])) + triangle.points[0].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[12:16])) + triangle.points[0].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[16:20])) + triangle.points[0].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[20:24])) // parse x, y and z coordinate for corner point b - triangle.b.x = math.Float32frombits(binary.LittleEndian.Uint32(data[24:28])) - triangle.b.y = math.Float32frombits(binary.LittleEndian.Uint32(data[28:32])) - triangle.b.z = math.Float32frombits(binary.LittleEndian.Uint32(data[32:36])) + triangle.points[1].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[24:28])) + triangle.points[1].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[28:32])) + triangle.points[1].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[32:36])) // parse x, y and z coordinate for corner point c - triangle.c.x = math.Float32frombits(binary.LittleEndian.Uint32(data[36:40])) - triangle.c.y = math.Float32frombits(binary.LittleEndian.Uint32(data[40:44])) - triangle.c.z = math.Float32frombits(binary.LittleEndian.Uint32(data[44:48])) + triangle.points[2].scalars[0] = math.Float32frombits(binary.LittleEndian.Uint32(data[36:40])) + triangle.points[2].scalars[1] = math.Float32frombits(binary.LittleEndian.Uint32(data[40:44])) + triangle.points[2].scalars[2] = math.Float32frombits(binary.LittleEndian.Uint32(data[44:48])) return triangle } @@ -79,19 +79,17 @@ func (stl StlModel) toVertices() []float32 { retval := make([]float32, stl.numberOfTriangles * 9) - for index,triangle := range(stl.surface.triangles) { + for triangleIndex,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 + for pointIndex,point := range(triangle.points) { - retval[index*9+3] = triangle.b.x - retval[index*9+4] = triangle.b.y - retval[index*9+5] = triangle.b.z + for scalarIndex,scalar := range(point.scalars) { - retval[index*9+6] = triangle.c.x - retval[index*9+7] = triangle.c.y - retval[index*9+8] = triangle.c.z + retval[triangleIndex*9+pointIndex*3+scalarIndex] = scalar + + } + + } } |