Project

General

Profile

« Previous | Next » 

Revision eae4b3b2

Added by Leszek Koltunski over 3 years ago

Convert bandaged Cubes to the standard mesh creation code.

View differences:

src/main/java/org/distorted/objects/TwistyBandaged3Plate.java
43 43
  // One State means one arrangement of the three 2x2 'plates'. Such State precisely defines which
44 44
  // rotations of the Cube are possible.
45 45
  // There are 27 such states in total, but 2 of them are unreachable from the initial State, and
46
  // 9 more and 'insignificant' - i.e. States which only permit rotation along a single axis.
46
  // 9 more are 'insignificant' - i.e. States which only permit rotation along a single axis.
47 47
  // When doing an automatic scramble, we never want to enter such 'insignificant' states because
48 48
  // that would mean we'd have to do two rotations in a row along the same axis.
49 49
  //
......
148 148
      case 1: mUseX = true ; mUseY = false; mUseZ = true ; break;
149 149
      case 2: mUseX = true ; mUseY = true ; mUseZ = false; break;
150 150
      }
151

  
152
    //android.util.Log.e("D", (info[0]==0 ? "X" : (info[0]==1 ? "Y" : "Z")) + info[2] +" --> "+info[3]);
153 151
    }
154 152

  
155 153
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyBandagedAbstract.java
24 24
import org.distorted.helpers.FactoryCubit;
25 25
import org.distorted.helpers.ObjectSticker;
26 26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.effect.VertexEffect;
28
import org.distorted.library.effect.VertexEffectMove;
29
import org.distorted.library.effect.VertexEffectRotate;
30
import org.distorted.library.effect.VertexEffectScale;
31 27
import org.distorted.library.main.DistortedEffects;
32 28
import org.distorted.library.main.DistortedTexture;
33 29
import org.distorted.library.mesh.MeshBase;
34
import org.distorted.library.mesh.MeshJoined;
35
import org.distorted.library.mesh.MeshPolygon;
36 30
import org.distorted.library.mesh.MeshSquare;
37
import org.distorted.library.type.Static1D;
38 31
import org.distorted.library.type.Static3D;
39 32
import org.distorted.library.type.Static4D;
40 33

  
......
178 171
    {
179 172
    float[][] pos = getPositions();
180 173

  
181
    if( cubit>=0 && cubit< pos.length )
174
    if( cubit>=0 && cubit<pos.length )
182 175
      {
183 176
      int numPoints = pos[cubit].length/3;
184 177
      return numPoints==8 ? 4 : numPoints-1;
......
212 205
    return ( cubit>=0 && cubit< indices.length ) ? indices[cubit] : 0;
213 206
    }
214 207

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
  private float[] createVertices(int A, int B)
218
    {
219
    float E = 0.5f / Math.max(A,B);
220
    return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
221
    }
222

  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

  
225
  private MeshBase createCuboid(int[] dimensions)
226
    {
227
    FactoryCubit factory = FactoryCubit.getInstance();
228

  
229
    int X = dimensions[0];
230
    int Y = dimensions[1];
231
    int Z = dimensions[2];
232

  
233
    float[] verticesXY = createVertices(X,Y);
234
    float[] verticesXZ = createVertices(X,Z);
235
    float[] verticesYZ = createVertices(Z,Y);
236

  
237
    float defHeight = 0.048f;
238

  
239
    float[] bandsX = factory.computeBands( defHeight/X,65,0.25f,0.5f,5);
240
    float[] bandsY = factory.computeBands( defHeight/Y,65,0.25f,0.5f,5);
241
    float[] bandsZ = factory.computeBands( defHeight/Z,65,0.25f,0.5f,5);
242

  
243
    MeshBase[] meshes = new MeshPolygon[6];
244

  
245
    meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
246
    meshes[0].setEffectAssociation(0,1,0);
247
    meshes[1] = meshes[0].copy(true);
248
    meshes[1].setEffectAssociation(0,2,0);
249
    meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
250
    meshes[2].setEffectAssociation(0,4,0);
251
    meshes[3] = meshes[2].copy(true);
252
    meshes[3].setEffectAssociation(0,8,0);
253
    meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
254
    meshes[4].setEffectAssociation(0,16,0);
255
    meshes[5] = meshes[4].copy(true);
256
    meshes[5].setEffectAssociation(0,32,0);
257

  
258
    return new MeshJoined(meshes);
259
    }
260

  
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

  
263
  private VertexEffect[] createCuboidEffects(int[] dimensions)
264
    {
265
    float X = dimensions[0];
266
    float Y = dimensions[1];
267
    float Z = dimensions[2];
268

  
269
    float MAX_XY = Math.max(X,Y);
270
    float MAX_XZ = Math.max(X,Z);
271
    float MAX_YZ = Math.max(Z,Y);
272

  
273
    Static1D angle = new Static1D(90);
274
    Static3D move  = new Static3D( 0.0f, 0.0f, 0.5f);
275
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
276
    Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
277
    Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
278

  
279
    Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
280
    Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
281
    Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
282
    Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
283
    Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
284
    Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
285

  
286
    VertexEffect[] effect = new VertexEffect[9];
287

  
288
    effect[0] = new VertexEffectMove(move);
289
    effect[1] = new VertexEffectRotate(angle, axisX, center);
290
    effect[2] = new VertexEffectRotate(angle, axisY, center);
291
    effect[3] = new VertexEffectScale(scale3);
292
    effect[4] = new VertexEffectScale(scale4);
293
    effect[5] = new VertexEffectScale(scale5);
294
    effect[6] = new VertexEffectScale(scale6);
295
    effect[7] = new VertexEffectScale(scale7);
296
    effect[8] = new VertexEffectScale(scale8);
297

  
298
    effect[1].setMeshAssociation(12,-1);  // meshes 2,3
299
    effect[2].setMeshAssociation( 3,-1);  // meshes 0,1
300
    effect[3].setMeshAssociation(16,-1);  // mesh 4
301
    effect[4].setMeshAssociation(32,-1);  // mesh 5
302
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
303
    effect[6].setMeshAssociation( 4,-1);  // mesh 2
304
    effect[7].setMeshAssociation( 1,-1);  // mesh 0
305
    effect[8].setMeshAssociation( 2,-1);  // mesh 1
306

  
307
    return effect;
308
    }
309

  
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

  
312
  private MeshBase createCuboidMesh(int[] dimensions)
313
    {
314
    MeshBase mesh = createCuboid(dimensions);
315
    VertexEffect[] effects = createCuboidEffects(dimensions);
316
    for( VertexEffect effect : effects ) mesh.apply(effect);
317

  
318
    int X = dimensions[0];
319
    int Y = dimensions[1];
320
    int Z = dimensions[2];
321

  
322
    float strength = 0.04f;
323
    float radius   = 0.15f;
324

  
325
    Static3D[] vertices = new Static3D[1];
326
    Static3D center;
327
    FactoryCubit factory = FactoryCubit.getInstance();
328

  
329
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,+0.5f*Z);
330
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
331
    factory.roundCorners(mesh, center, vertices, strength, radius);
332

  
333
    vertices[0] = new Static3D(+0.5f*X,+0.5f*Y,-0.5f*Z);
334
    center = new Static3D(+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
335
    factory.roundCorners(mesh, center, vertices, strength, radius);
336

  
337
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,+0.5f*Z);
338
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
339
    factory.roundCorners(mesh, center, vertices, strength, radius);
340

  
341
    vertices[0] = new Static3D(+0.5f*X,-0.5f*Y,-0.5f*Z);
342
    center = new Static3D(+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
343
    factory.roundCorners(mesh, center, vertices, strength, radius);
344

  
345
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,+0.5f*Z);
346
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1));
347
    factory.roundCorners(mesh, center, vertices, strength, radius);
