Project

General

Profile

« Previous | Next » 

Revision fa640198

Added by Leszek Koltunski about 3 years ago

Add to MeshPolygon a special modee to create a 2-band polygon with dense corners (needed to reduce number of vertices in side faces of the TwisttyPuzzle cubits)

View differences:

src/main/java/org/distorted/library/mesh/MeshPolygon.java
45 45

  
46 46
  private void computeNumberOfVertices()
47 47
     {
48
     numVertices = (mNumPolygonVertices*mNumPolygonBands+2)*(mNumPolygonBands-1) - 1;
49
     numVertices+= 2*mNumPolygonVertices*(2*extraIndex*extraVertices);
48
     if( mNumPolygonBands==2 && extraIndex>0 )
49
       {
50
       numVertices = 1 + 2*mNumPolygonVertices*(1+extraIndex+2*extraVertices);
51
       }
52
     else
53
       {
54
       numVertices = (mNumPolygonVertices*mNumPolygonBands+2)*(mNumPolygonBands-1) - 1;
55
       numVertices+= 2*mNumPolygonVertices*(2*extraIndex*extraVertices);
56
       }
50 57

  
51 58
     remainingVert = numVertices;
52 59
     }
......
68 75
      }
69 76
    }
70 77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  private float getSpecialQuot(int index)
81
    {
82
    int num = 1 + extraIndex + 2*extraVertices;
83
    int change1 = extraVertices+1;
84
    int change2 = num-change1;
85
    float quot = 1.0f/(extraIndex+1);
86

  
87
    if( index<change1 )      return index*quot/change1;
88
    else if( index>change2 ) return 1-quot + (index-change2)*quot/change1;
89
    else                     return (index-change1+1)*quot;
90
    }
91

  
71 92
///////////////////////////////////////////////////////////////////////////////////////////////////
72 93

  
73 94
  private float getQuot(int index, int band, boolean isExtra)
......
164 185
        }
165 186
      }
166 187

  
167
    int numPairs = mNumPolygonBands-1-polyBand;
188
    boolean specialCase = mNumPolygonBands==2 && polyBand==0 && extraIndex>0;
168 189
    boolean isExtra = polyBand<extraIndex;
169

  
170
    if( isExtra )
171
      {
172
      numPairs += 2*extraVertices;
173
      }
190
    int numPairs = specialCase ? extraIndex+1 : mNumPolygonBands-1-polyBand;
191
    if( isExtra ) numPairs += 2*extraVertices;
174 192

  
175 193
    int polyEndVer = polyVertex==mNumPolygonVertices-1 ? 0 : polyVertex+1;
176 194
    float quot1, quot2;
177 195

  
178 196
    for(int index=0; index<numPairs; index++)
179 197
      {
180
      quot1 = getQuot(index  ,polyBand+1, isExtra);
181
      quot2 = getQuot(index+1,polyBand  , isExtra);
198
      if( specialCase )
199
        {
200
        quot1 = 1.0f;
201
        quot2 = getSpecialQuot(index+1);
202
        }
203
      else
204
        {
205
        quot1 = getQuot(index  ,polyBand+1, isExtra);
206
        quot2 = getQuot(index+1,polyBand  , isExtra);
207
        }
182 208

  
183 209
      vertex = addVertex(vertex,polyBand+1,polyVertex,polyEndVer,quot1,attribs1,attribs2);
184 210
      vertex = addVertex(vertex,polyBand  ,polyVertex,polyEndVer,quot2,attribs1,attribs2);

Also available in: Unified diff