Added DrawModelTfm()
Same as DrawModelEx, but the position/rotation/scale paramters are supplies just as a transformation matrix.
This commit is contained in:
parent
ee7e1d4a2b
commit
03a8c635eb
|
|
@ -3532,6 +3532,28 @@ 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 transform
|
||||||
|
void DrawModelTfm(Model model, Matrix transform, Color tint)
|
||||||
|
{
|
||||||
|
// Combine model transformation matrix (model.transform) with matrix supplied transform.
|
||||||
|
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)(((int)color.r*(int)tint.r)/255);
|
||||||
|
colorTint.g = (unsigned char)(((int)color.g*(int)tint.g)/255);
|
||||||
|
colorTint.b = (unsigned char)(((int)color.b*(int)tint.b)/255);
|
||||||
|
colorTint.a = (unsigned char)(((int)color.a*(int)tint.a)/255);
|
||||||
|
|
||||||
|
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 with extended parameters
|
// Draw a model with extended parameters
|
||||||
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint)
|
||||||
{
|
{
|
||||||
|
|
@ -3541,25 +3563,10 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota
|
||||||
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
|
Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD);
|
||||||
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
|
||||||
|
|
||||||
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
// Gnereate transform matrix (matTransform) from function parameters
|
||||||
|
Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation);
|
||||||
|
|
||||||
// Combine model transformation matrix (model.transform) with matrix generated by function parameters (matTransform)
|
DrawModelTfm(model, matTransform, tint);
|
||||||
model.transform = MatrixMultiply(model.transform, matTransform);
|
|
||||||
|
|
||||||
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)(((int)color.r*(int)tint.r)/255);
|
|
||||||
colorTint.g = (unsigned char)(((int)color.g*(int)tint.g)/255);
|
|
||||||
colorTint.b = (unsigned char)(((int)color.b*(int)tint.b)/255);
|
|
||||||
colorTint.a = (unsigned char)(((int)color.a*(int)tint.a)/255);
|
|
||||||
|
|
||||||
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)
|
// Draw a model wires (with texture if set)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user