Project

General

Profile

« Previous | Next » 

Revision 418aa554

Added by Leszek Koltunski over 4 years ago

Beginnings of support for a new Object: the Dino.

View differences:

src/main/java/org/distorted/objects/RubikDino.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
import android.content.res.Resources;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshBase;
29
import org.distorted.library.mesh.MeshRectangles;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
public class RubikDino extends RubikObject
36
{
37
  static final float SQ3 = (float)Math.sqrt(3);
38

  
39
  // the four rotation axis of a RubikDino. Must be normalized.
40
  static final Static3D[] AXIS = new Static3D[]
41
         {
42
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
44
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
45
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
46
         };
47

  
48
  private static final int[] FACE_COLORS = new int[]
49
         {
50
           0xffffff00, 0xffffffff,   // AXIS[0]right (right-YELLOW) AXIS[0]left (left  -WHITE)
51
           0xff0000ff, 0xff00ff00,   // AXIS[1]right (top  -BLUE  ) AXIS[1]left (bottom-GREEN)
52
           0xffff0000, 0xffb5651d    // AXIS[2]right (front-RED   ) AXIS[2]left (back  -BROWN)
53
         };
54

  
55
  // All legal rotation quats of a RubikDino
56
  private static final Static4D[] QUATS = new Static4D[]
57
         {
58
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
59
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
60
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
61
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
62
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
63
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
64
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
65
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
66
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
67
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
68
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
69
           new Static4D(  0.0f, -1.0f,  0.0f,  0.0f )
70
         };
71

  
72
  private static MeshBase[] mMeshes;
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  RubikDino(int size, Static4D quat, DistortedTexture texture,
77
            MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
78
    {
79
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
80
    }
81

  
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

  
84
  float getScreenRatio()
85
    {
86
    return 0.5f;
87
    }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
  Static4D[] getQuats()
92
    {
93
    return QUATS;
94
    }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
  int getNumFaces()
99
    {
100
    return FACE_COLORS.length;
101
    }
102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

  
105
  Static3D[] getCubitPositions(int size)
106
    {
107
    // TODO
108

  
109
    return null;
110
    }
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
  MeshBase createCubitMesh(int cubit)
115
    {
116
    // TODO
117

  
118
    return null;
119
    }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
124
    {
125
    float STROKE = 0.06f*side;
126
    float OFF = STROKE/2 -1;
127
    float OFF2 = 0.5f*side + OFF;
128
    float HEIGHT = side - OFF;
129
    float RADIUS = side/12.0f;
130
    float ARC1_H = 0.2f*side;
131
    float ARC1_W = side*0.5f;
132
    float ARC2_W = 0.153f*side;
133
    float ARC2_H = 0.905f*side;
134
    float ARC3_W = side-ARC2_W;
135

  
136
    paint.setAntiAlias(true);
137
    paint.setStrokeWidth(STROKE);
138
    paint.setColor(FACE_COLORS[face]);
139
    paint.setStyle(Paint.Style.FILL);
140

  
141
    canvas.drawRect(left,top,left+side,top+side,paint);
142

  
143
    paint.setColor(INTERIOR_COLOR);
144
    paint.setStyle(Paint.Style.STROKE);
145

  
146
    canvas.drawLine(           left, HEIGHT,  side       +left, HEIGHT, paint);
147
    canvas.drawLine(      OFF +left, side  ,       OFF2  +left,      0, paint);
148
    canvas.drawLine((side-OFF)+left, side  , (side-OFF2) +left,      0, paint);
149

  
150
    canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint);
151
    canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint);
152
    canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint);
153
    }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
// PUBLIC API
157

  
158
  public Static3D[] getRotationAxis()
159
    {
160
    return AXIS;
161
    }
162

  
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

  
165
  public int getBasicAngle()
166
    {
167
    return 3;
168
    }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  public float returnMultiplier()
173
    {
174
    // TODO
175

  
176
    return 0;
177
    }
178

  
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

  
181
  public float returnRotationFactor(float offset)
182
    {
183
    return 1.0f;
184
    }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
  public float[] getRowChances()
189
    {
190
    int size = getSize();
191
    float[] chances = new float[size];
192

  
193
    for(int i=0; i<size; i++)
194
      {
195
      chances[i] = (i+1.0f) / size;
196
      }
197

  
198
    return chances;
199
    }
