OSDN Git Service

Merge pull request #817 from VinceAngel/master
authorXoppa <contact@xoppa.nl>
Fri, 11 Oct 2013 20:22:06 +0000 (13:22 -0700)
committerXoppa <contact@xoppa.nl>
Fri, 11 Oct 2013 20:22:06 +0000 (13:22 -0700)
Added a void circle builder (circleLine) to create a simple circle line

1  2 
gdx/src/com/badlogic/gdx/graphics/g3d/utils/MeshBuilder.java
gdx/src/com/badlogic/gdx/graphics/g3d/utils/MeshPartBuilder.java

@@@ -1,19 -1,3 +1,19 @@@
 +/*******************************************************************************\r
 + * Copyright 2011 See AUTHORS file.\r
 + * \r
 + * Licensed under the Apache License, Version 2.0 (the "License");\r
 + * you may not use this file except in compliance with the License.\r
 + * You may obtain a copy of the License at\r
 + * \r
 + *   http://www.apache.org/licenses/LICENSE-2.0\r
 + * \r
 + * Unless required by applicable law or agreed to in writing, software\r
 + * distributed under the License is distributed on an "AS IS" BASIS,\r
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
 + * See the License for the specific language governing permissions and\r
 + * limitations under the License.\r
 + ******************************************************************************/
 +
  package com.badlogic.gdx.graphics.g3d.utils;
  
  import com.badlogic.gdx.Gdx;
@@@ -648,69 -632,131 +648,131 @@@ public class MeshBuilder implements Mes
        }
        
        @Override
-       public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions) {
-               circle(width, height, centerX, centerY, centerZ, normalX, normalY, normalZ, divisions, 0, 360);
+       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);
        }
  
        @Override
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions) {
-               circle(width, height, center.x, center.y, center.z, normal.x, normal.y, normal.z, divisions);
+       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);
        }
  
        @Override
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions) {
-               circle(width, height, 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, 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);
        }
        
        @Override
-       public void circle(float width, float height, 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(width, height, centerX, centerY, centerZ, normalX, normalY, normalZ, tangentX, tangentY, tangentZ, binormalX, binormalY, binormalZ, divisions, 0, 360);          
+       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);         
        }
        
        @Override
-       public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo) {
+       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(width, height, centerX, centerY, centerZ, normalX, normalY, normalZ, tempV1.x, tempV1.y, tempV1.z, tempV2.x, tempV2.y, tempV2.z, divisions, angleFrom, angleTo);
+               circle(radius, centerX, centerY, centerZ, normalX, normalY, normalZ, tempV1.x, tempV1.y, tempV1.z, tempV2.x, tempV2.y, tempV2.z, divisions, angleFrom, angleTo);
        }
  
        @Override
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo) {
-               circle(width, height, center.x, center.y, center.z, normal.x, normal.y, normal.z, divisions, angleFrom, angleTo);
+       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);
        }
        
        @Override
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo) {
-               circle(width, height, 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, 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);
        }
  
        @Override
