diff options
author | sanine <sanine.not@pm.me> | 2023-03-13 02:42:16 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-13 02:42:16 -0500 |
commit | 89572c1648128456822cf2dda07b13e78cfc2813 (patch) | |
tree | 78cafed06eb4cb261e53d0de28fa7e170ce55d6f | |
parent | bb8c38bffba86cda05e0e8e9b52fb68301286b53 (diff) |
render all shapes
-rw-r--r-- | 44d9a0ec1c18e6126a5e9d9d9317f5ac.png | bin | 0 -> 643870 bytes | |||
-rw-r--r-- | 77155.png | bin | 0 -> 2996 bytes | |||
-rw-r--r-- | assets/Cube.png | bin | 0 -> 22611 bytes | |||
-rw-r--r-- | assets/Icosphere.png | bin | 0 -> 75897 bytes | |||
-rw-r--r-- | assets/cube.obj | 54 | ||||
-rw-r--r-- | assets/dodecahedron.mtl | 14 | ||||
-rw-r--r-- | assets/dodecahedron.obj | 298 | ||||
-rw-r--r-- | assets/icosahedron.mtl | 14 | ||||
-rw-r--r-- | assets/icosahedron.obj | 199 | ||||
-rw-r--r-- | assets/octahedron.mtl | 12 | ||||
-rw-r--r-- | assets/octahedron.obj | 70 | ||||
-rw-r--r-- | assets/octahedron.png (renamed from assets/octohedron.png) | bin | 32343 -> 32343 bytes | |||
-rw-r--r-- | assets/octohedron.mtl | 10 | ||||
-rw-r--r-- | assets/octohedron.obj | 32 | ||||
-rw-r--r-- | assets/tetrahedron.obj | 34 | ||||
-rw-r--r-- | honey/init.lua | 29 | ||||
-rw-r--r-- | honey/mat4.lua | 144 | ||||
-rw-r--r-- | honey/mesh.lua | 95 | ||||
-rw-r--r-- | honey/std.lua | 10 | ||||
-rw-r--r-- | honey/vec3.lua | 170 | ||||
-rw-r--r-- | honey/window.lua | 3 | ||||
-rw-r--r-- | main.lua | 124 |
22 files changed, 1033 insertions, 279 deletions
diff --git a/44d9a0ec1c18e6126a5e9d9d9317f5ac.png b/44d9a0ec1c18e6126a5e9d9d9317f5ac.png Binary files differnew file mode 100644 index 0000000..531b895 --- /dev/null +++ b/44d9a0ec1c18e6126a5e9d9d9317f5ac.png diff --git a/77155.png b/77155.png Binary files differnew file mode 100644 index 0000000..0209e70 --- /dev/null +++ b/77155.png diff --git a/assets/Cube.png b/assets/Cube.png Binary files differnew file mode 100644 index 0000000..413a785 --- /dev/null +++ b/assets/Cube.png diff --git a/assets/Icosphere.png b/assets/Icosphere.png Binary files differnew file mode 100644 index 0000000..47c48f4 --- /dev/null +++ b/assets/Icosphere.png diff --git a/assets/cube.obj b/assets/cube.obj index 59558f1..01d923d 100644 --- a/assets/cube.obj +++ b/assets/cube.obj @@ -1,7 +1,7 @@ # Blender v3.4.1 OBJ File: '' # www.blender.org mtllib cube.mtl -o Cube_Cube.001 +o Cube_Cube.003 v -1.000000 -1.000000 1.000000 v -1.000000 1.000000 1.000000 v -1.000000 -1.000000 -1.000000 @@ -10,19 +10,45 @@ v 1.000000 -1.000000 1.000000 v 1.000000 1.000000 1.000000 v 1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -1.000000 -vt 0.375000 0.000000 +v -1.000000 -1.000000 -1.000000 +v -1.000000 -1.000000 -1.000000 +v -1.000000 -1.000000 1.000000 +v -1.000000 -1.000000 1.000000 +v -1.000000 1.000000 1.000000 +v -1.000000 1.000000 1.000000 +v -1.000000 1.000000 -1.000000 +v -1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 -1.000000 +v 1.000000 -1.000000 -1.000000 +v 1.000000 1.000000 -1.000000 +v 1.000000 1.000000 -1.000000 +v 1.000000 -1.000000 1.000000 +v 1.000000 -1.000000 1.000000 +v 1.000000 1.000000 1.000000 +v 1.000000 1.000000 1.000000 vt 0.625000 0.000000 +vt 0.375000 0.250000 +vt 0.375000 0.000000 vt 0.625000 0.250000 +vt 0.375000 0.500000 vt 0.375000 0.250000 vt 0.625000 0.500000 +vt 0.375000 0.750000 vt 0.375000 0.500000 vt 0.625000 0.750000 -vt 0.375000 0.750000 -vt 0.625000 1.000000 vt 0.375000 1.000000 -vt 0.125000 0.500000 +vt 0.375000 0.750000 +vt 0.375000 0.500000 vt 0.125000 0.750000 +vt 0.125000 0.500000 vt 0.875000 0.500000 +vt 0.625000 0.750000 +vt 0.625000 0.500000 +vt 0.625000 0.250000 +vt 0.625000 0.500000 +vt 0.625000 0.750000 +vt 0.625000 1.000000 +vt 0.375000 0.750000 vt 0.875000 0.750000 vn -1.0000 0.0000 0.0000 vn 0.0000 0.0000 -1.0000 @@ -32,9 +58,15 @@ vn 0.0000 -1.0000 0.0000 vn 0.0000 1.0000 0.0000 usemtl None s off -f 1/1/1 2/2/1 4/3/1 3/4/1 -f 3/4/2 4/3/2 8/5/2 7/6/2 -f 7/6/3 8/5/3 6/7/3 5/8/3 -f 5/8/4 6/7/4 2/9/4 1/10/4 -f 3/11/5 7/6/5 5/8/5 1/12/5 -f 8/5/6 4/13/6 2/14/6 6/7/6 +f 13/1/1 9/2/1 11/3/1 +f 16/4/2 17/5/2 10/6/2 +f 20/7/3 21/8/3 18/9/3 +f 24/10/4 12/11/4 22/12/4 +f 7/13/5 1/14/5 3/15/5 +f 4/16/6 6/17/6 8/18/6 +f 13/1/1 15/19/1 9/2/1 +f 16/4/2 19/20/2 17/5/2 +f 20/7/3 23/21/3 21/8/3 +f 24/10/4 14/22/4 12/11/4 +f 7/13/5 5/23/5 1/14/5 +f 4/16/6 2/24/6 6/17/6 diff --git a/assets/dodecahedron.mtl b/assets/dodecahedron.mtl index f231bdf..a891989 100644 --- a/assets/dodecahedron.mtl +++ b/assets/dodecahedron.mtl @@ -1,10 +1,12 @@ # Blender MTL File: 'None' # Material Count: 1 -newmtl None -Ns 500 -Ka 0.8 0.8 0.8 -Kd 0.8 0.8 0.8 -Ks 0.8 0.8 0.8 -d 1 +newmtl None.001 +Ns 499.999983 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.800000 0.800000 0.800000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 illum 2 diff --git a/assets/dodecahedron.obj b/assets/dodecahedron.obj index 9378634..d833481 100644 --- a/assets/dodecahedron.obj +++ b/assets/dodecahedron.obj @@ -1,114 +1,114 @@ # Blender v3.4.1 OBJ File: '' # www.blender.org mtllib dodecahedron.mtl -o Circle -v 0.000000 0.000000 0.000000 -v -0.000000 -0.000000 -1.000000 -v -0.951057 0.000000 -0.309017 -v -0.587785 0.000000 0.809017 -v 0.587785 0.000000 0.809017 -v 0.951057 0.000000 -0.309017 -v -0.951060 1.618035 -1.309021 -v -0.000001 1.000000 -1.618033 -v -0.000005 -0.000000 -1.000000 -v -0.951065 -0.000000 -0.309022 -v -1.538849 1.000000 -0.500007 -v -0.688196 0.723607 -0.947217 -v 0.000002 1.000000 -1.618033 -v 0.951057 1.618035 -1.309011 -v 1.538839 1.000001 -0.499991 -v 0.951053 -0.000000 -0.309012 -v -0.000000 -0.000000 -1.000000 -v 0.688190 0.723607 -0.947210 -v 1.113522 0.723607 0.361803 -v 1.538852 1.000000 -0.499999 -v 0.951066 -0.000000 -0.309018 -v 0.587789 -0.000000 0.809014 -v 0.951057 1.000000 1.309016 -v 1.538846 1.618035 0.500001 -v 0.000000 1.618035 1.618039 -v -0.951055 1.000000 1.309017 -v -0.587781 -0.000000 0.809020 -v 0.587790 -0.000000 0.809026 -v 0.951058 1.000000 1.309027 -v 0.000002 0.723607 1.170826 -v -1.113521 0.723607 0.361807 -v -0.951065 1.000000 1.309022 -v -0.587792 -0.000000 0.809024 -v -0.951058 -0.000000 -0.309012 -v -1.538842 1.000000 -0.499998 -v -1.538846 1.618035 0.500002 -v 0.000000 2.618035 0.000000 -v 0.000000 2.618035 1.000000 -v 0.951057 2.618035 0.309017 -v 0.587785 2.618035 -0.809017 -v -0.587785 2.618035 -0.809017 -v -0.951057 2.618035 0.309017 -v 0.951060 1.000000 1.309021 -v 0.000002 1.618035 1.618033 -v 0.000005 2.618035 1.000000 -v 0.951065 2.618035 0.309022 -v 1.538849 1.618035 0.500007 -v 0.688196 1.894428 0.947217 -v -0.000002 1.618035 1.618033 -v -0.951057 1.000000 1.309011 -v -1.538839 1.618035 0.499992 -v -0.951053 2.618035 0.309012 -v 0.000000 2.618035 1.000000 -v -0.688190 1.894428 0.947210 -v -1.113522 1.894428 -0.361803 -v -1.538852 1.618035 0.499999 -v -0.951066 2.618035 0.309018 -v -0.587789 2.618035 -0.809014 -v -0.951058 1.618035 -1.309015 -v -1.538846 1.000000 -0.500001 -v -0.000001 1.000000 -1.618039 -v 0.951055 1.618035 -1.309017 -v 0.587781 2.618035 -0.809020 -v -0.587790 2.618035 -0.809026 -v -0.951058 1.618035 -1.309027 -v -0.000002 1.894428 -1.170826 -v 1.113521 1.894428 -0.361807 -v 0.951065 1.618035 -1.309022 -v 0.587792 2.618035 -0.809024 -v 0.951058 2.618035 0.309012 -v 1.538842 1.618035 0.499998 -v 1.538846 1.000000 -0.500002 +o Circle.003 +v 0.000000 -0.793800 -0.000000 +v 0.000000 -0.793800 -0.606409 +v -0.576730 -0.793800 -0.187391 +v -0.356438 -0.793800 0.490595 +v 0.356438 -0.793800 0.490595 +v 0.576730 -0.793800 -0.187391 +v -0.417328 -0.354998 -0.574401 +v -0.000001 -0.187391 -0.981190 +v -0.576732 0.187391 -0.793802 +v -0.933172 -0.187391 -0.303209 +v -0.576735 -0.793800 -0.187394 +v -0.000003 -0.793800 -0.606409 +v 0.417325 -0.354998 -0.574397 +v 0.576730 0.187391 -0.793796 +v 0.000001 -0.187391 -0.981190 +v 0.000000 -0.793800 -0.606409 +v 0.576727 -0.793800 -0.187388 +v 0.933166 -0.187390 -0.303199 +v 0.675250 -0.354998 0.219401 +v 0.933174 -0.187391 -0.303204 +v 0.576735 -0.793800 -0.187391 +v 0.933170 0.187391 0.303205 +v 0.356441 -0.793800 0.490594 +v 0.576730 -0.187391 0.793799 +v 0.000001 -0.354998 0.710000 +v -0.576728 -0.187391 0.793800 +v 0.000000 0.187391 0.981194 +v 0.356441 -0.793800 0.490601 +v -0.356436 -0.793800 0.490597 +v 0.576730 -0.187391 0.793806 +v -0.675249 -0.354998 0.219403 +v -0.576735 -0.187391 0.793803 +v -0.356442 -0.793800 0.490600 +v -0.576730 -0.793800 -0.187388 +v -0.933168 -0.187391 -0.303203 +v -0.933170 0.187391 0.303206 +v 0.000000 0.793800 0.000000 +v 0.000000 0.793800 0.606409 +v 0.576730 0.793800 0.187391 +v 0.356438 0.793800 -0.490595 +v -0.356438 0.793800 -0.490595 +v -0.576730 0.793800 0.187391 +v 0.417328 0.354998 0.574401 +v 0.000001 0.187391 0.981190 +v 0.576732 -0.187391 0.793802 +v 0.933172 0.187391 0.303209 +v 0.576735 0.793800 0.187394 +v 0.000003 0.793800 0.606409 +v -0.417325 0.354998 0.574397 +v -0.576730 -0.187391 0.793796 +v -0.000001 0.187391 0.981190 +v 0.000000 0.793800 0.606409 +v -0.576727 0.793800 0.187388 +v -0.933166 0.187391 0.303200 +v -0.675250 0.354998 -0.219401 +v -0.933174 0.187391 0.303204 +v -0.576735 0.793800 0.187391 +v -0.933170 -0.187391 -0.303205 +v -0.356441 0.793800 -0.490594 +v -0.576730 0.187391 -0.793799 +v -0.000001 0.354999 -0.710000 +v 0.576728 0.187391 -0.793800 +v -0.000001 -0.187391 -0.981194 +v -0.356441 0.793800 -0.490601 +v 0.356436 0.793800 -0.490597 +v -0.576730 0.187391 -0.793806 +v 0.675249 0.354998 -0.219403 +v 0.576735 0.187391 -0.793803 +v 0.356442 0.793800 -0.490600 +v 0.576730 0.793800 0.187388 +v 0.933168 0.187391 0.303203 +v 0.933170 -0.187391 -0.303206 vt 0.126156 0.755207 -vt 0.126156 0.865811 vt 0.020966 0.789385 +vt 0.126156 0.865811 vt 0.061145 0.665727 vt 0.191167 0.665727 vt 0.231347 0.789385 vt 0.133793 0.507300 -vt 0.198805 0.417820 vt 0.238984 0.541479 +vt 0.198805 0.417820 vt 0.133793 0.617904 -vt 0.028603 0.541479 vt 0.068782 0.417820 +vt 0.028603 0.541479 vt 0.629231 0.466888 -vt 0.694242 0.377408 vt 0.734421 0.501067 +vt 0.694242 0.377408 vt 0.629231 0.577492 -vt 0.524040 0.501067 vt 0.564220 0.377408 +vt 0.524040 0.501067 vt 0.382101 0.246545 -vt 0.382101 0.357149 vt 0.276910 0.280723 +vt 0.382101 0.357149 vt 0.487291 0.280723 vt 0.317090 0.157065 vt 0.447112 0.157065 vt 0.124232 0.237885 -vt 0.189243 0.148405 vt 0.229422 0.272063 -vt 0.019042 0.272063 +vt 0.189243 0.148405 vt 0.059221 0.148405 +vt 0.019042 0.272063 vt 0.124232 0.348489 vt 0.376328 0.742077 -vt 0.376328 0.852680 vt 0.271137 0.776255 -vt 0.311316 0.652596 +vt 0.376328 0.852680 vt 0.441339 0.652596 +vt 0.311316 0.652596 vt 0.481518 0.776255 vt 0.624574 0.728606 vt 0.624574 0.839209 @@ -146,71 +146,77 @@ vt 0.276910 0.501067 vt 0.317090 0.377408 vt 0.447112 0.377408 vt 0.487291 0.501067 -vn 0.0000 1.0000 -0.0000 +vn 0.0000 -1.0000 -0.0000 +vn -0.5257 -0.4472 -0.7236 +vn 0.5257 -0.4472 -0.7236 +vn 0.8506 -0.4472 0.2764 +vn -0.0000 -0.4472 0.8944 +vn -0.8507 -0.4472 0.2764 +vn 0.0000 1.0000 0.0000 vn 0.5257 0.4472 0.7236 vn -0.5257 0.4472 0.7236 vn -0.8506 0.4472 -0.2764 vn 0.0000 0.4472 -0.8944 vn 0.8507 0.4472 -0.2764 -usemtl None -s off -f 1/1/1 2/2/1 3/3/1 -f 1/1/1 3/3/1 4/4/1 -f 1/1/1 4/4/1 5/5/1 -f 1/1/1 5/5/1 6/6/1 -f 1/1/1 6/6/1 2/2/1 -f 12/7/2 8/8/2 7/9/2 -f 12/7/2 7/9/2 11/10/2 -f 12/7/2 10/11/2 9/12/2 -f 12/7/2 11/10/2 10/11/2 -f 12/7/2 9/12/2 8/8/2 -f 18/13/3 14/14/3 13/15/3 -f 18/13/3 13/15/3 17/16/3 -f 18/13/3 16/17/3 15/18/3 -f 18/13/3 17/16/3 16/17/3 -f 18/13/3 15/18/3 14/14/3 -f 19/19/4 20/20/4 21/21/4 -f 19/19/4 24/22/4 20/20/4 -f 19/19/4 21/21/4 22/23/4 -f 19/19/4 23/24/4 24/22/4 -f 19/19/4 22/23/4 23/24/4 -f 30/25/5 26/26/5 25/27/5 -f 30/25/5 28/28/5 27/29/5 -f 30/25/5 27/29/5 26/26/5 -f 30/25/5 29/30/5 28/28/5 -f 30/25/5 25/27/5 29/30/5 -f 31/31/6 32/32/6 33/33/6 -f 31/31/6 34/34/6 35/35/6 -f 31/31/6 36/36/6 32/32/6 -f 31/31/6 35/35/6 36/36/6 -f 31/31/6 33/33/6 34/34/6 -f 37/37/1 38/38/1 39/39/1 -f 37/37/1 39/39/1 40/40/1 -f 37/37/1 40/40/1 41/41/1 -f 37/37/1 41/41/1 42/42/1 -f 37/37/1 42/42/1 38/38/1 -f 48/43/2 44/44/2 43/45/2 -f 48/43/2 43/45/2 47/46/2 -f 48/43/2 46/47/2 45/48/2 -f 48/43/2 47/46/2 46/47/2 -f 48/43/2 45/48/2 44/44/2 -f 54/49/3 50/50/3 49/51/3 -f 54/49/3 49/51/3 53/52/3 -f 54/49/3 52/53/3 51/54/3 -f 54/49/3 53/52/3 52/53/3 -f 54/49/3 51/54/3 50/50/3 -f 55/55/4 56/56/4 57/57/4 -f 55/55/4 60/58/4 56/56/4 -f 55/55/4 57/57/4 58/59/4 -f 55/55/4 59/60/4 60/58/4 -f 55/55/4 58/59/4 59/60/4 -f 66/61/5 62/62/5 61/63/5 -f 66/61/5 64/64/5 63/65/5 -f 66/61/5 63/65/5 62/62/5 -f 66/61/5 65/66/5 64/64/5 -f 66/61/5 61/63/5 65/66/5 -f 67/67/6 68/68/6 69/69/6 -f 67/67/6 70/70/6 71/71/6 -f 67/67/6 72/72/6 68/68/6 -f 67/67/6 71/71/6 72/72/6 -f 67/67/6 69/69/6 70/70/6 +usemtl None.001 +s 1 +f 1/1/1 3/2/1 2/3/1 +f 1/1/1 4/4/1 3/2/1 +f 1/1/1 5/5/1 4/4/1 +f 1/1/1 6/6/1 5/5/1 +f 1/1/1 2/3/1 6/6/1 +f 7/7/2 9/8/2 8/9/2 +f 7/7/2 10/10/2 9/8/2 +f 7/7/2 12/11/2 11/12/2 +f 7/7/2 11/12/2 10/10/2 +f 7/7/2 8/9/2 12/11/2 +f 13/13/3 15/14/3 14/15/3 +f 13/13/3 16/16/3 15/14/3 +f 13/13/3 18/17/3 17/18/3 +f 13/13/3 17/18/3 16/16/3 +f 13/13/3 14/15/3 18/17/3 +f 19/19/4 21/20/4 20/21/4 +f 19/19/4 20/21/4 22/22/4 +f 19/19/4 23/23/4 21/20/4 +f 19/19/4 22/22/4 24/24/4 +f 19/19/4 24/24/4 23/23/4 +f 25/25/5 27/26/5 26/27/5 +f 25/25/5 29/28/5 28/29/5 +f 25/25/5 26/27/5 29/28/5 +f 25/25/5 28/29/5 30/30/5 +f 25/25/5 30/30/5 27/26/5 +f 31/31/6 33/32/6 32/33/6 +f 31/31/6 35/34/6 34/35/6 +f 31/31/6 32/33/6 36/36/6 +f 31/31/6 36/36/6 35/34/6 +f 31/31/6 34/35/6 33/32/6 +f 37/37/7 38/38/7 39/39/7 +f 37/37/7 39/39/7 40/40/7 +f 37/37/7 40/40/7 41/41/7 +f 37/37/7 41/41/7 42/42/7 +f 37/37/7 42/42/7 38/38/7 +f 43/43/8 44/44/8 45/45/8 +f 43/43/8 45/45/8 46/46/8 +f 43/43/8 47/47/8 48/48/8 +f 43/43/8 46/46/8 47/47/8 +f 43/43/8 48/48/8 44/44/8 +f 49/49/9 50/50/9 51/51/9 +f 49/49/9 51/51/9 52/52/9 +f 49/49/9 53/53/9 54/54/9 +f 49/49/9 52/52/9 53/53/9 +f 49/49/9 54/54/9 50/50/9 +f 55/55/10 56/56/10 57/57/10 +f 55/55/10 58/58/10 56/56/10 +f 55/55/10 57/57/10 59/59/10 +f 55/55/10 60/60/10 58/58/10 +f 55/55/10 59/59/10 60/60/10 +f 61/61/11 62/62/11 63/63/11 +f 61/61/11 64/64/11 65/65/11 +f 61/61/11 65/65/11 62/62/11 +f 61/61/11 66/66/11 64/64/11 +f 61/61/11 63/63/11 66/66/11 +f 67/67/12 68/68/12 69/69/12 +f 67/67/12 70/70/12 71/71/12 +f 67/67/12 72/72/12 68/68/12 +f 67/67/12 71/71/12 72/72/12 +f 67/67/12 69/69/12 70/70/12 diff --git a/assets/icosahedron.mtl b/assets/icosahedron.mtl index 46bc110..44b3c44 100644 --- a/assets/icosahedron.mtl +++ b/assets/icosahedron.mtl @@ -1,2 +1,12 @@ -# Blender 3.4.1 MTL File: 'None' -# www.blender.org +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Default_OBJ +Ns 250.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 diff --git a/assets/icosahedron.obj b/assets/icosahedron.obj index 4253bc0..94dea53 100644 --- a/assets/icosahedron.obj +++ b/assets/icosahedron.obj @@ -1,79 +1,166 @@ -# Blender 3.4.1 +# Blender v3.4.1 OBJ File: '' # www.blender.org mtllib icosahedron.mtl -o Icosphere -v 0.000000 -1.000000 0.000000 -v 0.723600 -0.447215 0.525720 -v -0.276385 -0.447215 0.850640 -v -0.894425 -0.447215 0.000000 -v -0.276385 -0.447215 -0.850640 -v 0.723600 -0.447215 -0.525720 -v 0.276385 0.447215 0.850640 -v -0.723600 0.447215 0.525720 -v -0.723600 0.447215 -0.525720 -v 0.276385 0.447215 -0.850640 -v 0.894425 0.447215 0.000000 -v 0.000000 1.000000 0.000000 -vn 0.1876 -0.7947 0.5774 -vn 0.6071 -0.7947 -0.0000 -vn -0.4911 -0.7947 0.3568 -vn -0.4911 -0.7947 -0.3568 -vn 0.1876 -0.7947 -0.5774 -vn 0.9822 -0.1876 -0.0000 -vn 0.3035 -0.1876 0.9342 -vn -0.7946 -0.1876 0.5774 -vn -0.7946 -0.1876 -0.5774 -vn 0.3035 -0.1876 -0.9342 -vn 0.7946 0.1876 0.5774 -vn -0.3035 0.1876 0.9342 -vn -0.9822 0.1876 -0.0000 -vn -0.3035 0.1876 -0.9342 -vn 0.7946 0.1876 -0.5774 -vn 0.4911 0.7947 0.3568 -vn -0.1876 0.7947 0.5774 -vn -0.6071 0.7947 -0.0000 -vn -0.1876 0.7947 -0.5774 -vn 0.4911 0.7947 -0.3568 +o Icosphere.001 +v 0.000000 -1.093451 -0.000000 +v 0.791221 -0.489008 0.574849 +v -0.302214 -0.489008 0.930134 +v 0.791221 -0.489008 -0.574849 +v -0.978010 -0.489008 -0.000000 +v -0.302214 -0.489008 -0.930134 +v 0.978010 0.489008 0.000000 +v 0.302214 0.489008 0.930134 +v -0.791221 0.489008 0.574849 +v -0.791221 0.489008 -0.574849 +v 0.302214 0.489008 -0.930134 +v 0.000000 1.093451 0.000000 +v -0.791221 0.489008 -0.574849 +v -0.791221 0.489008 -0.574849 +v -0.791221 0.489008 -0.574849 +v -0.791221 0.489008 -0.574849 +v 0.000000 1.093451 0.000000 +v 0.000000 1.093451 0.000000 +v 0.000000 1.093451 0.000000 +v 0.000000 1.093451 0.000000 +v 0.000000 -1.093451 -0.000000 +v 0.000000 -1.093451 -0.000000 +v 0.000000 -1.093451 -0.000000 +v 0.000000 -1.093451 -0.000000 +v 0.791221 -0.489008 0.574849 +v 0.791221 -0.489008 0.574849 +v 0.791221 -0.489008 0.574849 +v 0.791221 -0.489008 0.574849 +v -0.302214 -0.489008 0.930134 +v -0.302214 -0.489008 0.930134 +v -0.302214 -0.489008 0.930134 +v -0.302214 -0.489008 0.930134 +v 0.791221 -0.489008 -0.574849 +v 0.791221 -0.489008 -0.574849 +v 0.791221 -0.489008 -0.574849 +v 0.791221 -0.489008 -0.574849 +v -0.978010 -0.489008 -0.000000 +v -0.978010 -0.489008 -0.000000 +v -0.978010 -0.489008 -0.000000 +v -0.978010 -0.489008 -0.000000 +v -0.302214 -0.489008 -0.930134 +v -0.302214 -0.489008 -0.930134 +v -0.302214 -0.489008 -0.930134 +v -0.302214 -0.489008 -0.930134 +v 0.978010 0.489008 0.000000 +v 0.978010 0.489008 0.000000 +v 0.978010 0.489008 0.000000 +v 0.978010 0.489008 0.000000 +v 0.302214 0.489008 0.930134 +v 0.302214 0.489008 0.930134 +v 0.302214 0.489008 0.930134 +v 0.302214 0.489008 0.930134 +v -0.791221 0.489008 0.574849 +v -0.791221 0.489008 0.574849 +v -0.791221 0.489008 0.574849 +v -0.791221 0.489008 0.574849 +v 0.302214 0.489008 -0.930134 +v 0.302214 0.489008 -0.930134 +v 0.302214 0.489008 -0.930134 +v 0.302214 0.489008 -0.930134 vt 0.181819 0.000000 +vt 0.272728 0.157461 +vt 0.090910 0.157461 +vt 0.272728 0.157461 vt 0.363637 0.000000 +vt 0.454546 0.157461 vt 0.909091 0.000000 +vt 1.000000 0.157461 +vt 0.818182 0.157461 vt 0.727273 0.000000 +vt 0.818182 0.157461 +vt 0.636364 0.157461 vt 0.545455 0.000000 +vt 0.636364 0.157461 +vt 0.454546 0.157461 vt 0.272728 0.157461 -vt 1.000000 0.157461 +vt 0.454546 0.157461 +vt 0.363637 0.314921 vt 0.090910 0.157461 +vt 0.272728 0.157461 +vt 0.181819 0.314921 vt 0.818182 0.157461 +vt 1.000000 0.157461 +vt 0.909091 0.314921 vt 0.636364 0.157461 +vt 0.818182 0.157461 +vt 0.727273 0.314921 vt 0.454546 0.157461 +vt 0.636364 0.157461 +vt 0.545455 0.314921 +vt 0.272728 0.157461 +vt 0.363637 0.314921 +vt 0.181819 0.314921 +vt 0.090910 0.157461 vt 0.181819 0.314921 vt 0.000000 0.314921 +vt 0.818182 0.157461 vt 0.909091 0.314921 vt 0.727273 0.314921 +vt 0.636364 0.157461 +vt 0.727273 0.314921 +vt 0.545455 0.314921 +vt 0.454546 0.157461 vt 0.545455 0.314921 vt 0.363637 0.314921 +vt 0.181819 0.314921 +vt 0.363637 0.314921 vt 0.272728 0.472382 +vt 0.000000 0.314921 +vt 0.181819 0.314921 vt 0.090910 0.472382 +vt 0.727273 0.314921 +vt 0.909091 0.314921 vt 0.818182 0.472382 +vt 0.545455 0.314921 +vt 0.727273 0.314921 vt 0.636364 0.472382 +vt 0.363637 0.314921 +vt 0.545455 0.314921 vt 0.454546 0.472382 -s 0 -f 1/1/1 2/6/1 3/8/1 -f 2/6/2 1/2/2 6/11/2 -f 1/3/3 3/7/3 4/9/3 -f 1/4/4 4/9/4 5/10/4 -f 1/5/5 5/10/5 6/11/5 -f 2/6/6 6/11/6 11/17/6 -f 3/8/7 2/6/7 7/12/7 -f 4/9/8 3/7/8 8/14/8 -f 5/10/9 4/9/9 9/15/9 -f 6/11/10 5/10/10 10/16/10 -f 2/6/11 11/17/11 7/12/11 -f 3/8/12 7/12/12 8/13/12 -f 4/9/13 8/14/13 9/15/13 -f 5/10/14 9/15/14 10/16/14 -f 6/11/15 10/16/15 11/17/15 -f 7/12/16 11/17/16 12/18/16 -f 8/13/17 7/12/17 12/19/17 -f 9/15/18 8/14/18 12/20/18 -f 10/16/19 9/15/19 12/21/19 -f 11/17/20 10/16/20 12/22/20 +vn 0.1876 -0.7947 0.5774 +vn 0.6071 -0.7947 -0.0000 +vn -0.4911 -0.7947 0.3568 +vn -0.4911 -0.7947 -0.3568 +vn 0.1876 -0.7947 -0.5774 +vn 0.9822 -0.1876 -0.0000 +vn 0.3035 -0.1876 0.9342 +vn -0.7946 -0.1876 0.5774 +vn -0.7946 -0.1876 -0.5774 +vn 0.3035 -0.1876 -0.9342 +vn 0.7946 0.1876 0.5774 +vn -0.3035 0.1876 0.9342 +vn -0.9822 0.1876 0.0000 +vn -0.3035 0.1876 -0.9342 +vn 0.7946 0.1876 -0.5774 +vn 0.4911 0.7947 0.3568 +vn -0.1876 0.7947 0.5774 +vn -0.6071 0.7947 0.0000 +vn -0.1876 0.7947 -0.5774 +vn 0.4911 0.7947 -0.3568 +usemtl Default_OBJ +s 1 +f 21/1/1 25/2/1 29/3/1 +f 26/4/2 24/5/2 33/6/2 +f 22/7/3 31/8/3 37/9/3 +f 23/10/4 39/11/4 41/12/4 +f 1/13/5 43/14/5 35/15/5 +f 27/16/6 36/17/6 45/18/6 +f 30/19/7 28/20/7 49/21/7 +f 38/22/8 32/23/8 53/24/8 +f 42/25/9 40/26/9 14/27/9 +f 34/28/10 44/29/10 57/30/10 +f 2/31/11 46/32/11 51/33/11 +f 3/34/12 52/35/12 54/36/12 +f 5/37/13 55/38/13 15/39/13 +f 6/40/14 16/41/14 60/42/14 +f 4/43/15 59/44/15 47/45/15 +f 50/46/16 48/47/16 18/48/16 +f 56/49/17 8/50/17 20/51/17 +f 13/52/18 9/53/18 17/54/18 +f 58/55/19 10/56/19 19/57/19 +f 7/58/20 11/59/20 12/60/20 diff --git a/assets/octahedron.mtl b/assets/octahedron.mtl new file mode 100644 index 0000000..58c39f5 --- /dev/null +++ b/assets/octahedron.mtl @@ -0,0 +1,12 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl None +Ns 499.999983 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.800000 0.800000 0.800000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 diff --git a/assets/octahedron.obj b/assets/octahedron.obj new file mode 100644 index 0000000..5ce3470 --- /dev/null +++ b/assets/octahedron.obj @@ -0,0 +1,70 @@ +# Blender v3.4.1 OBJ File: '' +# www.blender.org +mtllib octahedron.mtl +o Circle_Circle.001 +v 0.000003 1.003216 0.000014 +v -0.707125 0.000000 -0.707121 +v 0.707135 0.000000 -0.707091 +v -0.707107 -0.000000 0.707107 +v 0.707164 -0.000000 0.707116 +v 0.000003 -1.003216 0.000014 +v 0.000003 1.003216 0.000014 +v 0.000003 1.003216 0.000014 +v 0.000003 1.003216 0.000014 +v -0.707125 0.000000 -0.707121 +v -0.707125 0.000000 -0.707121 +v -0.707125 0.000000 -0.707121 +v 0.707135 0.000000 -0.707091 +v 0.707135 0.000000 -0.707091 +v 0.707135 0.000000 -0.707091 +v -0.707107 -0.000000 0.707107 +v -0.707107 -0.000000 0.707107 +v -0.707107 -0.000000 0.707107 +v 0.707164 -0.000000 0.707116 +v 0.707164 -0.000000 0.707116 +v 0.707164 -0.000000 0.707116 +v 0.000003 -1.003216 0.000014 +v 0.000003 -1.003216 0.000014 +v 0.000003 -1.003216 0.000014 +vt 0.250045 0.749962 +vt 0.000076 0.999925 +vt 0.500014 0.999929 +vt 0.500014 0.999929 +vt 0.500010 0.500000 +vt 0.250045 0.749962 +vt 0.250045 0.749962 +vt 0.500010 0.500000 +vt 0.000071 0.500000 +vt 0.000076 0.999925 +vt 0.250045 0.749962 +vt 0.000071 0.500000 +vt 0.000076 0.000075 +vt 0.000071 0.500000 +vt 0.250045 0.250038 +vt 0.500014 0.000071 +vt 0.250045 0.250038 +vt 0.500010 0.500000 +vt 0.250045 0.250038 +vt 0.500014 0.000071 +vt 0.000076 0.000075 +vt 0.250045 0.250038 +vt 0.000071 0.500000 +vt 0.500010 0.500000 +vn 0.0000 0.5761 -0.8174 +vn -0.8174 0.5761 0.0000 +vn -0.0000 0.5761 0.8174 +vn 0.8174 0.5761 -0.0000 +vn 0.8174 -0.5761 -0.0000 +vn -0.8174 -0.5761 0.0000 +vn 0.0000 -0.5761 -0.8174 +vn -0.0000 -0.5761 0.8174 +usemtl None +s 1 +f 7/1/1 13/2/1 10/3/1 +f 11/4/2 16/5/2 9/6/2 +f 8/7/3 17/8/3 19/9/3 +f 14/10/4 1/11/4 20/12/4 +f 15/13/5 21/14/5 22/15/5 +f 12/16/6 23/17/6 18/18/6 +f 24/19/7 2/20/7 3/21/7 +f 6/22/8 5/23/8 4/24/8 diff --git a/assets/octohedron.png b/assets/octahedron.png Binary files differindex 63c70b2..63c70b2 100644 --- a/assets/octohedron.png +++ b/assets/octahedron.png diff --git a/assets/octohedron.mtl b/assets/octohedron.mtl deleted file mode 100644 index f231bdf..0000000 --- a/assets/octohedron.mtl +++ /dev/null @@ -1,10 +0,0 @@ -# Blender MTL File: 'None' -# Material Count: 1 - -newmtl None -Ns 500 -Ka 0.8 0.8 0.8 -Kd 0.8 0.8 0.8 -Ks 0.8 0.8 0.8 -d 1 -illum 2 diff --git a/assets/octohedron.obj b/assets/octohedron.obj deleted file mode 100644 index 424d8a8..0000000 --- a/assets/octohedron.obj +++ /dev/null @@ -1,32 +0,0 @@ -# Blender v3.4.1 OBJ File: '' -# www.blender.org -mtllib octohedron.mtl -o Circle_Circle.001 -v 0.707135 0.000000 -0.707091 -v 0.000003 1.003216 0.000014 -v -0.707125 0.000000 -0.707121 -v -0.707107 0.000000 0.707107 -v 0.707164 0.000000 0.707116 -v 0.000003 -1.003216 0.000014 -vt 0.250045 0.749962 -vt 0.500014 0.999929 -vt 0.000076 0.999925 -vt 0.500010 0.500000 -vt 0.000071 0.500000 -vt 0.000076 0.000075 -vt 0.250045 0.250038 -vt 0.500014 0.000071 -vn -0.0000 -0.5761 0.8174 -vn 0.8174 -0.5761 -0.0000 -vn 0.0000 -0.5761 -0.8174 -vn -0.8174 -0.5761 0.0000 -usemtl None -s off -f 2/1/1 3/2/1 1/3/1 -f 3/2/2 2/1/2 4/4/2 -f 2/1/3 5/5/3 4/4/3 -f 1/3/4 5/5/4 2/1/4 -f 1/6/2 5/5/2 6/7/2 -f 3/8/4 6/7/4 4/4/4 -f 6/7/3 3/8/3 1/6/3 -f 6/7/1 5/5/1 4/4/1 diff --git a/assets/tetrahedron.obj b/assets/tetrahedron.obj index b4ba6ed..b8ab982 100644 --- a/assets/tetrahedron.obj +++ b/assets/tetrahedron.obj @@ -2,23 +2,37 @@ # www.blender.org mtllib tetrahedron.mtl o Circle_Circle.002 -v -0.000000 -0.497806 -1.000000 -v -0.866025 -0.497806 0.500000 -v 0.866025 -0.497806 0.500000 -v 0.000000 0.916407 0.000000 +v -0.000000 -0.353553 -1.000000 +v -0.866025 -0.353553 0.500000 +v 0.866025 -0.353553 0.500000 +v 0.000000 1.060660 -0.000000 +v -0.866025 -0.353553 0.500000 +v -0.866025 -0.353553 0.500000 +v -0.000000 -0.353553 -1.000000 +v -0.000000 -0.353553 -1.000000 +v 0.866025 -0.353553 0.500000 +v 0.866025 -0.353553 0.500000 +v 0.000000 1.060660 -0.000000 +v 0.000000 1.060660 -0.000000 vt 0.433025 0.250046 -vt 0.433025 0.749954 vt 0.865957 0.500000 +vt 0.433025 0.749954 vt 0.865957 0.999907 +vt 0.433025 0.749954 +vt 0.865957 0.500000 vt 0.865957 0.000093 +vt 0.865957 0.500000 +vt 0.433025 0.250046 vt 0.000093 0.500000 -vn 0.0000 1.0000 0.0000 +vt 0.433025 0.250046 +vt 0.433025 0.749954 +vn 0.0000 -1.0000 0.0000 vn 0.0000 0.3333 0.9428 vn 0.8165 0.3333 -0.4714 vn -0.8165 0.3333 -0.4714 usemtl None s off -f 1/1/1 2/2/1 3/3/1 -f 4/4/2 2/2/2 3/3/2 -f 4/5/3 3/3/3 1/1/3 -f 4/6/4 1/1/4 2/2/4 +f 7/1/1 9/2/1 5/3/1 +f 12/4/2 6/5/2 10/6/2 +f 11/7/3 3/8/3 8/9/3 +f 4/10/4 1/11/4 2/12/4 diff --git a/honey/init.lua b/honey/init.lua new file mode 100644 index 0000000..c3dda37 --- /dev/null +++ b/honey/init.lua @@ -0,0 +1,29 @@ +local glfw = honey.glfw +local gl = honey.gl +local window = require 'honey.window' + +local hinit = {} +setmetatable(hinit, {__index=_G}) +setfenv(1, hinit) + + +function init(width, height, title) + local width = width or 640 + local height = height or 480 + local title = title or "honey3d" + + glfw.Init() + local window = honey.Window(width, height, title) + glfw.MakeContextCurrent(window.win) + gl.InitGlad() + + return window +end + + +function terminate() + glfw.Terminate() +end + + +return hinit diff --git a/honey/mat4.lua b/honey/mat4.lua new file mode 100644 index 0000000..a97129c --- /dev/null +++ b/honey/mat4.lua @@ -0,0 +1,144 @@ +local glm = honey.glm +local Vec3 = require 'honey.vec3' + +local module = {} +setmetatable(module, {__index=_G}) +setfenv(1, module) + +local RowLookup = {} +function RowLookup.new(_, row, data) + local self = { + row=row, + data=data, + } + setmetatable(self, RowLookup) + return self +end +setmetatable(RowLookup, {__call=RowLookup.new}) +function RowLookup.__index(self, col) + return glm.mat4_get(self.data, col-1, self.row-1) +end +function RowLookup.__newindex(self, col, value) + return glm.mat4_set(self.data, col-1, self.row-1, value) +end + + + +Mat4 = {} + +function Mat4.new(_, self, values) + local self = {} + self.type = "mat4" + self.data = glm.mat4_create() + setmetatable(self, Mat4) + if values then + self[1][1] = values[1] + self[1][2] = values[2] + self[1][3] = values[3] + self[1][4] = values[4] + + self[2][1] = values[5] + self[2][2] = values[6] + self[2][3] = values[7] + self[2][4] = values[8] + + self[3][1] = values[9] + self[3][2] = values[10] + self[3][3] = values[11] + self[3][4] = values[12] + + self[4][1] = values[13] + self[4][2] = values[14] + self[4][3] = values[15] + self[4][4] = values[16] + end + return self +end +setmetatable(Mat4, {__call=Mat4.new}) + + +function Mat4.__index(self, key) + if type(key) == "number" then + return RowLookup(key, self.data) + else + return Mat4[key] + end +end + + +function Mat4.__tostring(self) + return string.format( + "/ %0.4f, %0.4f, %0.4f, %0.4f \\\n" .. + "| %0.4f, %0.4f, %0.4f, %0.4f |\n" .. + "| %0.4f, %0.4f, %0.4f, %0.4f |\n" .. + "\\ %0.4f, %0.4f, %0.4f, %0.4f /", + self[1][1], self[1][2], self[1][3], self[1][4], + self[2][1], self[2][2], self[2][3], self[2][4], + self[3][1], self[3][2], self[3][3], self[3][4], + self[4][1], self[4][2], self[4][3], self[4][4] + ) +end + + +function Mat4.__mul(self, other) + if other.type == "mat4" then + local dest = Mat4() + glm.mat4_mul(self.data, other.data, dest.data) + return dest + elseif other.type == "vec4" then + -- todo + elseif other.type == "vec3" then + local dest = Vec3() + glm.mat4_mulv3(self.data, other.data, 1.0, dest.data) + return dest + else + error(string.format("cannot multiply Mat4 by %s", type(other))) + end +end + + +function Mat4.copyTo(self, dest) + glm.mat4_copy(self.data, dest.data) +end + + +function Mat4.identity(self) + glm.mat4_identity(self.data) +end + + +function Mat4.zero(self) + glm.mat4_zero(self.data) +end + + +function Mat4.translate(self, vec) + glm.translate(self.data, vec.data) +end + + +function Mat4.rotateX(self, angle) + glm.rotate_x(self.data, angle, self.data) +end +function Mat4.rotateY(self, angle) + glm.rotate_y(self.data, angle, self.data) +end +function Mat4.rotateZ(self, angle) + glm.rotate_z(self.data, angle, self.data) +end + + +function Mat4.scale(self, vec) + glm.scale(self.data, vec.data) +end + + +function Mat4.perspective(self, fovy, aspect, near, far) + glm.perspective(fovy, aspect, near, far, self.data) +end +function Mat4.perspectiveResize(self, aspect) + glm.perspective_resize(aspect, self.data) +end + + +return module.Mat4 diff --git a/honey/mesh.lua b/honey/mesh.lua new file mode 100644 index 0000000..430d5c3 --- /dev/null +++ b/honey/mesh.lua @@ -0,0 +1,95 @@ +local mesh = {} +local gl = honey.gl +setmetatable(mesh, {__index=_G}) +setfenv(1, mesh) + + +local function insertVertex(vertices, attrib, vertex) + local pos = 3*vertex.v_idx + for i=1,3 do + table.insert(vertices, attrib.vertices[pos+i]) + end + + local normal = 3*vertex.vn_idx + for i=1,3 do + table.insert(vertices, attrib.normals[normal+i]) + end + + local tex = 3*vertex.vt_idx + for i=1,2 do + table.insert(vertices, attrib.texcoords[tex+i]) + end +end + + +function loadShape(shape, attrib) + local vertices = {} + local indices = {} + + local start = shape.face_offset + local finish = start + shape.length + for i=start,finish-1 do + assert(attrib.face_num_verts[i+1] == 3, "non-triangular face!") + for j=0,2 do + local vertex = attrib.faces[(3*i) + j + 1] + insertVertex(vertices, attrib, vertex) + table.insert(indices, #indices) + end + end + + return vertices, indices +end + + +function loadFile(filename) + local flags = honey.tinyobj.FLAG_TRIANGULATE + local attrib, shapes, materials = honey.tinyobj.parse_obj(filename, flags) + + local meshes = {} + for _, shape in ipairs(shapes) do + local vertices, indices = loadShape(shape, attrib) + table.insert(meshes, Mesh(vertices, indices)) + end + return meshes +end + + +Mesh = {} +Mesh.__index = Mesh + + +function Mesh.new(_, vertices, indices) + local self = {} + setmetatable(self, Mesh) + + self.vertexArray = gl.GenVertexArrays() + self.vertexBuffer = gl.GenBuffers() + self.elementBuffer = gl.GenBuffers() + self.vertexCount = #indices + + gl.BindVertexArray(self.vertexArray) + gl.BindBuffer(gl.ARRAY_BUFFER, self.vertexBuffer) + gl.BufferData(gl.ARRAY_BUFFER, gl.FLOAT, vertices, gl.STATIC_DRAW) + + gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, self.elementBuffer) + gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, gl.UNSIGNED_INT, indices, gl.STATIC_DRAW) + + gl.VertexAttribPointer(0, 3, false, 8, 0) + gl.EnableVertexAttribArray(0) + gl.VertexAttribPointer(1, 3, false, 8, 3) + gl.EnableVertexAttribArray(1) + gl.VertexAttribPointer(2, 2, false, 8, 6) + gl.EnableVertexAttribArray(2) + + return self +end +setmetatable(Mesh, {__call=Mesh.new}) + + +function Mesh.drawElements(self) + gl.BindVertexArray(self.vertexArray) + gl.DrawElements(gl.TRIANGLES, self.vertexCount, gl.UNSIGNED_INT, 0) +end + + +return mesh diff --git a/honey/std.lua b/honey/std.lua index 923c66a..78b2525 100644 --- a/honey/std.lua +++ b/honey/std.lua @@ -1,3 +1,13 @@ +local init = require 'honey.init' local window = require 'honey.window' +local mesh = require 'honey.mesh' +local Vec3 = require 'honey.vec3' +local Mat4 = require 'honey.mat4' + +honey.init = init.init +honey.terminate = init.terminate honey.Window = window.Window +honey.mesh = mesh +honey.Vec3 = Vec3 +honey.Mat4 = Mat4 diff --git a/honey/vec3.lua b/honey/vec3.lua new file mode 100644 index 0000000..af9ac4b --- /dev/null +++ b/honey/vec3.lua @@ -0,0 +1,170 @@ +local glm = honey.glm + +local vec3 = {} +setmetatable(vec3, {__index=_G}) +setfenv(1, vec3) + + +Vec3 = {} + +function Vec3.new(_, values) + local self = {} + self.data = glm.vec3_create() + setmetatable(self, Vec3) + if values then + self[1] = values[1] + self[2] = values[2] + self[3] = values[3] + end + return self +end +setmetatable(Vec3, {__call=Vec3.new}) + + +function Vec3.__index(self, key) + if type(key) == 'number' then + return glm.vec3_get(self.data, key-1) + else + return Vec3[key] + end +end + + +function Vec3.__newindex(self, key, value) + glm.vec3_set(self.data, key-1, value) +end + + +function Vec3.__tostring(self) + return string.format("[%.4f, %.4f, %.4f]", self[1], self[2], self[3]) +end + + +--===== arithmetic =====-- + +local function swapIfNumber(self, other) + if type(self) == "number" and type(other) == "table" then + return other, self + else + return self, other + end +end + + +function Vec3.__add(self, other) + local self, other = swapIfNumber(self, other) + + local dest = Vec3() + if type(other) == "number" then + glm.vec3_adds(self.data, other, dest.data) + elseif type(other) == "table" then + glm.vec3_add(self.data, other.data, dest.data) + else + error(string.format("cannot add %s to Vec3", type(other))) + end + return dest +end + + +function Vec3.__sub(self, other) + local dest = Vec3() + if type(other) == "number" then + glm.vec3_subs(self.data, other, dest.data) + elseif type(other) == "table" then + glm.vec3_sub(self.data, other.data, dest.data) + else + error(string.format("cannot subtract %s from Vec3", type(other))) + end + return dest +end + + +function Vec3.__mul(self, other) + local self, other = swapIfNumber(self, other) + local dest = Vec3() + if type(other) == "number" then + glm.vec3_scale(self.data, other, dest.data) + elseif type(other) == "table" then + glm.vec3_mul(self.data, other.data, dest.data) + else + error(string.format("cannot multiply %s and Vec3", type(other))) + end + return dest +end + + +function Vec3.__div(self, other) + local dest = Vec3() + if type(other) == "number" then + glm.vec3_divs(self.data, other, dest.data) + elseif type(other) == "table" then + glm.vec3_div(self.data, other.data, dest.data) + else + error(string.format("cannot divide Vec3 by %s", type(other))) + end + return dest +end + + + + +function Vec3.copyTo(self, dest) + glm.vec3_copy(self.data, dest.data) +end + + +function Vec3.zero(self) + glm.vec3_zero(self.data) +end + + +function Vec3.zero(self) + glm.vec3_zero(self.data) +end +function Vec3.one(self) + glm.vec3_one(self.data) +end + + +function Vec3.dot(self, other) + return glm.vec3_dot(self.data, other.data) +end + + +function Vec3.crossTo(self, other, dest) + glm.vec3_cross(self.data, other.data, dest.data) +end +function Vec3.cross(self, other) + local dest = Vec3() + self:crossTo(other, dest) + return dest +end + + +function Vec3.crossnTo(self, other, dest) + glm.vec3_crossn(self.data, other.data, dest.data) +end +function Vec3.crossn(self, other) + local dest = Vec3() + self:crossTo(other, dest) + return dest +end + + +function Vec3.norm2(self) + return glm.vec3_norm2(self.data) +end +function Vec3.norm(self) + return glm.vec3_norm(self.data) +end + + +function Vec3.normalize(self) + glm.vec3_normalize(self.data) +end +function Vec3.normalizeTo(self, dest) + glm.vec3_normalize_to(self.data, dest.data) +end + + +return vec3.Vec3 diff --git a/honey/window.lua b/honey/window.lua index 204f8e4..35e04ac 100644 --- a/honey/window.lua +++ b/honey/window.lua @@ -17,7 +17,6 @@ function Window.new(_, width, height, title, monitor, share) self.win = glfw.CreateWindow(width, height, title, monitor, share) self.__gc = honey.util.gc_canary(function() - print("destroying window " .. tostring(self.win)) glfw.DestroyWindow(self.win) end) @@ -149,7 +148,7 @@ function Window.setContentScaleCallback(self, cb) end -function Window.SwapBuffers(self) +function Window.swapBuffers(self) glfw.SwapBuffers(self.win) end @@ -1,10 +1,126 @@ require 'honey.std' -honey.glfw.Init() -local window = honey.Window(640, 480, "geometry") +local glfw = honey.glfw +local gl = honey.gl +local Vec3 = honey.Vec3 +local Mat4 = honey.Mat4 + + +local window = honey.init() +gl.Enable(gl.DEPTH_TEST) + + +local model = Mat4() +model:identity() + +local view = Mat4() +view:identity() +view:translate(Vec3{0, 0, -3}) + +local projection = Mat4() +projection:perspective(math.rad(45), 640/480, 0.1, 100) + + +local vertexShaderSource = [[ +#version 410 core +layout (location = 0) in vec3 in_position; +layout (location = 1) in vec3 in_normal; +layout (location = 2) in vec2 in_tex; + +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; + +out vec3 position; +out vec3 normal; +out vec2 tex; + +void main() +{ + gl_Position = projection * view * model * vec4(in_position, 1.0); + position = in_position; + //normal = vec3(model * vec4(in_normal, 1.0f)); + normal = in_normal; + tex = in_tex; +} +]] + +local fragmentShaderSource = [[ +#version 410 core +out vec4 FragColor; + +in vec3 position; +in vec3 normal; +in vec2 tex; + +uniform sampler2D ourTexture; + +void main() +{ + FragColor = vec4(normal, 1.0f); + //FragColor = vec4(tex, 1.0f, 1.0f); + //FragColor = texture(ourTexture, TexCoord); +} +]] + +-- vertex shader +local vertexShader = gl.CreateShader(gl.VERTEX_SHADER) +gl.ShaderSource(vertexShader, vertexShaderSource) +gl.CompileShader(vertexShader) + +-- fragment shader +local fragmentShader = gl.CreateShader(gl.FRAGMENT_SHADER) +gl.ShaderSource(fragmentShader, fragmentShaderSource) +gl.CompileShader(fragmentShader) + +-- link +local shader = gl.CreateProgram() +gl.AttachShader(shader, vertexShader) +gl.AttachShader(shader, fragmentShader) +gl.LinkProgram(shader) +-- clean up +gl.DeleteShader(vertexShader) +gl.DeleteShader(fragmentShader) + + +local mesh = honey.mesh.loadFile("assets/tetrahedron.obj")[1] +--local mesh = honey.mesh.Mesh( +-- { +-- 0, 0, 0, 0, 0, 1, 0, 0, +-- 1, 0, 0, 0, 0, 1, 1, 0, +-- 0, 1, 0, 0, 0, 1, 0, 1, +-- }, +-- { 0, 2, 1 } +--) + + while not window:shouldClose() do - print(window:getSize()) - honey.glfw.PollEvents() + local time = glfw.GetTime() + model:identity() + model:rotateY(0.5 * math.pi * time) + model:rotateX(0.05 * math.pi * time) + --model:scale(0.2 * Vec3{1, 1, 1}) + + gl.ClearColor(0.2, 0.4, 1.0, 1.0) + gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT) + + gl.UseProgram(shader) + + local modelLocation = gl.GetUniformLocation(shader, "model") + local viewLocation = gl.GetUniformLocation(shader, "view") + local projectionLocation = gl.GetUniformLocation(shader, "projection") + + gl.UniformMatrix4fv(modelLocation, false, model.data) + gl.UniformMatrix4fv(viewLocation, false, view.data) + gl.UniformMatrix4fv(projectionLocation, false, projection.data) + + mesh:drawElements() + + + window:swapBuffers() + glfw.PollEvents() end + +honey.terminate() |