Project

General

Profile

« Previous | Next » 

Revision 80ec6abf

Added by Leszek Koltunski over 3 years ago

Fixes for the Rex Cube (mostly works now)

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
38 38
  static final float IVY_D = 0.003f;
39 39
  static final float IVY_C = 0.59f;
40 40
  static final float IVY_M = 0.35f;
41
  static final float REX_D = 0.03f;
41
  static final float REX_D = 0.003f;
42 42

  
43 43
  private static final float SQ2 = (float)Math.sqrt(2);
44 44
  private static final float SQ3 = (float)Math.sqrt(3);
......
195 195
    }
196 196

  
197 197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'angle' of the point
199
// (px,py) along axis Z. Center of rotation: (cx,cy).
198
// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'radians' of the
199
// point (px,py) along axis Z. Center of rotation: (cx,cy). Rotation is counterclockwise!
200 200
// Write (rx,ry) to array[index] and array[index+1].
201 201

  
202
  private void writeVertex( float cx, float cy, float px, float py, float angle, float[] array, int index)
202
  private void writeVertex( float cx, float cy, float px, float py, float radians, float[] array, int index)
203 203
    {
204 204
    float vx = px-cx;
205 205
    float vy = py-cy;
206 206

  
207
    double radAngle = Math.PI*angle/180;
208
    float sinA = (float)Math.sin(radAngle);
209
    float cosA = (float)Math.cos(radAngle);
207
    float sinA = (float)Math.sin(radians);
208
    float cosA = (float)Math.cos(radians);
210 209

  
211
    float rvx = vx*cosA +vy*sinA;
212
    float rvy =-vx*sinA +vy*cosA;
210
    float rvx = vx*cosA - vy*sinA;
211
    float rvy = vx*sinA + vy*cosA;
213 212

  
214 213
    array[index  ] = rvx + cx;
215 214
    array[index+1] = rvy + cy;
......
609 608

  
610 609
    final float angle = (float)Math.PI/(6*REX_N);
611 610
    float[] vertices = new float[6*REX_N];
612
    final float H = SQ2*(SQ3/3 - 0.5f);
613 611
    final float D = 0.5f - REX_D;
614
    final float F = H*D;
615
    final float B = (float)Math.sqrt(12/(H*H) - 0.75f) - 0.5f;
612
    final float F = D*SQ2*(SQ3-1);
613
    final float B = 2.5f;
616 614

  
617 615
    final float V1x = -F*0.5f;
618 616
    final float V1y = -F*SQ3/6;
......
622 620
    final float V3y = -2*V1y;
623 621

  
624 622
    final float C1x = 0.0f;
625
    final float C1y = -D*( (SQ3/6)*H - (float)Math.sqrt(4.0f-0.25f*H*H) );
626
    final float C2x = B*V2x;
627
    final float C2y = B*V2y;
628
    final float C3x = B*V3x;
629
    final float C3y = B*V3y;
623
    final float C1y = -F*(1+2*SQ3/3);
624
    final float C2x = B*V1x;
625
    final float C2y = B*V1y;
626
    final float C3x = B*V2x;
627
    final float C3y = B*V2y;
630 628

  
631 629
    for(int i=0; i<REX_N; i++)
632 630
      {
633
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
631
      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
634 632
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
635 633
      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
636 634
      }
637 635

  
638
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
639
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
636
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
637
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
640 638

  
641 639
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
642 640
    meshes[0].setEffectAssociation(0,1,0);
......
654 652

  
655 653
    final float angle = (float)Math.PI/(6*REX_N);
656 654
    float[] vertices = new float[8*REX_N];
657
    final float H = SQ3/2 - 0.5f;
658 655
    final float D = 0.5f - REX_D;
659
    final float F = H*D;
656
    final float F = D*(SQ3-1);
660 657

  
661 658
    final float V1x = 0.0f;
662 659
    final float V1y = +F;
663
    final float V2x = +F;
660
    final float V2x = -F;
664 661
    final float V2y = 0.0f;
665 662
    final float V3x = 0.0f;
666 663
    final float V3y = -F;
667
    final float V4x = -F;
664
    final float V4x = +F;
668 665
    final float V4y = 0.0f;
669 666

  
670
    final float C1x = -D;
667
    final float C1x = +D;
671 668
    final float C1y = -D;
672
    final float C2x = -D;
669
    final float C2x = +D;
673 670
    final float C2y = +D;
674
    final float C3x = +D;
671
    final float C3x = -D;
675 672
    final float C3y = +D;
676
    final float C4x = +D;
673
    final float C4x = -D;
677 674
    final float C4y = -D;
678 675

  
679 676
    for(int i=0; i<REX_N; i++)
......
684 681
      writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
685 682
      }
686 683

  
687
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
688
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
684
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
685
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
689 686

  
690 687
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
691 688
    meshes[0].setEffectAssociation(0,1,0);
......
702 699
    MeshBase[] meshes = new MeshBase[4];
703 700

  
704 701
    final float angle = (float)Math.PI/(6*REX_N);
705
    float[] vertices = new float[4*REX_N + 4];
702
    float[] vertices = new float[4*REX_N + 6];
706 703
    final float H = 1.0f - SQ3/2;
707 704
    final float D = 0.5f - REX_D;
708
    final float F = H*D;
705
    final float F = 0.5f*(0.5f - D*(SQ3-1));
709 706

  
710 707
    final float V1x = -D;
711
    final float V1y = +D - D*SQ3/2;
708
    final float V1y = +D + F - 0.5f;
712 709
    final float V2x = 0.0f;
