Browse Source

REVIEWED: DrawCubeTextureRec() formatting

raysan5 4 years ago
parent
commit
4a1bd12e2d
1 changed files with 122 additions and 186 deletions
  1. 122 186
      src/rmodels.c

+ 122 - 186
src/rmodels.c

@@ -341,57 +341,57 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co
         rlBegin(RL_LINES);
         rlBegin(RL_LINES);
             rlColor4ub(color.r, color.g, color.b, color.a);
             rlColor4ub(color.r, color.g, color.b, color.a);
 
 
-            // Front Face -----------------------------------------------------
-            // Bottom Line
-            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Bottom Left
-            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Bottom Right
-
-            // Left Line
-            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Bottom Right
-            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top Right
-
-            // Top Line
-            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top Right
-            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top Left
-
-            // Right Line
-            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top Left
-            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Bottom Left
-
-            // Back Face ------------------------------------------------------
-            // Bottom Line
-            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Bottom Left
-            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Bottom Right
-
-            // Left Line
-            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Bottom Right
-            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top Right
-
-            // Top Line
-            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top Right
-            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top Left
-
-            // Right Line
-            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top Left
-            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Bottom Left
-
-            // Top Face -------------------------------------------------------
-            // Left Line
-            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top Left Front
-            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top Left Back
-
-            // Right Line
-            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top Right Front
-            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top Right Back
-
-            // Bottom Face  ---------------------------------------------------
-            // Left Line
-            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Top Left Front
-            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Top Left Back
-
-            // Right Line
-            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Top Right Front
-            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Top Right Back
+            // Front face -----------------------------------------------------
+            // Bottom line
+            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Bottom left
+            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Bottom right
+
+            // Left line
+            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Bottom right
+            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top right
+
+            // Top line
+            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top right
+            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top left
+
+            // Right line
+            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top left
+            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Bottom left
+
+            // Back face ------------------------------------------------------
+            // Bottom line
+            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Bottom left
+            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Bottom right
+
+            // Left line
+            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Bottom right
+            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top right
+
+            // Top line
+            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top right
+            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top left
+
+            // Right line
+            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top left
+            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Bottom left
+
+            // Top face -------------------------------------------------------
+            // Left line
+            rlVertex3f(x-width/2, y+height/2, z+length/2);  // Top left front
+            rlVertex3f(x-width/2, y+height/2, z-length/2);  // Top left back
+
+            // Right line
+            rlVertex3f(x+width/2, y+height/2, z+length/2);  // Top right front
+            rlVertex3f(x+width/2, y+height/2, z-length/2);  // Top right back
+
+            // Bottom face  ---------------------------------------------------
+            // Left line
+            rlVertex3f(x-width/2, y-height/2, z+length/2);  // Top left front
+            rlVertex3f(x-width/2, y-height/2, z-length/2);  // Top left back
+
+            // Right line
+            rlVertex3f(x+width/2, y-height/2, z+length/2);  // Top right front
+            rlVertex3f(x+width/2, y-height/2, z-length/2);  // Top right back
         rlEnd();
         rlEnd();
     rlPopMatrix();
     rlPopMatrix();
 }
 }
@@ -464,153 +464,89 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei
     rlSetTexture(0);
     rlSetTexture(0);
 }
 }
 
 
+// Draw cube with texture piece applied to all faces
 void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
 void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color)
 {
 {
     float x = position.x;
     float x = position.x;
     float y = position.y;
     float y = position.y;
     float z = position.z;
     float z = position.z;
-    float texture_width  = (float)texture.width;
-    float texture_height = (float)texture.height;
+    float texWidth = (float)texture.width;
+    float texHeight = (float)texture.height;
 
 
     rlCheckRenderBatchLimit(36);
     rlCheckRenderBatchLimit(36);
 
 
     rlSetTexture(texture.id);
     rlSetTexture(texture.id);
 
 
-        rlBegin(RL_QUADS);
-            rlColor4ub(color.r, color.g, color.b, color.a);
-
-            // Front Face
-            {
-                // Normal Pointing Towards Viewer
-                rlNormal3f(0.0f, 0.0f, 1.0f);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z + length/2);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z + length/2);
-
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z + length/2);
-
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z + length/2);
-            }
-
-            // Back Face
-            {
-                // Normal Pointing Away From Viewer
-                rlNormal3f(0.0f, 0.0f, - 1.0f);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z - length/2);
-
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z - length/2);
-
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z - length/2);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z - length/2);
-            }
-
-            // Top Face
-            {
-                // Normal Pointing Up
-                rlNormal3f(0.0f, 1.0f, 0.0f);
-
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z - length/2);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z + length/2);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z + length/2);
-
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z - length/2);
-            }
-
-            // Bottom Face
-            {
-                // Normal Pointing Down
-                rlNormal3f(0.0f, - 1.0f, 0.0f);
-
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z - length/2);
-
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z - length/2);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z + length/2);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z + length/2);
-            }
-
-            // Right face
-            {
-                // Normal Pointing Right
-                rlNormal3f(1.0f, 0.0f, 0.0f);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z - length/2);
-
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z - length/2);
-
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x + width/2, y + height/2, z + length/2);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x + width/2, y - height/2, z + length/2);
-            }
-
-            // Left Face
-            {
-                // Normal Pointing Left
-                rlNormal3f( - 1.0f, 0.0f, 0.0f);
-
-                // Bottom Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z - length/2);
-
-                // Bottom Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, (source.y + source.height) / texture_height);
-                rlVertex3f(x - width/2, y - height/2, z + length/2);
+    rlBegin(RL_QUADS);
+        rlColor4ub(color.r, color.g, color.b, color.a);
 
 
-                // Top Right Of The Texture and Quad
-                rlTexCoord2f((source.x + source.width) / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z + length/2);
+        // Front face
+        rlNormal3f(0.0f, 0.0f, 1.0f);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z + length/2);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z + length/2);
+
+        // Back face
+        rlNormal3f(0.0f, 0.0f, - 1.0f);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z - length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z - length/2);
+
+        // Top face
+        rlNormal3f(0.0f, 1.0f, 0.0f);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z - length/2);
+
+        // Bottom face
+        rlNormal3f(0.0f, - 1.0f, 0.0f);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z + length/2);
+
+        // Right face
+        rlNormal3f(1.0f, 0.0f, 0.0f);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z - length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z - length/2);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x + width/2, y + height/2, z + length/2);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x + width/2, y - height/2, z + length/2);
+
+        // Left face
+        rlNormal3f( - 1.0f, 0.0f, 0.0f);
+        rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z - length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight);
+        rlVertex3f(x - width/2, y - height/2, z + length/2);
+        rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z + length/2);
+        rlTexCoord2f(source.x/texWidth, source.y/texHeight);
+        rlVertex3f(x - width/2, y + height/2, z - length/2);
 
 
-                // Top Left Of The Texture and Quad
-                rlTexCoord2f(source.x / texture_width, source.y / texture_height);
-                rlVertex3f(x - width/2, y + height/2, z - length/2);
-            }
-        rlEnd();
+    rlEnd();
 
 
     rlSetTexture(0);
     rlSetTexture(0);
 }
 }