Project

General

Profile

« Previous | Next » 

Revision e35247b8

Added by Leszek Koltunski over 4 years ago

Improve Pyraminx Mesh

View differences:

src/main/java/org/distorted/main/RubikActivity.java
284 284
        RubikObjectList oldList = oldObject.getObjectList();
285 285
        int oldSize = oldObject.getSize();
286 286
        float fps = view.getRenderer().getFPS();
287
        fps = (int)(fps+0.5f);
287 288
        StringBuilder name = new StringBuilder();
288 289
        name.append(oldList.name());
289 290
        name.append('_');
src/main/java/org/distorted/objects/RubikPyraminx.java
26 26
import org.distorted.library.effect.VertexEffectDeform;
27 27
import org.distorted.library.effect.VertexEffectMove;
28 28
import org.distorted.library.effect.VertexEffectRotate;
29
import org.distorted.library.effect.VertexEffectScale;
29
import org.distorted.library.effect.VertexEffectSink;
30 30
import org.distorted.library.main.DistortedEffects;
31 31
import org.distorted.library.main.DistortedTexture;
32 32
import org.distorted.library.mesh.MeshBase;
......
253 253
    final int MESHES=4;
254 254

  
255 255
    int size = getSize();
256

  
257 256
    int association = 1;
258
    MeshBase[] meshes;
259 257

  
260
    float D = 0.005f;
261
    float E = 0.5f - D*SQ2;
258
    float D = 0.0003f;
259
    float E = SQ3/2 - 3*D*SQ2;
262 260
    float F = 0.5f - D*SQ2*SQ3;
263
    float G = 0.006f;
264 261
    float[] bands;
265 262
    int extraI, extraV;
266 263

  
267
    float[] vertices = { -F,-E, +F,-E, 0.0f,E-D*SQ2};
264
    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
268 265

  
269 266
    switch(size)
270 267
      {
271
      case 3 : bands = new float[] { 1.0f    ,-G,
272
                                     1.0f-G/2,-G*0.55f,
273
                                     1.0f-G  ,-G*0.25f,
274
                                     1.0f-2*G,+G*0.25f,
275
                                     0.50f, 0.050f,
276
                                     0.0f, 0.055f };
268
      case 3 : bands = new float[] { 1.0f    ,-D,
269
                                     1.0f  -D,-D*0.80f,
270
                                     1.0f-2*D,-D*0.65f,
271
                                     1.0f-4*D,+D*0.10f,
272
                                     0.50f, 0.035f,
273
                                     0.0f, 0.040f };
277 274
                      extraI = 2;
278 275
                      extraV = 2;
279 276
                      break;
280
      case 4 : bands = new float[] { 1.0f    ,-G,
281
                                     1.0f-G*1.2f,-G*0.55f,
282
                                     1.0f-2*G, +G*0.25f,
283
                                     0.50f, 0.050f,
284
                                     0.0f, 0.055f };
277
      case 4 : bands = new float[] { 1.0f    ,-D,
278
                                     1.0f-D*1.2f,-D*0.70f,
279
                                     1.0f-3*D, -D*0.15f,
280
                                     0.50f, 0.035f,
281
                                     0.0f, 0.040f };
285 282
                      extraI = 2;
286 283
                      extraV = 2;
287 284
                      break;
288
      default: bands = new float[] { 1.0f    ,-G,
289
                                     1.0f-G*1.2f,-G*0.55f,
290
                                     1.0f-2*G, +G*0.25f,
291
                                     0.50f, 0.050f,
292
                                     0.0f, 0.055f };
285
      default: bands = new float[] { 1.0f    ,-D,
286
                                     1.0f-D*1.2f,-D*0.70f,
287
                                     1.0f-3*D, -D*0.15f,
288
                                     0.50f, 0.035f,
289
                                     0.0f, 0.040f };
293 290
                      extraI = 2;
294 291
                      extraV = 1;
295 292
                      break;
296 293
      }
297 294

  
298
    meshes = new MeshPolygon[MESHES];
295
    MeshBase[] meshes = new MeshPolygon[MESHES];
299 296
    meshes[0] = new MeshPolygon(vertices, bands, extraI,extraV);
300 297
    meshes[0].setEffectAssociation(0,association,0);
301 298

  
......
315 312

  
316 313
    float tetraHeight = SQ2*SQ3/3;
317 314
    float d1 = (0.75f-2*SQ2*D)*tetraHeight;
318
    float d2 =-0.10f*tetraHeight;
319
    float d3 = 0.20f*tetraHeight;
