Added DrawModelTfm()

Same as DrawModelEx, but the position/rotation/scale paramters are
supplies just as a transformation matrix.
This commit is contained in:
André Jonsson 2024-08-11 19:56:34 +02:00
parent ee7e1d4a2b
commit 03a8c635eb

View File

@ -3532,19 +3532,11 @@ void DrawModel(Model model, Vector3 position, float scale, Color tint)
DrawModelEx(model, position, rotationAxis, 0.0f, vScale, tint); DrawModelEx(model, position, rotationAxis, 0.0f, vScale, tint);
} }
// Draw a model with extended parameters // Draw a model with transform
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint) void DrawModelTfm(Model model, Matrix transform, Color tint)
{ {
// Calculate transformation matrix from function parameters // Combine model transformation matrix (model.transform) with matrix supplied transform.
// Get transform matrix (rotation -> scale -> translation) model.transform = MatrixMultiply(model.transform, transform);
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
// Combine model transformation matrix (model.transform) with matrix generated by function parameters (matTransform)
model.transform = MatrixMultiply(model.transform, matTransform);
for (int i = 0; i < model.meshCount; i++) for (int i = 0; i < model.meshCount; i++)
{ {
@ -3562,6 +3554,21 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
} }
} }
// Draw a model with extended parameters
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
{
// Calculate transformation matrix from function parameters
// Get transform matrix (rotation -> scale -> translation)
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
// Gnereate transform matrix (matTransform) from function parameters
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
DrawModelTfm(model, matTransform, tint);
}
// Draw a model wires (with texture if set) // Draw a model wires (with texture if set)
void DrawModelWires(Model model, Vector3 position, float scale, Color tint) void DrawModelWires(Model model, Vector3 position, float scale, Color tint)
{ {