tofu

Making something with OpenGL in Go
Log | Files | Refs

commit 54571622e3dd606740170097d39887400c3efad5
parent 5672e19193c39b893f6149de7e0c31ff63ebe8d6
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat,  9 Nov 2024 17:56:07 +0900

add Face struct

Diffstat:
Mcmd/sample/main.go | 30++++++++++++------------------
Mobject.go | 7++++---
2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/cmd/sample/main.go b/cmd/sample/main.go @@ -115,17 +115,11 @@ var object = tofu.Object{ }, Normals: []tofu.Vec3{ {0.0, 0.0, -1.0}, - {0.0, 0.0, -1.0}, - {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, - {0.0, -1.0, 0.0}, {-1.0, 0.0, 0.0}, - {-1.0, 0.0, 0.0}, - {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, - {0.0, 0.0, 1.0}, }, TexCoords: []tofu.Vec2{ tofu.Vec2{1.0, 1.0}, @@ -138,18 +132,18 @@ var object = tofu.Object{ tofu.Vec2{0.0, 1.0}, }, Faces: []tofu.Face{ - {V: [3]int{0, 1, 2}}, - {V: [3]int{0, 2, 3}}, - {V: [3]int{0, 1, 5}}, - {V: [3]int{0, 5, 4}}, - {V: [3]int{1, 2, 6}}, - {V: [3]int{1, 6, 5}}, - {V: [3]int{2, 3, 7}}, - {V: [3]int{2, 7, 6}}, - {V: [3]int{3, 0, 4}}, - {V: [3]int{3, 4, 7}}, - {V: [3]int{4, 5, 6}}, - {V: [3]int{4, 6, 7}}, + {V: [3]int{0, 1, 2}, N: {0, 0, 0}}, + {V: [3]int{0, 2, 3}, N: {1, 1, 1}}, + {V: [3]int{0, 1, 5}, N: {1, 1, 1}}, + {V: [3]int{0, 5, 4}, N: {2, 2, 2}}, + {V: [3]int{1, 2, 6}, N: {2, 2, 2}}, + {V: [3]int{1, 6, 5}, N: {3, 3, 3}}, + {V: [3]int{2, 3, 7}, N: {3, 3, 3}}, + {V: [3]int{2, 7, 6}, N: {4, 4, 4}}, + {V: [3]int{3, 0, 4}, N: {4, 4, 4}}, + {V: [3]int{3, 4, 7}, N: {5, 5, 5}}, + {V: [3]int{4, 5, 6}, N: {5, 5, 5}}, + {V: [3]int{4, 6, 7}, N: {6, 6, 6}}, }, } diff --git a/object.go b/object.go @@ -18,6 +18,7 @@ type Object struct { type Face struct { V [3]int + N [3]int } const objectStride = 11 @@ -35,9 +36,9 @@ func (obj Object) data() []float32 { data[objectStride * (3*i+j) + 5] = float32(b)/0xffff data[objectStride * (3*i+j) + 6] = obj.TexCoords[f.V[j]][0] data[objectStride * (3*i+j) + 7] = obj.TexCoords[f.V[j]][1] - data[objectStride * (3*i+j) + 8] = obj.Normals[f.V[j]][0] - data[objectStride * (3*i+j) + 9] = obj.Normals[f.V[j]][1] - data[objectStride * (3*i+j) + 10] = obj.Normals[f.V[j]][2] + data[objectStride * (3*i+j) + 8] = obj.Normals[f.N[j]][0] + data[objectStride * (3*i+j) + 9] = obj.Normals[f.N[j]][1] + data[objectStride * (3*i+j) + 10] = obj.Normals[f.N[j]][2] } } return data