diff options
author | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-23 17:04:05 -0700 |
---|---|---|
committer | nathansmithsmith <thenathansmithsmith@gmail.com> | 2023-12-23 17:04:05 -0700 |
commit | f439828dc068974ddc161cc3469ac489a93bbabc (patch) | |
tree | 1d74af0b59744a17ba73716d91196922d3843859 /src/util.c | |
parent | 2c046ef3dca9e128a801c7a92c3a3a63e01fdd98 (diff) |
Working on the web assembly openglES issue
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -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 +} |