713
    final float V2y = D*(SQ3-1) - D*SQ3/2;
710
    final float V2y = -F;
714 711

  
715 712
    final float C1x = -D;
716
    final float C1y = -D - D*SQ3/2;
713
    final float C1y = -D + F - 0.5f;
717 714
    final float C2x = +D;
718 715
    final float C2y = C1y;
719 716

  
720 717
    for(int i=0; i<REX_N; i++)
721 718
      {
722
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
723
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
719
      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
720
      writeVertex(C2x,C2y,V2x,V2y,-i*angle, vertices, 2*i + 2*REX_N);
724 721
      }
725 722

  
726 723
    vertices[4*REX_N  ] = +D;
727
    vertices[4*REX_N+1] = +F + REX_D;
728
    vertices[4*REX_N+2] = -D;
729
    vertices[4*REX_N+3] = +F + REX_D;
724
    vertices[4*REX_N+1] = +F-REX_D;
725
    vertices[4*REX_N+2] = +D;
726
    vertices[4*REX_N+3] = +F;
727
    vertices[4*REX_N+4] = -D;
728
    vertices[4*REX_N+5] = +F;
730 729

  
731
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
732
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
730
    float[] bands0 = computeBands(+0.02f, 9,0.5f,0.5f,5);
731
    float[] bands1 = computeBands( 0.00f,45,0.5f,0.0f,2);
733 732

  
734 733
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
735 734
    meshes[0].setEffectAssociation(0,1,0);
......
1174 1173

  
1175 1174
  VertexEffect[] createVertexEffectsRexEdge()
1176 1175
    {
1177
    final float H = 1.0f - SQ3/2;
1178 1176
    final float D = 0.5f - REX_D;
1179
    final float F = H*D;
1177
    final float F = 0.5f*(0.5f - D*(SQ3-1));
1180 1178

  
1181 1179
    Static3D move  = new Static3D(0.0f,   -F, 0.0f);
1182 1180
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
......
1204 1202
    {
1205 1203
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1206 1204
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1207
    Static1D angle = new Static1D(45);
1205
    Static1D angle = new Static1D(225);
1208 1206

  
1209 1207
    VertexEffect[] effect = new VertexEffect[1];
1210 1208
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
src/main/java/org/distorted/objects/MovementRex.java
25 25

  
26 26
class MovementRex extends Movement
27 27
{
28
  static final float DIST3D = 0.5f;
29
  static final float DIST2D = 0.5f;
28
  static final float DIST3D = 0.166f;
29
  static final float DIST2D = 0.166f;
30 30

  
31 31
  static final Static3D[] FACE_AXIS = new Static3D[]
32 32
         {
src/main/java/org/distorted/objects/TwistyDino.java
165 165

  
166 166
  float[] getCuts(int size)
167 167
    {
168
    float[] cuts = new float[2];
169

  
170
    cuts[0] = -SQ3/3;
171
    cuts[1] = +SQ3/3;
172

  
173
    return cuts;
168
    return new float[] { -SQ3/3, +SQ3/3 };
174 169
    }
175 170

  
176 171
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyRex.java
118 118
           {  4, 1, 18,18 },
119 119
           {  0, 2, 18,18 },
120 120
           {  3, 0, 18,18 },
121
           {  1, 3, 18,18 },
122
           {  3, 2, 18,18 },
123
           {  5, 2, 18,18 },
124
           {  5, 0, 18,18 },
121
           {  3, 1, 18,18 },
122
           {  1, 2, 18,18 },
123
           {  2, 5, 18,18 },
124
           {  0, 5, 18,18 },
125 125
           {  5, 3, 18,18 },
126
           {  5, 1, 18,18 },
126
           {  1, 5, 18,18 },
127 127
         };
128 128

  
129 129
  private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
......
140 140

  
141 141
  float getScreenRatio()
142 142
    {
143
    return 1.0f;
143
    return 1.5f;
144 144
    }
145 145

  
146 146
///////////////////////////////////////////////////////////////////////////////////////////////////
......
262 262
    {
263 263
    switch(cubit)
264 264
      {
265
      case  0: return QUATS[5];
266
      case  1: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
267
      case  2: return QUATS[8];
268
      case  3: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
265
      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
266
      case  1: return QUATS[5];
267
      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
268
      case  3: return QUATS[8];
269 269
      case  4: return QUATS[6];
270
      case  5: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
270
      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
271 271
      case  6: return QUATS[11];
272
      case  7: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
273
      case  8: return QUATS[10];
274
      case  9: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
272
      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
273
      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
274
      case  9: return QUATS[10];
275 275
      case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
276 276
      case 11: return QUATS[4];
277 277
      case 12: return QUATS[9];
......
282 282
      case 17: return QUATS[0];
283 283
      case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
284 284
      case 19: return QUATS[3];
285
      case 20: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
286
      case 21: return QUATS[2];
287
      case 22: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
288
      case 23: return QUATS[1];
285
      case 20: return QUATS[1];
286
      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
287
      case 22: return QUATS[2];
288
      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
289 289

  
290
      case 24: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
291
      case 25: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
290
      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
291
      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
292 292
      case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
293 293
      case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
294 294
      case 28: return QUATS[0];
......
298 298
      case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
299 299
      case 32: return QUATS[3];
300 300
      case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
301
      case 34: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
301
      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
302 302
      case 35: return QUATS[7];
303 303
      case 36: return QUATS[9];
304
      case 37: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
304
      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
305 305
      case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
306 306
      case 39: return QUATS[8];
307 307
      case 40: return QUATS[1];

Also available in: Unified diff