OSDN Git Service

Fixed up PolygonSprite.
authorNathanSweet <nathan.sweet@gmail.com>
Wed, 11 Sep 2013 14:35:22 +0000 (16:35 +0200)
committerNathanSweet <nathan.sweet@gmail.com>
Wed, 11 Sep 2013 14:35:22 +0000 (16:35 +0200)
gdx/src/com/badlogic/gdx/graphics/g2d/PolygonSprite.java
gdx/src/com/badlogic/gdx/graphics/g2d/PolygonSpriteBatch.java

index d2eee3b..3bb7216 100644 (file)
@@ -159,7 +159,7 @@ public class PolygonSprite {
                float color = NumberUtils.intToFloatColor(intBits);\r
                final float[] vertices = this.vertices;\r
                for (int i = 2; i < vertices.length; i += Sprite.VERTEX_SIZE)\r
-                       vertices[i + 2] = color;\r
+                       vertices[i] = color;\r
        }\r
 \r
        /** Sets the origin in relation to the sprite's position for scaling and rotation. */\r
@@ -201,31 +201,30 @@ public class PolygonSprite {
 \r
        /** Returns the packed vertices, colors, and texture coordinates for this sprite. */\r
        public float[] getVertices () {\r
-               if (dirty) {\r
-                       dirty = false;\r
-\r
-                       final float originX = this.originX;\r
-                       final float originY = this.originY;\r
-                       final float scaleX = this.scaleX;\r
-                       final float scaleY = this.scaleY;\r
-                       final PolygonRegion region = this.region;\r
-                       final float[] vertices = this.vertices;\r
-                       final float[] regionVertices = region.vertices;\r
-\r
-                       final float worldOriginX = x + originX;\r
-                       final float worldOriginY = y + originY;\r
-                       final float sX = width / region.region.getRegionWidth();\r
-                       final float sY = height / region.region.getRegionHeight();\r
-                       final float cos = MathUtils.cosDeg(rotation);\r
-                       final float sin = MathUtils.sinDeg(rotation);\r
-\r
-                       float fx, fy;\r
-                       for (int i = 0, v = 0, n = regionVertices.length; i < n; i += 2, v += 5) {\r
-                               fx = (regionVertices[i] * sX - originX) * scaleX;\r
-                               fy = (regionVertices[i + 1] * sY - originY) * scaleY;\r
-                               vertices[v] = cos * fx - sin * fy + worldOriginX;\r
-                               vertices[v + 1] = sin * fx + cos * fy + worldOriginY;\r
-                       }\r
+               if (!dirty) return vertices;\r
+               dirty = false;\r
+\r
+               final float originX = this.originX;\r
+               final float originY = this.originY;\r
+               final float scaleX = this.scaleX;\r
+               final float scaleY = this.scaleY;\r
+               final PolygonRegion region = this.region;\r
+               final float[] vertices = this.vertices;\r
+               final float[] regionVertices = region.vertices;\r
+\r
+               final float worldOriginX = x + originX;\r
+               final float worldOriginY = y + originY;\r
+               final float sX = width / region.region.getRegionWidth();\r
+               final float sY = height / region.region.getRegionHeight();\r
+               final float cos = MathUtils.cosDeg(rotation);\r
+               final float sin = MathUtils.sinDeg(rotation);\r
+\r
+               float fx, fy;\r
+               for (int i = 0, v = 0, n = regionVertices.length; i < n; i += 2, v += 5) {\r
+                       fx = (regionVertices[i] * sX - originX) * scaleX;\r
+                       fy = (regionVertices[i + 1] * sY - originY) * scaleY;\r
+                       vertices[v] = cos * fx - sin * fy + worldOriginX;\r
+                       vertices[v + 1] = sin * fx + cos * fy + worldOriginY;\r
                }\r
                return vertices;\r
        }\r
@@ -243,10 +242,12 @@ public class PolygonSprite {
                float maxy = vertices[1];\r
 \r
                for (int i = 5; i < vertices.length; i += 5) {\r
-                       minx = minx > vertices[i] ? vertices[i] : minx;\r
-                       maxx = maxx < vertices[i] ? vertices[i] : maxx;\r
-                       miny = miny > vertices[i + 1] ? vertices[i + 1] : miny;\r
-                       maxy = maxy < vertices[i + 1] ? vertices[i + 1] : maxy;\r
+                       float x = vertices[i];\r
+                       float y = vertices[i + 1];\r
+                       minx = minx > x ? x : minx;\r
+                       maxx = maxx < x ? x : maxx;\r
+                       miny = miny > y ? y : miny;\r
+                       maxy = maxy < y ? y : maxy;\r
                }\r
 \r
                bounds.x = minx;\r
@@ -329,7 +330,7 @@ public class PolygonSprite {
 \r
                // Set the color and UVs in this sprite's vertices.\r
                float[] vertices = this.vertices;\r
-               for (int i = 2, v = 0, n = regionVertices.length; i < n; i += 2, v += 5) {\r
+               for (int i = 0, v = 2, n = regionVertices.length; i < n; i += 2, v += 5) {\r
                        vertices[v] = color.toFloatBits();\r
                        vertices[v + 1] = textureCoords[i];\r
                        vertices[v + 2] = textureCoords[i + 1];\r
index d53ac18..6d6c7b0 100644 (file)
@@ -107,7 +107,7 @@ public class PolygonSpriteBatch {
        public int totalRenderCalls = 0;\r
 \r
        /** the maximum number of sprites rendered in one batch so far **/\r
-       public int maxVerticesInBatch = 0;\r
+       public int maxTrianglesInBatch = 0;\r
 \r
        /** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards,\r
         * x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect\r
@@ -464,8 +464,8 @@ public class PolygonSpriteBatch {
 \r
                renderCalls++;\r
                totalRenderCalls++;\r
-               int verticesInBatch = triangleIndex;\r
-               if (verticesInBatch > maxVerticesInBatch) maxVerticesInBatch = verticesInBatch;\r
+               int trianglesInBatch = triangleIndex;\r
+               if (trianglesInBatch > maxTrianglesInBatch) maxTrianglesInBatch = trianglesInBatch;\r
 \r
                lastTexture.bind();\r
                Mesh mesh = this.mesh;\r
@@ -480,9 +480,9 @@ public class PolygonSpriteBatch {
                }\r
 \r
                if (Gdx.graphics.isGL20Available())\r
-                       mesh.render(customShader != null ? customShader : shader, GL10.GL_TRIANGLES, 0, verticesInBatch);\r
+                       mesh.render(customShader != null ? customShader : shader, GL10.GL_TRIANGLES, 0, trianglesInBatch);\r
                else\r
-                       mesh.render(GL10.GL_TRIANGLES, 0, verticesInBatch);\r
+                       mesh.render(GL10.GL_TRIANGLES, 0, trianglesInBatch);\r
 \r
                vertexIndex = 0;\r
                triangleIndex = 0;\r