diff options
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 +} |