Project

General

Profile

« Previous | Next » 

Revision 988f434e

Added by Leszek Koltunski almost 5 years ago

Progress with of Pyraminx.
Bugfix for joining a single Mesh!

View differences:

src/main/java/org/distorted/object/RubikPyraminx.java
22 22
import android.graphics.Canvas;
23 23
import android.graphics.Paint;
24 24

  
25
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;
25 29
import org.distorted.library.main.DistortedEffects;
26 30
import org.distorted.library.main.DistortedTexture;
27 31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.mesh.MeshJoined;
28 33
import org.distorted.library.mesh.MeshRectangles;
34
import org.distorted.library.mesh.MeshTriangles;
35
import org.distorted.library.type.Static1D;
29 36
import org.distorted.library.type.Static3D;
30 37
import org.distorted.library.type.Static4D;
31 38

  
......
35 42
{
36 43
  private static final Static3D[] AXIS = new Static3D[]
37 44
         {
38
           new Static3D(                     0,                       0,       1 ),
39
           new Static3D( (float)Math.sqrt(6)/3,  -(float)Math.sqrt(3)/3, -1.0f/3 ),
40
           new Static3D(-(float)Math.sqrt(6)/3,  -(float)Math.sqrt(3)/3, -1.0f/3 ),
41
           new Static3D(                     0, 2*(float)Math.sqrt(2)/3, -1.0f/3 )
45
           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 )
42 49
         };
43 50

  
44 51
  private static final int[] FACE_COLORS = new int[]
......
96 103
    }
97 104

  
98 105
///////////////////////////////////////////////////////////////////////////////////////////////////
99
// TODO
100 106

  
101 107
  MeshBase createCubitMesh(int vertices)
102 108
    {
103
    return null;
109
    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);
104 143
    }
105 144

  
106 145
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff