Project

General

Profile

« Previous | Next » 

Revision 5caf2641

Added by Leszek Koltunski over 2 years ago

Beginnings of support for TouchControl of Icosehedral and Ball-shaped objects.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
2112 2112
                                   break;
2113 2113
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
2114 2114
                                   break;
2115
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
2116
                                   break;
2115 2117
        case TC_CUBOID           : int[] numLayers = getNumLayers();
2116 2118
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
2117 2119
                                   break;
2120
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
2121
                                   break;
2118 2122
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
2119 2123
                                   break;
2120 2124
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
26 26
  public static final int TC_TETRAHEDRON       =   4;
27 27
  public static final int TC_OCTAHEDRON        =   8;
28 28
  public static final int TC_DODECAHEDRON      =  12;
29
  public static final int TC_ICOSAHEDRON       =  20;
29 30
  public static final int TC_CUBOID            =   0;
31
  public static final int TC_BALL              =   1;
30 32
  public static final int TC_CHANGING_MIRROR   = 100;
31 33
  public static final int TC_CHANGING_SQUARE   = 101;
32 34
  public static final int TC_CHANGING_SHAPEMOD = 102;
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.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.touchcontrol;
11

  
12
import org.distorted.library.main.QuatHelper;
13
import org.distorted.library.type.Static3D;
14
import org.distorted.library.type.Static4D;
15
import org.distorted.objectlib.main.TwistyObject;
16

  
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18
// Ball-shaped objects: map the 2D swipes of user's fingers to 3D rotations
19

  
20
public class TouchControlBall extends TouchControl
21
{
22
  private final Static3D[] mRotAxis;
23

  
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

  
26
  public TouchControlBall(TwistyObject object)
27
    {
28
    super(object.getObjectRatio());
29
    mRotAxis = object.getRotationAxis();
30
    }
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
  public float returnRotationFactor(int[] numLayers, int row)
35
    {
36
    return 1.0f;
37
    }
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
  public int getTouchedCubitFace()
42
    {
43
    return 0;
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  public int getTouchedCubit()
49
    {
50
    return 0;
51
    }
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
// TODO
55

  
56
  public boolean objectTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera)
57
    {
58
    return false;
59
    }
60

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
// TODO
63

  
64
  public void newRotation(int[] output, Static4D rotatedTouchPoint, Static4D quat)
65
    {
66

  
67
    }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
// simply cast the appropriate rotational axis of the object to the screen surface.
71

  
72
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
73
    {
74
    Static3D a = mRotAxis[axisIndex];
75
    Static4D result = QuatHelper.rotateVectorByQuat(a.get0(),a.get1(),a.get2(),0,quat);
76

  
77
    float cx = result.get0();
78
    float cy = result.get1();
79
    float len= (float)Math.sqrt(cx*cx+cy*cy);
80

  
81
    if( len!=0 )
82
      {
83
      output[0] = cx/len;
84
      output[1] = cy/len;
85
      }
86
    else
87
      {
88
      output[0] = 1;
89
      output[1] = 0;
90
      }
91
    }
92
}
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlDodecahedron.java
124 124
// pentagon.
125 125
// Distance from the center to a vertex of the pentagon = 1/(6*COS54)
126 126

  
127
  int partEdge(float[] point, int face)
127
  private int partEdge(float[] point, int face)
128 128
    {
129 129
    float angle = returnAngle(face);
130 130
    float A = (float)(Math.PI/5);
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlIcosahedron.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.touchcontrol;
11

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

  
14
import org.distorted.library.type.Static3D;
15
import org.distorted.objectlib.main.TwistyObject;
16

  
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18
// Icosahedral objects: map the 2D swipes of user's fingers to 3D rotations
19

  
20
public class TouchControlIcosahedron extends TouchControlShapeConstant
21
{
22
  public  static final float DIST3D = (3*SQ3 + SQ3*SQ5)/12;
23
  private static final float DIST2D = SQ3/6;
24
  public static final float[] D3D   = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
25
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
26
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
27
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
28

  
29
  public static final Static3D[] FACE_AXIS = new Static3D[]
30
         {
31
           // TODO
32
         };
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
  public TouchControlIcosahedron(TwistyObject object)
37
    {
38
    super(object,D3D,FACE_AXIS);
39
    }
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
  public float returnRotationFactor(int[] numLayers, int row)
44
    {
45
    return 1.0f;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  private boolean isFaceInverted(int face)
51
    {
52
    return face<10;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
// corner    edge
57
//   |       \ 0 /
58
// 2 | 0      \ /
59
//  / \      2 | 1
60
// / 1 \       |
61

  
62
  int returnPart(int type, int face, float[] touchPoint)
63
    {
64
    switch(type)
65
      {
66
      case TYPE_NOT_SPLIT   : return 0;
67

  
68
      case TYPE_SPLIT_EDGE  : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
69
                              float x1 = touchPoint[0];
70

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

  
75
                              if(  e1 && e2 ) return 0;
76
                              if( !e1 && e0 ) return 1;
77
                              if( !e0 &&!e2 ) return 2;
78

  
79
      case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
80
                              float x2 = touchPoint[0];
81

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

  
86
                              if(  c0 && c2 ) return 0;
87
                              if( !c1 &&!c2 ) return 1;
88
                              if( !c0 && c1 ) return 2;
89
      }
90

  
91
    return 0;
92
    }
93

  
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

  
96
  boolean isInsideFace(int face, float[] p)
97
    {
98
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
99
    float x = p[0];
100
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
101
    }
102
}
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
561 561

  
562 562
///////////////////////////////////////////////////////////////////////////////////////////////////
563 563

  
564
  public void getCastedRotAxis(float[] output, Static4D quat, int rotIndex)
564
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
565 565
    {
566
    Static3D rotAxis = mRotAxis[rotIndex];
566
    Static3D rotAxis = mRotAxis[axisIndex];
567 567
    float rx = rotAxis.get0();
568 568
    float ry = rotAxis.get1();
569 569
    float rz = rotAxis.get2();
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java
376 376
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
377 377
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
378 378

  
379
  public void getCastedRotAxis(float[] output, Static4D quat, int rotIndex)
379
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
380 380
    {
381
    Static4D axis = mCastedRotAxis4D[mLastTouchedFace][rotIndex];
381
    Static4D axis = mCastedRotAxis4D[mLastTouchedFace][axisIndex];
382 382
    Static4D result = QuatHelper.rotateVectorByQuat(axis, quat);
383 383

  
384 384
    output[0] =result.get0();
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlTetrahedron.java
82 82
  public float returnRotationFactor(int[] numLayers, int row)
83 83
    {
84 84
    int numL = numLayers[0];
85

  
86 85
    return numL==2 ? 1.0f : ((float)numL)/(numL-row);
87 86
    }
88 87

  

Also available in: Unified diff