OSDN Git Service

Small changes to MeshBuilder
authorXoppa <contact@xoppa.nl>
Fri, 11 Oct 2013 21:58:29 +0000 (23:58 +0200)
committerXoppa <contact@xoppa.nl>
Fri, 11 Oct 2013 21:58:29 +0000 (23:58 +0200)
gdx/src/com/badlogic/gdx/graphics/g3d/utils/MeshBuilder.java
gdx/src/com/badlogic/gdx/graphics/g3d/utils/MeshPartBuilder.java

index 468e4c8..23f5a63 100644 (file)
@@ -648,74 +648,107 @@ public class MeshBuilder implements MeshPartBuilder {
        }
        
        @Override
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions) {
-               circle(radius, centerX, centerY, centerZ, normalX, normalY, normalZ, divisions, 0, 360);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ) {
+               circle(radius, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, 0f, 360f);
        }
 
        @Override
-       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions) {
-               circle(radius, center.x, center.y, center.z, normal.x, normal.y, normal.z, divisions);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal) {
+               circle(radius, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z);
        }
 
        @Override
-       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions) {
-               circle(radius, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z, divisions);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal) {
+               circle(radius, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z);
        }
        
        @Override
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions) {
-               circle(radius, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, divisions, 0, 360);         
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ) {
+               circle(radius, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, 0f, 360f);               
        }
        
        @Override
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo) {
-               tempV1.set(normalX, normalY, normalZ).crs(0, 0, 1);
-               tempV2.set(normalX, normalY, normalZ).crs(0, 1, 0);
-               if (tempV2.len2() > tempV1.len2())
-                       tempV1.set(tempV2);
-               tempV2.set(tempV1.nor()).crs(normalX, normalY, normalZ).nor();
-               circle(radius, centerX, centerY, centerZ, normalX, normalY, normalZ, tempV1.x, tempV1.y, tempV1.z, tempV2.x, tempV2.y, tempV2.z, divisions, angleFrom, angleTo);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo) {
+               ellipse(radius * 2f, radius * 2f, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, angleFrom, angleTo);
        }
 
        @Override
-       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo) {
-               circle(radius, center.x, center.y, center.z, normal.x, normal.y, normal.z, divisions, angleFrom, angleTo);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, float angleFrom, float angleTo) {
+               circle(radius, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, angleFrom, angleTo);
        }
        
        @Override
