Project

General

Profile

« Previous | Next » 

Revision a0b0795b

Added by Leszek Koltunski almost 3 years ago

Introduce support for per-object pillowing.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
25 25
import org.distorted.library.effect.MatrixEffectScale;
26 26
import org.distorted.library.effect.VertexEffectQuaternion;
27 27
import org.distorted.library.effect.VertexEffectRotate;
28
import org.distorted.library.effect.VertexEffectSink;
28 29
import org.distorted.library.main.DistortedEffects;
29 30
import org.distorted.library.main.DistortedLibrary;
30 31
import org.distorted.library.main.DistortedNode;
......
386 387
      }
387 388
    }
388 389

  
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
392
//
393
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
394
// to introduce the concept of a 'sink center' as well.
395

  
396
  private float getCircumscribedRadius()
397
    {
398
    switch(mNumPuzzleFaces)
399
      {
400
      case  4: return (SQ6/4)*mSize;
401
      case  6: return (SQ3/2)*mSize;
402
      case  8: return (SQ2/2)*mSize;
403
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
404
      }
405

  
406
    return 0.0f;
407
    }
408

  
389 409
///////////////////////////////////////////////////////////////////////////////////////////////////
390 410

  
391 411
  private void createMeshAndCubits(InputStream stream, int meshState, boolean fromDMESH)
......
418 438
        }
419 439

  
420 440
      mMesh = new MeshJoined(cubitMesh);
441

  
442
      float pillowCoeff = getPillowCoeff();
443

  
444
      if( pillowCoeff!=1.0f )
445
        {
446
        float radius = getCircumscribedRadius();
447
        Static1D coeff = new Static1D(pillowCoeff);
448
        Static4D region= new Static4D(0,0,0,radius);
449
        VertexEffectSink sink = new VertexEffectSink(coeff,CENTER,region);
450
        mMesh.apply(sink);
451
        }
421 452
      }
422 453

  
423 454
    for(int i=0; i<mNumCubits; i++)
......
2046 2077
    }
2047 2078

  
2048 2079
///////////////////////////////////////////////////////////////////////////////////////////////////
2049
// this is here only so it can be overridden in TwistyJSON soo that we can get this from JSON.
2080
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
2050 2081

  
2051 2082
  public int getNumCubitFaces()
2052 2083
    {
2053 2084
    return 0;
2054 2085
    }
2055 2086

  
2087
///////////////////////////////////////////////////////////////////////////////////////////////////
2088
// 1.0 - i.e. no pillowing - by default.
2089
// The coeff is really param of the 'sink' vertex effect - if it is not equal to 1.0, we apply the
2090
// sink effect [centered at (0,0,0)] to the whole mesh as the last step of composing it.
2091

  
2092
  public float getPillowCoeff()
2093
    {
2094
    return 1.0f;
2095
    }
2096

  
2056 2097
///////////////////////////////////////////////////////////////////////////////////////////////////
2057 2098

  
2058 2099
  public TouchControl getTouchControl()
src/main/java/org/distorted/objectlib/objects/TwistyJing.java
278 278
    else if( variant==1 )
279 279
      {
280 280
      float height = isInIconMode() ? 0.001f : 0.015f;
281
      float[][] bands     = { {height,35,0.5f*F,F,5,1,1},{0.001f,35,0.5f*F,F,5,1,1} };
281
      float[][] bands     = { {height,35,0.2f*F,0.3f*F,7,0,0},{0.001f,35,0.2f*F,0.3f*F,7,0,0} };
282 282
      int[] bandIndices   = { 0,0,1,1,1,1 };
283 283
      float[][] corners   = { {0.07f,0.20f*F} };
284 284
      int[] cornerIndices = { 0,0,-1,0,0,0,-1,0 };

Also available in: Unified diff