-       public void circle(float width, float height, 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) {
-               ensureTriangles(divisions + 2, divisions);
+       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);
+       }
+       @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);
+       }
+               
+       @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) {
+               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);
+       }
+       
+       @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) {
+       
+               if(innerWidth <= 0 || innerHeight <= 0) {                                       
+                       ensureTriangles(divisions + 2, divisions);
+               }
+               else if (innerWidth == width && innerHeight == height){
+                       ensureVertices(divisions + 1);
+                       ensureIndices(divisions + 1);
+                       if(primitiveType != GL10.GL_LINES)
+                               throw new GdxRuntimeException("Incorrect primitive type : expect GL_LINES because innerWidth == width && innerHeight == height");
+               }
+               else {
+                       ensureRectangles((divisions + 1)*2, divisions + 1);
+               }
                
                final float ao = MathUtils.degreesToRadians * angleFrom;
                final float step = (MathUtils.degreesToRadians * (angleTo - angleFrom)) / divisions;
-               final Vector3 sx = tempV1.set(tangentX, tangentY, tangentZ).scl(width * 0.5f);
-               final Vector3 sy = tempV2.set(binormalX, binormalY, binormalZ).scl(height * 0.5f);
-               VertexInfo curr = vertTmp3.set(null, null, null, null);
-               curr.hasUV = curr.hasPosition = curr.hasNormal = true;
-               curr.uv.set(.5f, .5f);
-               curr.position.set(centerX, centerY, centerZ);
-               curr.normal.set(normalX, normalY, normalZ);     
-               final short center = vertex(curr);
+               final Vector3 sxEx = tempV1.set(tangentX, tangentY, tangentZ).scl(width * 0.5f);
+               final Vector3 syEx = tempV2.set(binormalX, binormalY, binormalZ).scl(height * 0.5f);
+               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.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.position.set(centerX, centerY, centerZ);
+               currEx.normal.set(normalX, normalY, normalZ);
+               final short center = vertex(currEx);
                float angle = 0f;
                for (int i = 0; i <= divisions; i++) {
                        angle = ao + step * i;
                        final float x = MathUtils.cos(angle);
                        final float y = MathUtils.sin(angle);
-                       curr.uv.set(.5f + .5f * x, .5f + .5f * y);
-                       curr.position.set(centerX, centerY, centerZ).add(sx.x*x+sy.x*y, sx.y*x+sy.y*y, sx.z*x+sy.z*y);
-                       vertex(curr);
-                       if (i != 0)
-                               triangle((short)(vindex - 1), (short)(vindex - 2), center);
+                       currEx.position.set(centerX, centerY, centerZ).add(sxEx.x*x+syEx.x*y, sxEx.y*x+syEx.y*y, sxEx.z*x+syEx.z*y);
+                       currEx.uv.set(.5f + .5f * x, .5f + .5f * y);                            
+                       vertex(currEx);
+                       
+                       if(innerWidth <= 0 || innerHeight <= 0) {                                       
+                               if (i != 0)
+                                       triangle((short)(vindex - 1), (short)(vindex - 2), center);
+                       }
+                       else if (innerWidth == width && innerHeight == height){
+                               if (i != 0)
+                                       line((short)(vindex - 1), (short)(vindex - 2));
+                       }
+                       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);                            
+                               vertex(currIn);
+                               
+                               if( i != 0)
+                                       rect((short)(vindex - 1), (short)(vindex - 2),(short)(vindex - 4), (short)(vindex - 3));
+                       }
                }
        }
        
                                rect((short)(vindex-3), (short)(vindex-1), (short)(vindex-2), (short)(vindex-4)); // FIXME don't duplicate lines and points
                }
                if (close) {
-                       circle(width, depth, 0, hh, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, divisions, angleFrom, angleTo);
-                       circle(width, depth, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, divisions, 180f-angleTo, 180f-angleFrom);
+                       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);
                }
        }
        
                                continue;
                        triangle((short)base, (short)(vindex-1), (short)(vindex-2)); // FIXME don't duplicate lines and points
                }
-               circle(width, depth, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, divisions, 180f-angleTo, 180f-angleFrom);
+               ellipse(width, depth, 0, 0, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, divisions, 180f-angleTo, 180f-angleFrom);
        }
        
        @Override
@@@ -1,19 -1,3 +1,19 @@@
 +/*******************************************************************************\r
 + * Copyright 2011 See AUTHORS file.\r
 + * \r
 + * Licensed under the Apache License, Version 2.0 (the "License");\r
 + * you may not use this file except in compliance with the License.\r
 + * You may obtain a copy of the License at\r
 + * \r
 + *   http://www.apache.org/licenses/LICENSE-2.0\r
 + * \r
 + * Unless required by applicable law or agreed to in writing, software\r
 + * distributed under the License is distributed on an "AS IS" BASIS,\r
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
 + * See the License for the specific language governing permissions and\r
 + * limitations under the License.\r
 + ******************************************************************************/
 +
  package com.badlogic.gdx.graphics.g3d.utils;
  
  import com.badlogic.gdx.graphics.Color;
@@@ -103,21 -87,50 +103,50 @@@ 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 width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
+       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions);
        /** Add a circle */
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions);
+       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions);
        /** Add a circle */
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions);
+       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions);
        /** Add a circle */
-       public void circle(float width, float height, 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, 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);
        /** Add a circle */
-       public void circle(float width, float height, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, int divisions, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, final Vector3 center, final Vector3 normal, int divisions, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float width, float height, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo);
+       public void circle(float radius, final Vector3 center, final Vector3 normal, final Vector3 tangent, final Vector3 binormal, int divisions, float angleFrom, float angleTo);
        /** Add a circle */
-       public void circle(float width, float height, 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, 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);
+       /** 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);
+       /** 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);
+       /** Add an ellipse */
+       public void ellipse(float width, float height, float innerWidth, float innerHeight, Vector3 center, Vector3 normal, int divisions);
        /** Add a cylinder */
        public void cylinder(float width, float height, float depth, int divisions);
        /** Add a cylinder */