348

  
349
    vertices[0] = new Static3D(-0.5f*X,+0.5f*Y,-0.5f*Z);
350
    center = new Static3D(-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1));
351
    factory.roundCorners(mesh, center, vertices, strength, radius);
352

  
353
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,+0.5f*Z);
354
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1));
355
    factory.roundCorners(mesh, center, vertices, strength, radius);
356

  
357
    vertices[0] = new Static3D(-0.5f*X,-0.5f*Y,-0.5f*Z);
358
    center = new Static3D(-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1));
359
    factory.roundCorners(mesh, center, vertices, strength, radius);
360

  
361
    mesh.mergeEffComponents();
362

  
363
    return mesh;
364
    }
365

  
366 208
///////////////////////////////////////////////////////////////////////////////////////////////////
367 209

  
368 210
  MeshBase createCubitMesh(int cubit, int numLayers)
......
372 214
      int LEN = mDimensions.length;
373 215
      mMeshes = new MeshBase[LEN];
374 216

  
217
      final int[][] vert_indices =
218
          {
219
              {2,3,1,0},
220
              {7,6,4,5},
221
              {6,2,0,4},
222
              {3,7,5,1},
223
              {4,0,1,5},
224
              {7,3,2,6},
225
          };
226

  
227
      float defHeight = 0.048f;
