From f439828dc068974ddc161cc3469ac489a93bbabc Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sat, 23 Dec 2023 17:04:05 -0700 Subject: Working on the web assembly openglES issue --- src/util.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 8165e11..692ae4b 100644 --- a/src/util.c +++ b/src/util.c @@ -81,3 +81,45 @@ void copyTriangle3D(Triangle3D a, const Triangle3D b) { a[1] = b[1]; a[2] = b[2]; } + +Vector3 getVertexAt(Mesh mesh, int vertexNum) { + return (Vector3){ + mesh.vertices[vertexNum * 3], + mesh.vertices[vertexNum * 3 + 1], + mesh.vertices[vertexNum * 3 + 2] + }; +} + +void drawModelWireframe(Model model, Vector3 position, Quaternion rotation, Color color) { + // DrawModelWires doesn't work on the version of opengl that web assembly uses. + // Instead I use this stupid peice of shit. + +#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33) + model.transform = QuaternionToMatrix(rotation); + DrawModelWires(model, position, 1.0, color); +#else + for (int i = 0; i < model.meshCount; ++i) { + Mesh mesh = model.meshes[i]; + + // Loop through the triangles. + for (int triangleNum = 0; triangleNum < mesh.triangleCount; ++triangleNum) { + Triangle3D triangle = { + getVertexAt(mesh, triangleNum * 3), + getVertexAt(mesh, triangleNum * 3 + 1), + getVertexAt(mesh, triangleNum * 3 + 2) + }; + + // Rotation and transform. + for (int vertexNum = 0; vertexNum < 3; ++vertexNum) { + triangle[vertexNum] = Vector3RotateByQuaternion(triangle[vertexNum], rotation); + triangle[vertexNum] = Vector3Add(triangle[vertexNum], position); + } + + // Draw. + DrawLine3D(triangle[0], triangle[1], color); + DrawLine3D(triangle[1], triangle[2], color); + DrawLine3D(triangle[2], triangle[0], color); + } + } +#endif +} -- cgit v1.2.3