Project

General

Profile

« Previous | Next » 

Revision ad73edd5

Added by Leszek Koltunski over 4 years ago

Minor speedup

View differences:

src/main/java/org/distorted/objects/RubikObject.java
161 161
    setProjection(fov, 0.1f);
162 162
    }
163 163

  
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
  private void textureCubitMesh(MeshBase mesh, int cubit)
167
    {
168
    boolean belongs;
169
    final Static4D[] maps = new Static4D[NUM_FACES];
170
    final float ratio = 1.0f/(NUM_FACES+1);
171

  
172
    if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
173
      {
174
      for(int i=0; i<NUM_FACES; i++)
175
        {
176
        belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
177
        maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
178
        }
179
      }
180
    else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
181
      {
182
      for(int i=0; i<NUM_FACES; i++)
183
        {
184
        belongs = isOnFace(cubit, i, 0 );
185
        maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
186
        }
187
      }
188

  
189
    mesh.setTextureMap(maps,NUM_FACES*cubit);
190
    }
191

  
192 164
///////////////////////////////////////////////////////////////////////////////////////////////////
193 165
// Cast centers of all Cubits on the first rotation Axis and compute the leftmost and rightmost
194 166
// one. From there compute the 'start' (i.e. the leftmost) and 'step' (i.e. distance between two
......
439 411

  
440 412
  public void resetAllTextureMaps()
441 413
    {
442
    for(int i=0; i<NUM_CUBITS; i++)
414
    boolean belongs;
415
    final float ratio = 1.0f/(NUM_FACES+1);
416

  
417
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
443 418
      {
444
      textureCubitMesh( mMesh , i );
419
      final Static4D[] maps = new Static4D[NUM_FACES];
420

  
421
      if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
422
        {
423
        for(int i=0; i<NUM_FACES; i++)
424
          {
425
          belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
426
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
427
          }
428
        }
429
      else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
430
        {
431
        for(int i=0; i<NUM_FACES; i++)
432
          {
433
          belongs = isOnFace(cubit, i, 0 );
434
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
435
          }
436
        }
437

  
438
      mMesh.setTextureMap(maps,NUM_FACES*cubit);
445 439
      }
446 440
    }
447 441

  

Also available in: Unified diff