-       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo) {
-               circle(radius, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z, divisions, angleFrom, angleTo);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, float angleFrom, float angleTo) {
+               circle(radius, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z, angleFrom, angleTo);
        }
 
        @Override
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo) {
-               
-               ellipse(radius*2, radius*2, 0, 0, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, divisions, angleFrom, angleTo);
-       }
-       
-       @Override
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, Vector3 center, Vector3 normal, int divisions) {
-               ellipse(width, height, innerWidth, innerHeight, center.x, center.y, center.z, normal.x, normal.y, normal.z, divisions, 0, 360);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo) {
+               ellipse(radius*2, radius*2, 0, 0, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, angleFrom, angleTo);
+       }\r
+       \r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ) {\r
+               ellipse(width, height, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, 0f, 360f);\r
+       }\r
+\r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal) {\r
+               ellipse(width, height, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z);\r
+       }\r
+\r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal) {\r
+               ellipse(width, height, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z);\r
+       }\r
+       \r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ) {\r
+               ellipse(width, height, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, 0f, 360f);               \r
+       }\r
+       \r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo) {\r
+               ellipse(width, height, 0f, 0f, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, angleFrom, angleTo);\r
+       }\r
+\r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, float angleFrom, float angleTo) {\r
+               ellipse(width, height, 0f, 0f, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, angleFrom, angleTo);\r
+       }\r
+       \r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, float angleFrom, float angleTo) {\r
+               ellipse(width, height, 0f, 0f, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, tangent.x, tangent.y, tangent.z, binormal.x, binormal.y, binormal.z, angleFrom, angleTo);\r
+       }\r
+\r
+       @Override\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo) {\r
+               ellipse(width, height, 0f, 0f, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, angleFrom, angleTo);\r
+       }\r
+       
+       @Override
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, Vector3 center, Vector3 normal) {
+               ellipse(width, height, innerWidth, innerHeight, divisions, center.x, center.y, center.z, normal.x, normal.y, normal.z, 0f, 360f);
        }
 
        @Override
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions) {
-               ellipse(width, height, innerWidth, innerHeight, centerX, centerY, centerZ, normalX, normalY, normalZ, divisions, 0, 360);
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ) {
+               ellipse(width, height, innerWidth, innerHeight, divisions, centerX, centerY, centerZ, normalX, normalY, normalZ, 0f, 360f);
        }
                
        @Override
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo) {
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo) {\r
                tempV1.set(normalX, normalY, normalZ).crs(0, 0, 1);
                tempV2.set(normalX, normalY, normalZ).crs(0, 1, 0);
                if (tempV2.len2() > tempV1.len2())
                        tempV1.set(tempV2);
                tempV2.set(tempV1.nor()).crs(normalX, normalY, normalZ).nor();
-               ellipse(width, height, innerWidth, innerHeight, centerX, centerY, centerZ, normalX, normalY, normalZ,  tempV1.x, tempV1.y, tempV1.z, tempV2.x, tempV2.y, tempV2.z, divisions, angleFrom, angleTo);
+               ellipse(width, height, innerWidth, innerHeight, divisions, centerX, centerY, centerZ, normalX, normalY,  normalZ, tempV1.x, tempV1.y, tempV1.z, tempV2.x, tempV2.y, tempV2.z, angleFrom, angleTo);
        }
        
        @Override
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo) {
-       
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo) {
                if(innerWidth <= 0 || innerHeight <= 0) {                                       
                        ensureTriangles(divisions + 2, divisions);
                }
@@ -736,19 +769,19 @@ public class MeshBuilder implements MeshPartBuilder {
                final Vector3 sxIn = tempV3.set(tangentX, tangentY, tangentZ).scl(innerWidth * 0.5f);
                final Vector3 syIn = tempV4.set(binormalX, binormalY, binormalZ).scl(innerHeight * 0.5f);
                VertexInfo currIn = vertTmp3.set(null, null, null, null);
-               currIn.hasUV = true;
-               currIn.uv.set(.5f, .5f);                
-               currIn.hasPosition = currIn.hasNormal = true;
+               currIn.hasUV = currIn.hasPosition = currIn.hasNormal = true;\r
+               currIn.uv.set(.5f, .5f);
                currIn.position.set(centerX, centerY, centerZ);
                currIn.normal.set(normalX, normalY, normalZ);   
                VertexInfo currEx = vertTmp4.set(null, null, null, null);
-               currEx.hasUV = true;
-               currEx.uv.set(.5f, .5f);                
-               currEx.hasPosition = currEx.hasNormal = true;
+               currEx.hasUV = currEx.hasPosition = currEx.hasNormal = true;\r
+               currEx.uv.set(.5f, .5f);
                currEx.position.set(centerX, centerY, centerZ);
                currEx.normal.set(normalX, normalY, normalZ);
                final short center = vertex(currEx);
-               float angle = 0f;
+               float angle = 0f;\r
+               final float us = 0.5f * (innerWidth / width);\r
+               final float vs = 0.5f * (innerHeight / height);
                for (int i = 0; i <= divisions; i++) {
                        angle = ao + step * i;
                        final float x = MathUtils.cos(angle);
@@ -757,7 +790,7 @@ public class MeshBuilder implements MeshPartBuilder {
                        currEx.uv.set(.5f + .5f * x, .5f + .5f * y);                            
                        vertex(currEx);
                        
-                       if(innerWidth <= 0 || innerHeight <= 0) {                                       
+                       if(innerWidth <= 0f || innerHeight <= 0f)       {                                       
                                if (i != 0)
                                        triangle((short)(vindex - 1), (short)(vindex - 2), center);
                        }
@@ -767,7 +800,7 @@ public class MeshBuilder implements MeshPartBuilder {
                        }
                        else {
                                currIn.position.set(centerX, centerY, centerZ).add(sxIn.x*x+syIn.x*y, sxIn.y*x+syIn.y*y, sxIn.z*x+syIn.z*y);
-                               currIn.uv.set(.5f + .5f * x, .5f + .5f * y);                            
+                               currIn.uv.set(.5f + us * x, .5f + vs * y);                              
                                vertex(currIn);
                                
                                if( i != 0)
@@ -820,8 +853,8 @@ public class MeshBuilder implements MeshPartBuilder {
                                rect((short)(vindex-3), (short)(vindex-1), (short)(vindex-2), (short)(vindex-4)); // FIXME don't duplicate lines and points
                }
                if (close) {
-                       ellipse(width, depth, 0, 0, 0, hh, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, divisions, angleFrom, angleTo);
-                       ellipse(width, depth, 0, 0, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, divisions, 180f-angleTo, 180f-angleFrom);
+                       ellipse(width, depth, 0, 0, divisions, 0, hh, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, angleFrom, angleTo);
+                       ellipse(width, depth, 0, 0, divisions, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 180f-angleTo, 180f-angleFrom);
                }
        }
        
@@ -859,7 +892,7 @@ public class MeshBuilder implements MeshPartBuilder {
                                continue;
                        triangle((short)base, (short)(vindex-1), (short)(vindex-2)); // FIXME don't duplicate lines and points
                }
-               ellipse(width, depth, 0, 0, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, divisions, 180f-angleTo, 180f-angleFrom);
+               ellipse(width, depth, 0, 0, divisions, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 180f-angleTo, 180f-angleFrom);
        }
        
        @Override
index 3fbde86..0dc2859 100644 (file)
@@ -103,50 +103,45 @@ public interface MeshPartBuilder {
        /** Add a box at the specified location, with the specified dimensions */
        public void box(float x, float y, float z, float width, float height, float depth);
        /** Add a circle */
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ);
        /** Add a circle */
-       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal);
        /** Add a circle */
-       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal);
        /** Add a circle */
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ);
        /** Add a circle */
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo);
-       /**
-        * Add an ellipse
-        * @param width external width
-        * @param height external height
-        * @param innerWidth internal width
-        * @param innerHeight internal height
-        * @param centerX center
-        * @param centerY center
-        * @param centerZ center
-        * @param normalX normal
-        * @param normalY normal
-        * @param normalZ normal
-        * @param tangentX
-        * @param tangentY
-        * @param tangentZ
-        * @param binormalX
-        * @param binormalY
-        * @param binormalZ
-        * @param divisions number of subdivisions
-        * @param angleFrom
-        * @param angleTo
-        */
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, float angleFrom, float angleTo);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, float angleFrom, float angleTo);\r
+       /** Add a circle */\r
+       public void ellipse(float width, float height, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo);
        /** Add an ellipse */
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo);
        /** Add an ellipse */
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float angleFrom, float angleTo);
        /** Add an ellipse */
-       public void ellipse(float width, float height, float innerWidth, float innerHeight, Vector3 center, Vector3 normal, int divisions);
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ);
+       /** Add an ellipse */
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, int divisions, Vector3 center, Vector3 normal);
        /** Add a cylinder */
        public void cylinder(float width, float height, float depth, int divisions);
        /** Add a cylinder */