Project

General

Profile

« Previous | Next » 

Revision 140f2c4e

Added by Leszek Koltunski over 3 years ago

Face cubit creation: progress, a cube renders correctly :)

View differences:

src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
263 263
    mBuffer[1] = v1z*v2x - v2z*v1x;
264 264
    mBuffer[2] = v1x*v2y - v2x*v1y;
265 265

  
266
android.util.Log.e("D", " buffer: "+mBuffer[0]+" "+mBuffer[1]+" "+mBuffer[2]);
266
    float len = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
267
    len = (float)Math.sqrt(len);
268
    mBuffer[0] /= len;
269
    mBuffer[1] /= len;
270
    mBuffer[2] /= len;
267 271

  
268

  
269
    if( mBuffer[2]<0.0f )
270
      {
271
      mBuffer[0] *= -1.0f;
272
      mBuffer[1] *= -1.0f;
273
      mBuffer[2] *= -1.0f;
274
      }
272
//android.util.Log.e("D", " normal: "+mBuffer[0]+" "+mBuffer[1]+" "+mBuffer[2]);
275 273
    }
276 274

  
277 275
///////////////////////////////////////////////////////////////////////////////////////////////////
......
378 376

  
379 377
    computeNormalVector(vert3D,0,1,foundIndex);
380 378

  
379
    // rotate so that the normal vector becomes (0,0,1)
380
    float axisX, axisY, axisZ;
381

  
381 382
    if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f )
382 383
      {
383
      // rotate so that the normal vector becomes (0,0,1)
384
      float axisX = -mBuffer[1];
385
      float axisY =  mBuffer[0];
386
      float axisZ = 0.0f;
387

  
388
      float vecLen = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
389
      vecLen = (float)Math.sqrt(vecLen);
390
      mBuffer[0] /= vecLen;
391
      mBuffer[1] /= vecLen;
392
      mBuffer[2] /= vecLen;
384
      axisX = -mBuffer[1];
385
      axisY =  mBuffer[0];
386
      axisZ = 0.0f;
393 387

  
394 388
      float axiLen = axisX*axisX + axisY*axisY + axisZ*axisZ;
395 389
      axiLen = (float)Math.sqrt(axiLen);
396 390
      axisX /= axiLen;
397 391
      axisY /= axiLen;
398 392
      axisZ /= axiLen;
393
      }
394
    else
395
      {
396
      axisX = 0.0f;
397
      axisY = 1.0f;
398
      axisZ = 0.0f;
399
      }
399 400

  
400
      float cosTheta = mBuffer[2];
401
      //float sinTheta = axiLen / vecLen;
401
    float cosTheta = mBuffer[2];
402
  //float sinTheta = axiLen / vecLen;
402 403

  
403
      float sinHalfTheta = (float)Math.sqrt(0.5f*(1-cosTheta));
404
      float cosHalfTheta = (float)Math.sqrt(0.5f*(1+cosTheta));
404
    float sinHalfTheta = (float)Math.sqrt(0.5f*(1-cosTheta));
405
    float cosHalfTheta = (float)Math.sqrt(0.5f*(1+cosTheta));
405 406

  
406
      mQuat1[0] = axisX*sinHalfTheta;
407
      mQuat1[1] = axisY*sinHalfTheta;
408
      mQuat1[2] = axisZ*sinHalfTheta;
409
      mQuat1[3] = cosHalfTheta;
410
      mQuat2[0] = axisX*sinHalfTheta;
411
      mQuat2[1] = axisY*sinHalfTheta;
412
      mQuat2[2] = axisZ*sinHalfTheta;
413
      mQuat2[3] = -cosHalfTheta;
407
    mQuat1[0] = axisX*sinHalfTheta;
408
    mQuat1[1] = axisY*sinHalfTheta;
409
    mQuat1[2] = axisZ*sinHalfTheta;
410
    mQuat1[3] = cosHalfTheta;
411
    mQuat2[0] = axisX*sinHalfTheta;
412
    mQuat2[1] = axisY*sinHalfTheta;
413
    mQuat2[2] = axisZ*sinHalfTheta;
414
    mQuat2[3] = -cosHalfTheta;
414 415

  
415
      for (float[] vert : vert3D)
416
        {
417
        quatMultiply(mQuat1, vert, mQuat3);
418
        quatMultiply(mQuat3, mQuat2, vert);
419
        }
416
    for (float[] vert : vert3D)
417
      {
418
      quatMultiply(mQuat1, vert, mQuat3);
419
      quatMultiply(mQuat3, mQuat2, vert);
420 420
      }
421 421

  
422 422
    // fit the whole thing in a square and remember the scale & 2D vertices
......
594 594
      for(int previous=0; previous<face; previous++)
