aboutsummaryrefslogtreecommitdiff
path: root/src/rlgl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rlgl.c')
-rw-r--r--src/rlgl.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/rlgl.c b/src/rlgl.c
index 4531f2d8..c44372f5 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -1500,28 +1500,34 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
glUseProgram(model.shader.id);
-
- // Apply transformation provided in model.transform matrix
- // TODO: review if at this point the modelview matrix just contains view matrix values
- Matrix viewworld = modelview; // Store view matrix before applying model transformations
- Matrix modelviewworld = MatrixMultiply(model.transform, modelview); // World-space transformation
-
- // Apply transformations provided in function
+
+ // At this point the modelview matrix just contains the view matrix (camera)
+ // That's because Begin3dMode() sets it an no model-drawing function modifies it, all use rlPushMatrix() and rlPopMatrix()
+ Matrix matView = modelview; // View matrix (camera)
+ Matrix matProjection = projection; // Projection matrix (perspective)
+
+ // Calculate transformation matrix from function parameters
// Get transform matrix (rotation -> scale -> translation)
- Matrix rotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis);
+ Matrix matRotation = MatrixRotate(rotationAngle*DEG2RAD, rotationAxis);
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
- Matrix translation = MatrixTranslate(position.x, position.y, position.z);
-
- Matrix transform = MatrixMultiply(MatrixMultiply(rotation, matScale), translation); // Object-space transformation matrix
- modelviewworld = MatrixMultiply(transform, modelview); // World-space transformation
+ Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
+ Matrix matTransform = MatrixMultiply(MatrixMultiply(matRotation, matScale), matTranslation);
+
+ // Combine model internal transformation matrix (model.transform) with matrix generated by function parameters (matTransform)
+ Matrix matModel = MatrixMultiply(model.transform, matTransform); // Transform to world-space coordinates
+
+ // Calculate model-view matrix combining matModel and matView
+ Matrix matModelView = MatrixMultiply(matModel, matView); // Transform to camera-space coordinates
- // Projection: Screen-space transformation
+ // Calculate model-view-projection matrix (MVP)
+ //Matrix matMVP = MatrixMultiply(matModelView, matProjection); // Transform to screen-space coordinates
- // NOTE: Drawing in OpenGL 3.3+, transform is passed to shader
- glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(projection));
- glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(transform));
- glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(viewworld));
- glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(modelviewworld));
+ // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
+ // TODO: Reduce number of matrices passed to shaders, use only matMVP
+ glUniformMatrix4fv(model.shader.modelLoc, 1, false, GetMatrixVector(matModel));
+ glUniformMatrix4fv(model.shader.viewLoc, 1, false, GetMatrixVector(matView));
+ glUniformMatrix4fv(model.shader.projectionLoc, 1, false, GetMatrixVector(matProjection));
+ glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, GetMatrixVector(matModelView));
// Apply color tinting to model
// NOTE: Just update one uniform on fragment shader