Project

General

Profile

« Previous | Next » 

Revision c0b37c89

Added by Leszek Koltunski about 4 years ago

Convert RubikCubes to the new MeshPolygon - better quality of the mesh and less vertices!

View differences:

src/main/java/org/distorted/objects/RubikCube.java
28 28
import org.distorted.library.effect.VertexEffectDeform;
29 29
import org.distorted.library.effect.VertexEffectMove;
30 30
import org.distorted.library.effect.VertexEffectRotate;
31
import org.distorted.library.effect.VertexEffectSink;
32 31
import org.distorted.library.main.DistortedEffects;
33 32
import org.distorted.library.main.DistortedTexture;
34 33
import org.distorted.library.mesh.MeshBase;
35 34
import org.distorted.library.mesh.MeshJoined;
35
import org.distorted.library.mesh.MeshPolygon;
36 36
import org.distorted.library.mesh.MeshSquare;
37 37
import org.distorted.library.type.Static1D;
38 38
import org.distorted.library.type.Static3D;
......
196 196
    int size   = getSize();
197 197
    int ordinal= RubikObjectList.CUBE.ordinal();
198 198
    int index  = RubikObjectList.getSizeIndex(ordinal,size);
199
    float[] loc;
199
    float[] bands;
200
    float D = 0.027f;
201
    float E = 0.5f-D;
202
    float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E };
203
    int extraI, extraV;
200 204

  
201 205
    switch(size)
202 206
      {
203
      case 5 : loc = new float[] { -0.5f, 0.05f, 0.1f, 0.35f, 0.35f, 0.1f, 0.05f };
207
      case 2 : bands = new float[] { 1.0f    ,-D,
208
                                     1.0f-D/2,-D*0.45f,
209
                                     1.0f-D  ,-D*0.80f,
210
                                     1.0f-2*D, 0.0f,
211
                                     0.50f, 0.040f,
212
                                     0.0f, 0.048f };
213
               extraI = 2;
214
               extraV = 2;
204 215
               break;
205
      case 2 : loc = new float[] { -0.5f, 0.03f, 0.05f, 0.07f, 0.20f, 0.30f, 0.20f, 0.07f, 0.05f, 0.03f };
216
      case 3 : bands = new float[] { 1.0f    ,-D,
217
                                     1.0f-D*1.2f,-D*0.55f,
218
                                     1.0f-2*D, 0.0f,
219
                                     0.50f, 0.040f,
220
                                     0.0f, 0.048f };
221
               extraI = 2;
222
               extraV = 2;
223
               break;
224
      case 4 : bands = new float[] { 1.0f    ,-D,
225
                                     1.0f-D*1.2f,-D*0.55f,
226
                                     1.0f-2*D, 0.0f,
227
                                     0.50f, 0.040f,
228
                                     0.0f, 0.048f };
229
               extraI = 1;
230
               extraV = 2;
231
               break;
232
      default: bands = new float[] { 1.0f    ,-D,
233
                                     1.0f-2*D, 0.0f,
234
                                     0.50f, 0.025f,
235
                                     0.0f, 0.030f };
236
               extraI = 1;
237
               extraV = 1;
206 238
               break;
207
      default: loc = new float[] { -0.5f, 0.04f, 0.06f, 0.25f, 0.30f, 0.25f, 0.06f, 0.04f };
208 239
      }
209 240

  
210
    return createCubitMesh(index,loc);
241
    return createCubitMesh(index,vertices,bands,extraI,extraV);
211 242
    }
212 243

  
213 244
///////////////////////////////////////////////////////////////////////////////////////////////////
214 245

  
215
  MeshBase createCubitMesh(int index, float[] loc)
246
  MeshBase createCubitMesh(int index, float[] vertices, float[] bands, int extraI, int extraV)
216 247
    {
217 248
    if( mMeshes==null )
218 249
      {
......
223 254
      {
224 255
      final int MESHES=6;
225 256
      int association = 1;
226
      MeshBase[] meshes = new MeshSquare[MESHES];
227
      meshes[0] = new MeshSquare(loc,loc);
257
      MeshBase[] meshes = new MeshPolygon[MESHES];
258
      meshes[0] = new MeshPolygon(vertices,bands,extraI,extraV);
228 259
      meshes[0].setEffectAssociation(0,association,0);
229 260

  
230 261
      for(int i=1; i<MESHES; i++)
......
290 321
      VertexEffectDeform effect12= new VertexEffectDeform(dVec6, dRad, dCen6, dReg);
291 322
      VertexEffectDeform effect13= new VertexEffectDeform(dVec7, dRad, dCen7, dReg);
292 323

  
293
      VertexEffectSink   effect14= new VertexEffectSink( new Static1D(1.5f), center, new Static4D(0,0,0,0.72f) );
294

  
295 324
      mMeshes[index].apply(effect0);
296 325
      mMeshes[index].apply(effect1);
297 326
      mMeshes[index].apply(effect2);
......
306 335
      mMeshes[index].apply(effect11);
307 336
      mMeshes[index].apply(effect12);
308 337
      mMeshes[index].apply(effect13);
309
      mMeshes[index].apply(effect14);
310 338

  
311 339
      mMeshes[index].mergeEffComponents();
312 340
      }

Also available in: Unified diff