Project

General

Profile

« Previous | Next » 

Revision 33bd5234

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/examples/meshjoin/MeshJoinRenderer.java
129 129
      if( mTexture==null ) mTexture = new DistortedTexture();
130 130
      mTexture.setTexture(bitmap);
131 131

  
132
      if( mMesh==null ) mMesh = createJoinedMesh();
132
      if( mMesh==null ) mMesh = createJoinedTetrahedron();
133 133

  
134 134
     // mMesh.setShowNormals(true);
135 135

  
......
146 146
        }
147 147
      }
148 148

  
149

  
149 150
///////////////////////////////////////////////////////////////////////////////////////////////////
150 151

  
151
    private MeshBase createJoinedMesh()
152
    private MeshBase createJoinedDoubleQuad()
152 153
      {
153
      /*
154 154
      MeshBase[] meshes = new MeshBase[2];
155 155
      meshes[0] = new MeshQuad();
156 156
      meshes[1] = new MeshQuad();
......
164 164
      effects1[0] = new MatrixEffectMove( new Static3D(0,-0.6f,0));
165 165

  
166 166
      meshes[1].apply(effects1);
167
      */
168
      /*
167

  
168
      return new MeshJoined(meshes);
169
      }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
    private MeshBase createJoinedSphereAndTriangle()
174
      {
169 175
      MeshBase[] meshes = new MeshBase[2];
170 176
      meshes[0] = new MeshSphere(5);
171 177
      meshes[1] = new MeshTriangles(5);
......
181 187
      effects1[1] = new MatrixEffectMove( new Static3D(-0.25f,0,0));
182 188

  
183 189
      meshes[1].apply(effects1);
184
      */
190

  
191
      return new MeshJoined(meshes);
192
      }
193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

  
196
    private MeshBase createJoinedCube()
197
      {
185 198
      final int MESHES=6;
186 199

  
187 200
      Static3D axisY  = new Static3D(0,1,0);
......
217 230
      MeshJoined result = new MeshJoined(meshes);
218 231

  
219 232
      Static4D[] maps = new Static4D[MESHES];
220
      maps[0] = new Static4D(3.0f/8, 3.0f/8, 1.0f/8, 2.0f/8);
221
      maps[1] = new Static4D(5.0f/8, 3.0f/8, 1.0f/8, 2.0f/8);
222
      maps[2] = new Static4D(3.0f/8, 5.0f/8, 1.0f/8, 2.0f/8);
223
      maps[3] = new Static4D(1.0f/8, 5.0f/8, 1.0f/8, 2.0f/8);
224
      maps[4] = new Static4D(5.0f/8, 1.0f/8, 1.0f/8, 2.0f/8);
225
      maps[5] = new Static4D(5.0f/8, 5.0f/8, 1.0f/8, 2.0f/8);
226

  
227
      result.setTextureMap(maps);
228 233

  
229 234
      maps[0] = new Static4D(3.0f/8, 3.0f/8, 2.0f/8, 2.0f/8);
230 235
      maps[1] = new Static4D(5.0f/8, 1.0f/8, 2.0f/8, 2.0f/8);
......
236 241
      result.setTextureMap(maps);
237 242
      return result;
238 243
      }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
    private MeshBase createJoinedTetrahedron()
248
      {
249
      final float SQ3 = (float)Math.sqrt(3);
250
      final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
251
      final int MESHES=4;
252

  
253
      MeshBase[] meshes = new MeshTriangles[MESHES];
254
      for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(5);
255

  
256
      MatrixEffect[] effects0 = new MatrixEffect[3];
257
      effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) );
258
      effects0[1] = new MatrixEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
259
      effects0[2] = new MatrixEffectMove( new Static3D(0,-SQ3/6,SQ3/12) );
260

  
261
      meshes[0].apply(effects0);
262

  
263
      Static1D angle = new Static1D(angleFaces);
264
      Static3D axis  = new Static3D(-1,0,0);
265
      Static3D center= new Static3D(0,-SQ3/6,-SQ3/6);
266

  
267
      MatrixEffect[] effects1 = new MatrixEffect[5];
268
      effects1[0] = effects0[0];
269
      effects1[1] = effects0[1];
270
      effects1[2] = effects0[2];
271
      effects1[3] = new MatrixEffectRotate( new Static1D(180), new Static3D(0,0,1), center );
272
      effects1[4] = new MatrixEffectRotate( angle, axis, center );
273
      meshes[1].apply(effects1);
274

  
275
      axis.set(0.5f,0,-SQ3/2);
276
      center.set2(SQ3/3);
277
      meshes[2].apply(effects1);
278

  
279
      axis.set2(SQ3/2);
280
      meshes[3].apply(effects1);
281

  
282
      return new MeshJoined(meshes);
283
      }
239 284
}

Also available in: Unified diff