315
    float d2 =-0.06f*tetraHeight;
316
    float d3 = 0.05f*tetraHeight;
317
    float d4 = 0.70f*tetraHeight;
318
    float d5 = 1.2f;
320 319

  
321 320
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
322 321
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
......
330 329

  
331 330
    Static4D dReg  = new Static4D(0,0,0,d3);
332 331
    Static1D dRad  = new Static1D(1);
332
    Static3D center= new Static3D(0,0,0);
333
    Static4D sReg  = new Static4D(0,0,0,d4);
334
    Static1D sink  = new Static1D(d5);
333 335

  
334 336
    Static1D angle  = new Static1D(angleFaces);
335 337
    Static3D axis1  = new Static3D(  -1, 0,      0);
......
338 340
    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
339 341
    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
340 342

  
341
    VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
342
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
343
    VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
344
    VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
345
    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
346
    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
347
    VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
343
    VertexEffectRotate  effect1 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), center );
344
    VertexEffectMove    effect2 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,0) );
345
    VertexEffectRotate  effect3 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
346
    VertexEffectRotate  effect4 = new VertexEffectRotate( angle, axis1, center1 );
347
    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis2, center2 );
348
    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis3, center2 );
349

  
350
    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
351
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
352
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
353
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
348 354

  
349
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
350
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
351
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
352
    VertexEffectDeform  effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
355
    VertexEffectSink effect11= new VertexEffectSink(sink,center, sReg);
353 356

  
354
    effect4.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
355
    effect5.setMeshAssociation( 2,-1);  // apply only to mesh[1]
356
    effect6.setMeshAssociation( 4,-1);  // apply only to mesh[2]
357
    effect7.setMeshAssociation( 8,-1);  // apply only to mesh[3]
357
    effect3.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
358
    effect4.setMeshAssociation( 2,-1);  // apply only to mesh[1]
359
    effect5.setMeshAssociation( 4,-1);  // apply only to mesh[2]
360
    effect6.setMeshAssociation( 8,-1);  // apply only to mesh[3]
358 361

  
359 362
    result.apply(effect1);
360 363
    result.apply(effect2);
......
362 365
    result.apply(effect4);
363 366
    result.apply(effect5);
364 367
    result.apply(effect6);
368

  
365 369
    result.apply(effect7);
366 370
    result.apply(effect8);
367 371
    result.apply(effect9);
368 372
    result.apply(effect10);
373

  
369 374
    result.apply(effect11);
370 375

  
371 376
    if( mRotArray[cubit]>=0 )
......
411 416
    float ARC2_H = 0.905f*side;
412 417
    float ARC3_W = side-ARC2_W;
413 418

  
419
    float M = SQ3/2;
420
    float D = (M/2 - 0.51f)*side;
421

  
414 422
    paint.setAntiAlias(true);
415 423
    paint.setStrokeWidth(STROKE);
416 424
    paint.setColor(FACE_COLORS[face]);
......
421 429
    paint.setColor(INTERIOR_COLOR);
422 430
    paint.setStyle(Paint.Style.STROKE);
423 431

  
424
    canvas.drawLine(           left, HEIGHT,  side       +left, HEIGHT, paint);
425
    canvas.drawLine(      OFF +left, side  ,       OFF2  +left,      0, paint);
426
    canvas.drawLine((side-OFF)+left, side  , (side-OFF2) +left,      0, paint);
432
    canvas.drawLine(           left, M*HEIGHT+D,  side       +left, M*HEIGHT+D, paint);
433
    canvas.drawLine(      OFF +left, M*side  +D,       OFF2  +left,          D, paint);
434
    canvas.drawLine((side-OFF)+left, M*side  +D, (side-OFF2) +left,          D, paint);
427 435

  
428
    canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint);
429
    canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint);
430
    canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint);
436
    canvas.drawArc( ARC1_W-RADIUS+left, M*(ARC1_H-RADIUS)+D, ARC1_W+RADIUS+left, M*(ARC1_H+RADIUS)+D, 225, 90, false, paint);
437
    canvas.drawArc( ARC2_W-RADIUS+left, M*(ARC2_H-RADIUS)+D, ARC2_W+RADIUS+left, M*(ARC2_H+RADIUS)+D, 105, 90, false, paint);
438
    canvas.drawArc( ARC3_W-RADIUS+left, M*(ARC2_H-RADIUS)+D, ARC3_W+RADIUS+left, M*(ARC2_H+RADIUS)+D, 345, 90, false, paint);
431 439
    }
432 440

  
433 441
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff