Project

General

Profile

« Previous | Next » 

Revision 99320a69

Added by Leszek Koltunski almost 3 years ago

Shape and TouchControl for the Icosahedral puzzles.

View differences:

src/main/java/org/distorted/objectlib/main/ShapeIcosahedron.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.objectlib.main;
11

  
12
import org.distorted.library.type.Static3D;
13
import org.distorted.library.type.Static4D;
14

  
15
import java.io.InputStream;
16

  
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

  
19
public abstract class ShapeIcosahedron extends TwistyObject
20
{
21
  public static final Static4D DEFAULT_ROT = new Static4D(-0.63874420f, 0.25712812f, 0.358450060f, 0.63039730f);
22

  
23
  static final int ICO_1 = 0xff53aa00;  // TODO: define the color scheme
24
  static final int ICO_2 = 0xfffd7ab7;
25
  static final int ICO_3 = 0xffefd48b;
26
  static final int ICO_4 = 0xff00a2d7;
27
  static final int ICO_5 = 0xffff6200;
28
  static final int ICO_6 = 0xff7d59a4;
29
  static final int ICO_7 = 0xff007a47;
30
  static final int ICO_8 = 0xffbd0000;
31
  static final int ICO_9 = 0xff1a29b2;
32
  static final int ICO_10= 0xffffc400;
33
  static final int ICO_11= 0xffffffff;
34
  static final int ICO_12= 0xff727c7b;
35
  static final int ICO_13= 0xff727c7b;
36
  static final int ICO_14= 0xff727c7b;
37
  static final int ICO_15= 0xff727c7b;
38
  static final int ICO_16= 0xff727c7b;
39
  static final int ICO_17= 0xff727c7b;
40
  static final int ICO_18= 0xff727c7b;
41
  static final int ICO_19= 0xff727c7b;
42
  static final int ICO_20= 0xff727c7b;  // END TODO
43

  
44
  static final int[] FACE_COLORS = new int[]
45
         {
46
           ICO_1 , ICO_2 , ICO_3 , ICO_4 , ICO_5 ,
47
           ICO_6 , ICO_7 , ICO_8 , ICO_9 , ICO_10,
48
           ICO_11, ICO_12, ICO_13, ICO_14, ICO_15,
49
           ICO_16, ICO_17, ICO_18, ICO_19, ICO_20,
50
         };
51

  
52
  static final int NUM_FACES = 20;
53
  static final int FOV = 30;
54
  static final float RATIO = 0.35f;
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
  public ShapeIcosahedron(InitData data, int meshState, int iconMode, float realSize, Static4D quat, Static3D move, float scale, InputStream stream)
59
    {
60
    super(data, meshState, iconMode, realSize, quat, move, scale, stream);
61
    }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  public final int getNumFaces()
66
    {
67
    return NUM_FACES;
68
    }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  public int getNumFaceColors()
73
    {
74
    return FACE_COLORS.length;
75
    }
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
  public int getColor(int face)
80
    {
81
    return FACE_COLORS[face];
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  public int getFOV()
87
    {
88
    return FOV;
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  public float getScreenRatio()
94
    {
95
    return RATIO;
96
    }
97
}
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlIcosahedron.java
9 9

  
10 10
package org.distorted.objectlib.touchcontrol;
11 11

  
12
import static org.distorted.objectlib.main.TwistyObject.SQ2;
12 13
import static org.distorted.objectlib.main.TwistyObject.SQ5;
13 14

  
14 15
import org.distorted.library.type.Static3D;
......
19 20

  
20 21
public class TouchControlIcosahedron extends TouchControlShapeConstant
21 22
{
22
  public  static final float DIST3D = (3*SQ3 + SQ3*SQ5)/12;
23
  public  static final float DIST3D = (3+SQ5)*SQ3/12;
23 24
  private static final float DIST2D = SQ3/6;
24 25
  public static final float[] D3D   = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
25 26
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
26 27
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
27 28
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
29
  // topmost vertex (0,A,0)
30
  // 3 vertices from the second-topmost-layer, front one and two ones to the right:
31
  // (0,B,C) , (D,B,E) , (F,B,H)
32

  
33
  private static final float Z = (float)Math.sqrt(5+SQ5);
34

  
35
  private static final float A = Z*(SQ2/4);
36
  private static final float B = Z*(SQ2*SQ5/20);
37
  private static final float C = Z*(SQ2*SQ5/10);
38
  private static final float D = Z*(SQ5-1)/(4*SQ2*SQ5);
39
  private static final float E = (SQ5+1)/4;
40
  private static final float F = 0.5f;
41
  private static final float H =-Z*(SQ5+1)/(4*SQ2*SQ5);
42

  
43
  private static final float X1 = D/3;
44
  private static final float X2 = (D+F)/3;
45
  private static final float X3 = (2*D+F)/3;
46
  private static final float X4 = (D+F)/2;
47
  private static final float Y1 = (A+2*B)/3;
48
  private static final float Y2 = B/3;
49
  private static final float Z1 = (C+E)/3;
50
  private static final float Z2 = (E+H)/3;
51
  private static final float Z3 = 2*H/3;
52
  private static final float Z4 = (C-2*H)/3;
53
  private static final float Z5 = -H/3;
54
  private static final float Z6 = (H-C-E)/3;
28 55

  
29 56
  public static final Static3D[] FACE_AXIS = new Static3D[]
30 57
         {
31
           // TODO
58
           new Static3D(    X1, Y1, Z1   ),
59
           new Static3D(    X2, Y1, Z2   ),
60
           new Static3D(  0.0f, Y1, Z3   ),
61
           new Static3D(   -X2, Y1, Z2   ),
62
           new Static3D(   -X1, Y1, Z1   ),
63

  
64
           new Static3D(  0.0f,-Y2, Z4   ),
65
           new Static3D(    X3,-Y2, Z5   ),
66
           new Static3D(    X4,-Y2, Z6   ),
67
           new Static3D(   -X4,-Y2, Z6   ),
68
           new Static3D(   -X3,-Y2, Z5   ),
69

  
70
           new Static3D(  0.0f, Y2,-Z4   ),
71
           new Static3D(   -X3, Y2,-Z5   ),
72
           new Static3D(   -X4, Y2,-Z6   ),
73
           new Static3D(    X4, Y2,-Z6   ),
74
           new Static3D(    X3, Y2,-Z5   ),
75

  
76
           new Static3D(   -X1,-Y1,-Z1   ),
77
           new Static3D(   -X2,-Y1,-Z2   ),
78
           new Static3D(  0.0f,-Y1,-Z3   ),
79
           new Static3D(    X2,-Y1,-Z2   ),
80
           new Static3D(    X1,-Y1,-Z1   ),
32 81
         };
33 82

  
34 83
///////////////////////////////////////////////////////////////////////////////////////////////////
......
69 118
                              float x1 = touchPoint[0];
70 119

  
71 120
                              boolean e0 = x1>0;
72
                              boolean e1 = y1>(+SQ3/3)*x1;
121
                              boolean e1 = y1>( SQ3/3)*x1;
73 122
                              boolean e2 = y1>(-SQ3/3)*x1;
74 123

  
75 124
                              if(  e1 && e2 ) return 0;
......
80 129
                              float x2 = touchPoint[0];
81 130

  
82 131
                              boolean c0 = x2>0;
83
                              boolean c1 = y2>(+SQ3/3)*x2;
132
                              boolean c1 = y2>( SQ3/3)*x2;
84 133
                              boolean c2 = y2>(-SQ3/3)*x2;
85 134

  
86 135
                              if(  c0 && c2 ) return 0;

Also available in: Unified diff