Review transforms to match OpenGL 1.1

This commit is contained in:
raysan5 2017-08-04 18:34:51 +02:00
parent 1f310f7d4b
commit eeca607506
5 changed files with 100 additions and 100 deletions

View file

@ -912,8 +912,6 @@ void End3dMode(void)
rlMatrixMode(RL_MODELVIEW); // Get back to modelview matrix rlMatrixMode(RL_MODELVIEW); // Get back to modelview matrix
rlLoadIdentity(); // Reset current matrix (MODELVIEW) rlLoadIdentity(); // Reset current matrix (MODELVIEW)
//rlTranslatef(0.375, 0.375, 0); // HACK to ensure pixel-perfect drawing on OpenGL (after exiting 3D mode)
rlDisableDepthTest(); // Disable DEPTH_TEST for 2D rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
} }

View file

@ -118,16 +118,15 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
float z = 0.0f; float z = 0.0f;
rlPushMatrix(); rlPushMatrix();
// NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
// NOTE: Be careful! Function order matters (scale -> rotate -> translate)
//rlScalef(1.0f, 3.0f, 1.0f);
//rlRotatef(45, 0, 1, 0);
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
//rlRotatef(45, 0, 1, 0);
//rlScalef(1.0f, 1.0f, 1.0f); // NOTE: Vertices are directly scaled on definition
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
// Front Face ----------------------------------------------------- // Front face
rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
@ -136,7 +135,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
// Back Face ------------------------------------------------------ // Back face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
@ -145,7 +144,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
// Top Face ------------------------------------------------------- // Top face
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left
rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right
@ -154,7 +153,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right
// Bottom Face ---------------------------------------------------- // Bottom face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left
@ -163,7 +162,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right
rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Left
// Right face ----------------------------------------------------- // Right face
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right
rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left
@ -172,7 +171,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c
rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left
// Left Face ------------------------------------------------------ // Left face
rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right
rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left
rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right
@ -198,8 +197,6 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co
float z = 0.0f; float z = 0.0f;
rlPushMatrix(); rlPushMatrix();
//rlRotatef(45, 0, 1, 0);
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
rlBegin(RL_LINES); rlBegin(RL_LINES);
@ -271,10 +268,10 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei
rlEnableTexture(texture.id); rlEnableTexture(texture.id);
//rlPushMatrix(); //rlPushMatrix();
// NOTE: Be careful! Function order matters (scale -> rotate -> translate) // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
//rlScalef(2.0f, 2.0f, 2.0f);
//rlRotatef(45, 0, 1, 0);
//rlTranslatef(2.0f, 0.0f, 0.0f); //rlTranslatef(2.0f, 0.0f, 0.0f);
//rlRotatef(45, 0, 1, 0);
//rlScalef(2.0f, 2.0f, 2.0f);
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -330,8 +327,9 @@ void DrawSphere(Vector3 centerPos, float radius, Color color)
void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color) void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color)
{ {
rlPushMatrix(); rlPushMatrix();
rlScalef(radius, radius, radius); // NOTE: Transformation is applied in inverse order (scale -> translate)
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
rlScalef(radius, radius, radius);
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -369,8 +367,9 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color) void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color)
{ {
rlPushMatrix(); rlPushMatrix();
rlScalef(radius, radius, radius); // NOTE: Transformation is applied in inverse order (scale -> translate)
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
rlScalef(radius, radius, radius);
rlBegin(RL_LINES); rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -496,8 +495,8 @@ void DrawPlane(Vector3 centerPos, Vector2 size, Color color)
{ {
// NOTE: Plane is always created on XZ ground // NOTE: Plane is always created on XZ ground
rlPushMatrix(); rlPushMatrix();
rlScalef(size.x, 1.0f, size.y);
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
rlScalef(size.x, 1.0f, size.y);
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -567,8 +566,8 @@ void DrawGizmo(Vector3 position)
float length = 1.0f; float length = 1.0f;
rlPushMatrix(); rlPushMatrix();
rlScalef(length, length, length);
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
rlScalef(length, length, length);
rlBegin(RL_LINES); rlBegin(RL_LINES);
rlColor3f(1.0f, 0.0f, 0.0f); rlVertex3f(0.0f, 0.0f, 0.0f); rlColor3f(1.0f, 0.0f, 0.0f); rlVertex3f(0.0f, 0.0f, 0.0f);

View file

@ -446,7 +446,8 @@ void rlTranslatef(float x, float y, float z)
{ {
Matrix matTranslation = MatrixTranslate(x, y, z); Matrix matTranslation = MatrixTranslate(x, y, z);
*currentMatrix = MatrixMultiply(*currentMatrix, matTranslation); // NOTE: We transpose matrix with multiplication order
*currentMatrix = MatrixMultiply(matTranslation, *currentMatrix);
} }
// Multiply the current matrix by a rotation matrix // Multiply the current matrix by a rotation matrix
@ -458,7 +459,8 @@ void rlRotatef(float angleDeg, float x, float y, float z)
Vector3Normalize(&axis); Vector3Normalize(&axis);
matRotation = MatrixRotate(axis, angleDeg*DEG2RAD); matRotation = MatrixRotate(axis, angleDeg*DEG2RAD);
*currentMatrix = MatrixMultiply(*currentMatrix, matRotation); // NOTE: We transpose matrix with multiplication order
*currentMatrix = MatrixMultiply(matRotation, *currentMatrix);
} }
// Multiply the current matrix by a scaling matrix // Multiply the current matrix by a scaling matrix
@ -466,7 +468,8 @@ void rlScalef(float x, float y, float z)
{ {
Matrix matScale = MatrixScale(x, y, z); Matrix matScale = MatrixScale(x, y, z);
*currentMatrix = MatrixMultiply(*currentMatrix, matScale); // NOTE: We transpose matrix with multiplication order
*currentMatrix = MatrixMultiply(matScale, *currentMatrix);
} }
// Multiply the current matrix by another matrix // Multiply the current matrix by another matrix

View file

@ -123,7 +123,7 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
rlPushMatrix(); rlPushMatrix();
rlTranslatef((float)startPos.x, (float)startPos.y, 0); rlTranslatef((float)startPos.x, (float)startPos.y, 0);
rlRotatef(-RAD2DEG*angle, 0, 0, 1); rlRotatef(RAD2DEG*angle, 0, 0, 1);
rlTranslatef(0, -thick/2.0f, 0); rlTranslatef(0, -thick/2.0f, 0);
rlBegin(RL_QUADS); rlBegin(RL_QUADS);

View file

@ -1800,9 +1800,9 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
rlEnableTexture(texture.id); rlEnableTexture(texture.id);
rlPushMatrix(); rlPushMatrix();
rlTranslatef(-origin.x, -origin.y, 0);
rlRotatef(rotation, 0, 0, 1);
rlTranslatef((float)destRec.x, (float)destRec.y, 0); rlTranslatef((float)destRec.x, (float)destRec.y, 0);
rlRotatef(rotation, 0, 0, 1);
rlTranslatef(-origin.x, -origin.y, 0);
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlColor4ub(tint.r, tint.g, tint.b, tint.a);