228
      int[] bandIndexes = new int[] { 0,0,1,1,2,2 };
229
      float[][] corners = new float[][] { {0.04f,0.15f} };
230
      int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
231
      int[] centerIndexes = new int[] { 0,1,2,3,4,5,6,7 };
232

  
375 233
      for(int i=0; i<LEN; i++)
376 234
        {
377
        mMeshes[i] = createCuboidMesh(mDimensions[i]);
235
        int X = mDimensions[i][0];
236
        int Y = mDimensions[i][1];
237
        int Z = mDimensions[i][2];
238

  
239
        double[][] vertices =
240
            {
241
                {+0.5f*X,+0.5f*Y,+0.5f*Z},
242
                {+0.5f*X,+0.5f*Y,-0.5f*Z},
243
                {+0.5f*X,-0.5f*Y,+0.5f*Z},
244
                {+0.5f*X,-0.5f*Y,-0.5f*Z},
245
                {-0.5f*X,+0.5f*Y,+0.5f*Z},
246
                {-0.5f*X,+0.5f*Y,-0.5f*Z},
247
                {-0.5f*X,-0.5f*Y,+0.5f*Z},
248
                {-0.5f*X,-0.5f*Y,-0.5f*Z}
249
            };
250

  
251
        float[][] bands= new float[][]
252
            {
253
                {defHeight/X,65,0.25f,0.5f,5,1,2},
254
                {defHeight/Y,65,0.25f,0.5f,5,1,2},
255
                {defHeight/Z,65,0.25f,0.5f,5,1,2}
256
            };
257

  
258
        float[][] centers = new float[][]
259
            {
260
                {+0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1)},
261
                {+0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1)},
262
                {+0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1)},
263
                {+0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1)},
264
                {-0.5f*(X-1),+0.5f*(Y-1),+0.5f*(Z-1)},
265
                {-0.5f*(X-1),+0.5f*(Y-1),-0.5f*(Z-1)},
266
                {-0.5f*(X-1),-0.5f*(Y-1),+0.5f*(Z-1)},
267
                {-0.5f*(X-1),-0.5f*(Y-1),-0.5f*(Z-1)}
268
            };
269

  
270
        FactoryCubit factory = FactoryCubit.getInstance();
271
        factory.createNewFaceTransform(vertices,vert_indices);
272
        mMeshes[i] = factory.createRoundedSolid(vertices,vert_indices,
273
                                                bands, bandIndexes,
274
                                                corners, cornerIndexes,
275
                                                centers, centerIndexes,
276
                                                getNumCubitFaces() );
378 277
        }
379 278
      }
380 279

  

Also available in: Unified diff