Project

General

Profile

Download (6.07 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / object / RubikPyraminx.java @ 988f434e

1 e844c116 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.object;
21
22
import android.graphics.Canvas;
23
import android.graphics.Paint;
24
25 988f434e Leszek Koltunski
import org.distorted.library.effect.MatrixEffect;
26
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectRotate;
28
import org.distorted.library.effect.MatrixEffectScale;
29 e844c116 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32 988f434e Leszek Koltunski
import org.distorted.library.mesh.MeshJoined;
33 e844c116 Leszek Koltunski
import org.distorted.library.mesh.MeshRectangles;
34 988f434e Leszek Koltunski
import org.distorted.library.mesh.MeshTriangles;
35
import org.distorted.library.type.Static1D;
36 e844c116 Leszek Koltunski
import org.distorted.library.type.Static3D;
37
import org.distorted.library.type.Static4D;
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
41
public class RubikPyraminx extends RubikObject
42
{
43
  private static final Static3D[] AXIS = new Static3D[]
44
         {
45 988f434e Leszek Koltunski
           new Static3D(                     0,        1,                       0 ),
46
           new Static3D( (float)Math.sqrt(6)/3,  -1.0f/3,  -(float)Math.sqrt(3)/3 ),
47
           new Static3D(-(float)Math.sqrt(6)/3,  -1.0f/3,  -(float)Math.sqrt(3)/3 ),
48
           new Static3D(                     0,  -1.0f/3, 2*(float)Math.sqrt(2)/3 )
49 e844c116 Leszek Koltunski
         };
50
51
  private static final int[] FACE_COLORS = new int[]
52
         {
53
           0xffffff00, 0xff00ff00,  // AXIS[0]right (YELLOW) AXIS[1]right (GREEN )
54
           0xff0000ff, 0xffff0000   // AXIS[2]right (BLUE  ) AXIS[3]right (RED   )
55
         };
56
57
  private static final float[] LEGALQUATS = new float[]
58
         {
59
         // TODO;
60
         };
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64
  RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
65
    {
66
    super(size,quatCur,quatAcc,texture,mesh,effects);
67
    }
68
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
// TODO
71
72
  Static3D[] getCubitPositions(int size)
73
    {
74
    return null;
75
    }
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
  float[] getLegalQuats()
80
    {
81
    return LEGALQUATS;
82
    }
83
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
86
  int getNumFaces()
87
    {
88
    return FACE_COLORS.length;
89
    }
90
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
93
  Static3D[] getRotationAxis()
94
    {
95
    return AXIS;
96
    }
97
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100
  void createFaceTexture(Canvas canvas, Paint paint, int face)
101
    {
102
    // TODO
103
    }
104
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
107
  MeshBase createCubitMesh(int vertices)
108
    {
109 988f434e Leszek Koltunski
    final float SQ3 = (float)Math.sqrt(3);
110
    final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
111
    final int MESHES=4;
112
113
    MeshBase[] meshes = new MeshTriangles[MESHES];
114
    for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(5);
115
116
    MatrixEffect[] effects0 = new MatrixEffect[3];
117
    effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) );
118
    effects0[1] = new MatrixEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
119
    effects0[2] = new MatrixEffectMove( new Static3D(0,-SQ3/6,SQ3/12) );
120
121
    meshes[0].apply(effects0);
122
123
    Static1D angle = new Static1D(angleFaces);
124
    Static3D axis  = new Static3D(-1,0,0);
125
    Static3D center= new Static3D(0,-SQ3/6,-SQ3/6);
126
127
    MatrixEffect[] effects1 = new MatrixEffect[5];
128
    effects1[0] = effects0[0];
129
    effects1[1] = effects0[1];
130
    effects1[2] = effects0[2];
131
    effects1[3] = new MatrixEffectRotate( new Static1D(180), new Static3D(0,0,1), center );
132
    effects1[4] = new MatrixEffectRotate( angle, axis, center );
133
    meshes[1].apply(effects1);
134
135
    axis.set(0.5f,0,-SQ3/2);
136
    center.set2(SQ3/3);
137
    meshes[2].apply(effects1);
138
139
    axis.set2(SQ3/2);
140
    meshes[3].apply(effects1);
141
142
    return new MeshJoined(meshes);
143 e844c116 Leszek Koltunski
    }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
// PUBLIC API
147
148
  public int getBasicAngle()
149
    {
150
    return 3;
151
    }
152
}