595 595
        {
596 596
        info = mFaceInfo.get(previous);
597
        if( tryFindingRotation(info,newInfo.vertices) ) break;
597
        if( tryFindingRotation(newInfo,info.vertices) )
598
          {
599
          android.util.Log.e("D", "comparing face "+face+" to "+previous+" SUCCESS!!");
600
          break;
601
          }
598 602
        }
599 603

  
600 604
      mFaceInfo.add(newInfo);
......
637 641
    for(int face=0; face<numFaces; face++)
638 642
      {
639 643
      info = mFaceInfo.get(face);
644

  
645
      android.util.Log.d("D", "--------------");
646
      printInfo(info);
647

  
640 648
      band = bands[bandIndexes[face]];
641 649
      bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]);
642 650
      meshes[face] = new MeshPolygon(info.vertices,bandsComputed,(int)band[5],(int)band[6]);
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
31 31
import org.distorted.library.effect.EffectType;
32 32
import org.distorted.library.effect.MatrixEffectQuaternion;
33 33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffect;
35
import org.distorted.library.effect.VertexEffectDeform;
36 34
import org.distorted.library.effect.VertexEffectDisappear;
37
import org.distorted.library.effect.VertexEffectRotate;
38 35
import org.distorted.library.main.DistortedEffects;
39 36
import org.distorted.library.main.DistortedLibrary;
40 37
import org.distorted.library.main.DistortedScreen;
......
54 51
import javax.microedition.khronos.opengles.GL10;
55 52

  
56 53
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
57
import static org.distorted.examples.meshfile.FactoryCubit.COS18;
58
import static org.distorted.examples.meshfile.FactoryCubit.SIN18;
59 54

  
60 55
///////////////////////////////////////////////////////////////////////////////////////////////////
61 56

  
......
65 60
    private static final float SQ3 = (float)Math.sqrt(3);
66 61
    private final float DEFAULT_SCALE = 0.3f;
67 62

  
68
    private GLSurfaceView mView;
63
    private final GLSurfaceView mView;
69 64
    private DistortedTexture mTexture;
70
    private DistortedScreen mScreen;
71
    private DistortedEffects mEffects;
72
    private Static3D mScale;
65
    private final DistortedScreen mScreen;
66
    private final DistortedEffects mEffects;
67
    private final Static3D mScale;
73 68
    private long mTime;
74 69
    private float mCurrentScale;
75 70
    private MeshBase mMesh;
......
258 253

  
259 254
  private MeshBase createStaticMesh()
260 255
    {
261
    /*
262
    MeshBase triangle = new MeshTriangle(5);
263

  
264
    VertexEffectMove move = new VertexEffectMove( new Static3D(1,0,0) );
265
    triangle.apply(move);
266

  
267
    triangle.mergeEffComponents();
268

  
269
    VertexEffectScale scale = new VertexEffectScale( new Static3D(2,1,1) );
270
    triangle.apply(scale);
271

  
272
    return triangle;
273
     */
274
/*
275
    final float DIST  = 0.2f;
276
    float[] vertices = new float[6];
277

  
278
    vertices[0] =  0.5f-DIST;
279
    vertices[1] = -0.5f-DIST;
280

  
281
    vertices[2] =  0.5f-DIST;
282
    vertices[3] =  0.5f-DIST;
283

  
284
    vertices[4] = -0.5f-DIST;
285
    vertices[5] =  0.5f-DIST;
286

  
287
    float[] bands0 = new float[] {1.0f, 0.0f, 0.5f, 0.03f, 0.0f, 0.05f};
288

  
289
    MeshBase mesh = new MeshPolygon(vertices,bands0,0,0);
290
    mesh.setShowNormals(true);
291

  
292
    return mesh;
293
    */
294

  
295 256
    final float IVY_D = 0.10f;
296 257
    final int   IVY_N = 8;
297 258

  
......
344 305

  
345 306
      final int[][] vertIndexes = new int[][]
346 307
          {
347
              {0,1,3,2},
348
              {5,4,6,7},
349
              {5,1,0,4},
350
              {6,2,3,7},
351
              {4,0,2,6},
352
              {1,5,7,3}
308
              {2,3,1,0},   // counterclockwise!
309
              {7,6,4,5},
310
              {4,0,1,5},
311
              {7,3,2,6},
312
              {6,2,0,4},
313
              {3,7,5,1}
353 314
          };
354 315

  
355 316
      final float[][] bands = new float[][]
356 317
          {
357
              {0.048f,35,0.5f,0.7f,5,  2,2}
318
              {0.05f,45,0.6f,0.5f,5,  2,2}
358 319
          };
359 320

  
360 321
      final int[] bandIndexes = new int[] { 0,0,0,0,0,0 };

Also available in: Unified diff