From e975a5b5f23c84dd81e2116fa5a866e9a591a55f Mon Sep 17 00:00:00 2001 From: Nikhil Date: Thu, 29 Feb 2024 22:25:16 -0800 Subject: [PATCH] Added another Draw Model method that can be drawn using Matrices --- src/raylib.h | 1 + src/rmodels.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 03045ed13..ab177a2df 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1529,6 +1529,7 @@ RLAPI BoundingBox GetModelBoundingBox(Model model); // Model drawing functions RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters +RLAPI void DrawModelEx2(Model* model, const Matrix* transform, Color tint); // Draw a model with extended parameters RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) diff --git a/src/rmodels.c b/src/rmodels.c index 5be06b370..97c5a378c 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -3545,6 +3545,27 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota } } +void DrawModelEx2(Model* model, const Matrix* transform, Color tint) +{ + // Combine model transformation matrix (model.transform) with matrix generated by function parameters (matTransform) + model->transform = MatrixMultiply(model->transform, *transform); + + for (int i = 0; i < model->meshCount; i++) + { + Color color = model->materials[model->meshMaterial[i]].maps[MATERIAL_MAP_DIFFUSE].color; + + Color colorTint = WHITE; + colorTint.r = (unsigned char)((((float)color.r / 255.0f) * ((float)tint.r / 255.0f)) * 255.0f); + colorTint.g = (unsigned char)((((float)color.g / 255.0f) * ((float)tint.g / 255.0f)) * 255.0f); + colorTint.b = (unsigned char)((((float)color.b / 255.0f) * ((float)tint.b / 255.0f)) * 255.0f); + colorTint.a = (unsigned char)((((float)color.a / 255.0f) * ((float)tint.a / 255.0f)) * 255.0f); + + model->materials[model->meshMaterial[i]].maps[MATERIAL_MAP_DIFFUSE].color = colorTint; + DrawMesh(model->meshes[i], model->materials[model->meshMaterial[i]], model->transform); + model->materials[model->meshMaterial[i]].maps[MATERIAL_MAP_DIFFUSE].color = color; + } +} + // Draw a model wires (with texture if set) void DrawModelWires(Model model, Vector3 position, float scale, Color tint) {