200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
// TODO  (only needed for solvers - there are no Dino solvers ATM)
203

  
204
  public String retObjectString()
205
    {
206
    return "";
207
    }
208

  
209
}
src/main/java/org/distorted/objects/RubikDinoMovement.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
class RubikDinoMovement extends RubikObjectMovement
25
{
26
  RubikDinoMovement()
27
    {
28
    super(RubikDino.AXIS, 1.5f, 0.5f, 0.5f);
29
    }
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
  boolean isInsideFace(float[] p)
34
    {
35
    return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f );
36
    }
37
}
src/main/java/org/distorted/objects/RubikObject.java
645 645

  
646 646
  public int getCubit(float[] point3D)
647 647
    {
648
    float dist, minDist = Float. MAX_VALUE;
648
    float dist, minDist = Float.MAX_VALUE;
649 649
    int currentBest=-1;
650 650
    float multiplier = returnMultiplier();
651 651

  
src/main/java/org/distorted/objects/RubikObjectList.java
54 54
         RubikPyraminx.class,
55 55
         new RubikPyraminxMovement()
56 56
       ),
57

  
58
  DINO (
59
         new int[][] {
60
                       {3 , 10, R.raw.pyra3, R.drawable.ui_small_pyra3, R.drawable.ui_medium_pyra3, R.drawable.ui_big_pyra3, R.drawable.ui_huge_pyra3} ,
61
                     },
62
         RubikDino.class,
63
         new RubikDinoMovement()
64
       ),
57 65
  ;
58 66

  
59 67
  public static final int NUM_OBJECTS = values().length;
......
354 362
      {
355 363
      case 0: return new RubikCube    (size, quat, texture, mesh, effects, moves, res, scrWidth);
356 364
      case 1: return new RubikPyraminx(size, quat, texture, mesh, effects, moves, res, scrWidth);
365
      case 2: return new RubikDino    (size, quat, texture, mesh, effects, moves, res, scrWidth);
357 366
      }
358 367

  
359 368
    return null;
src/main/java/org/distorted/objects/RubikObjectMovement.java
42 42

  
43 43
///////////////////////////////////////////////////////////////////////////////////////////////////
44 44

  
45
  RubikObjectMovement(Static3D[] axis, int numFacesPerAxis, float distance3D, float distance2D)
45
  RubikObjectMovement(Static3D[] axis, float numFacesPerAxis, float distance3D, float distance2D)
46 46
    {
47 47
    mPoint = new float[3];
48 48
    mCamera= new float[3];
......
53 53

  
54 54
    mAxis = axis;
55 55
    mNumAxis = mAxis.length;
56
    mNumFacesPerAxis = numFacesPerAxis;
56
    mNumFacesPerAxis = (int)numFacesPerAxis;  // TODO
57 57
    mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces
58 58
    mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge
59 59

  
src/main/java/org/distorted/objects/RubikPyraminx.java
420 420
    }
421 421

  
422 422
///////////////////////////////////////////////////////////////////////////////////////////////////
423
// TODO
423
// TODO  (only needed for solvers - there are no Pyraminx solvers ATM)
424 424

  
425 425
  public String retObjectString()
426 426
    {
src/main/res/raw/compute_quats.c
2 2
#include <math.h>
3 3
#include <stdlib.h>
4 4

  
5
#define PYRAMIX
5
#define DINO
6 6

  
7 7
#define SQ2 1.41421356237f
8 8
#define SQ3 1.73205080757f
......
20 20
#endif
21 21

  
22 22
#ifdef CUBE
23
#define NUM_AXIS 3
23
#define NUM_AXIS    3
24 24
#define BASIC_ANGLE 4
25

  
25 26
float axis[NUM_AXIS][3] = { { 1,0,0 }, {0,1,0}, {0,0,1} };
26 27
#endif
27 28

  
29
#ifdef DINO
30
#define NUM_AXIS    4
31
#define BASIC_ANGLE 3
32

  
33
float axis[NUM_AXIS][3] = { {+SQ3/3,+SQ3/3,+SQ3/3} , 
34
                            {+SQ3/3,+SQ3/3,-SQ3/3} , 
35
                            {+SQ3/3,-SQ3/3,+SQ3/3} , 
36
                            {+SQ3/3,-SQ3/3,-SQ3/3} };
37
#endif
38

  
28 39
float* quats;
29 40
float* table;
30 41
int inserted=0;

Also available in: Unified diff