Project

General

Profile

« Previous | Next » 

Revision ef231eba

Added by Leszek Koltunski over 3 years ago

Face cubit creation: progress, a cube rendered almost correctly :)

View differences:

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

  
266
android.util.Log.e("D", " buffer: "+mBuffer[0]+" "+mBuffer[1]+" "+mBuffer[2]);
267

  
268

  
269
    if( mBuffer[2]<0.0f )
270
      {
271
      mBuffer[0] *= -1.0f;
272
      mBuffer[1] *= -1.0f;
273
      mBuffer[2] *= -1.0f;
274
      }
265 275
    }
266 276

  
267 277
///////////////////////////////////////////////////////////////////////////////////////////////////
......
306 316
      }
307 317

  
308 318
    info.scale = Math.max(maxX-minX,maxY-minY);
319

  
309 320
    int len = vert3D.length;
310 321
    info.vertices = new float[2*len];
311 322

  
......
367 378

  
368 379
    computeNormalVector(vert3D,0,1,foundIndex);
369 380

  
370
    // rotate so that the normal vector becomes (0,0,1)
371
    float axisX = -mBuffer[1];
372
    float axisY =  mBuffer[0];
373
    float axisZ = 0.0f;
374

  
375
    float vecLen = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2];
376
    vecLen = (float)Math.sqrt(vecLen);
377
    mBuffer[0] /= vecLen;
378
    mBuffer[1] /= vecLen;
379
    mBuffer[2] /= vecLen;
380

  
381
    float axiLen = axisX*axisX + axisY*axisY + axisZ*axisZ;
382
    axiLen = (float)Math.sqrt(axiLen);
383
    axisX /= axiLen;
384
    axisY /= axiLen;
385
    axisZ /= axiLen;
386

  
387
    float cosTheta = mBuffer[2];
388
    float sinTheta = axiLen / vecLen;
389

  
390
    mQuat1[0] = axisX*sinTheta;
391
    mQuat1[1] = axisY*sinTheta;
392
    mQuat1[2] = axisZ*sinTheta;
393
    mQuat1[3] = cosTheta;
394
    mQuat2[0] = axisX*sinTheta;
395
    mQuat2[1] = axisY*sinTheta;
396
    mQuat2[2] = axisZ*sinTheta;
397
    mQuat2[3] = -cosTheta;
398

  
399
    for (float[] vert : vert3D)
381
    if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f )
400 382
      {
401
      quatMultiply(mQuat1, vert, mQuat3);
402
      quatMultiply(mQuat3, mQuat2, vert);
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;
393

  
394
      float axiLen = axisX*axisX + axisY*axisY + axisZ*axisZ;
395
      axiLen = (float)Math.sqrt(axiLen);
396
      axisX /= axiLen;
397
      axisY /= axiLen;
398
      axisZ /= axiLen;
399

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

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

  
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;
414

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

  
405 422
    // fit the whole thing in a square and remember the scale & 2D vertices
......
584 601
      }
585 602
    }
586 603

  
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605

  
606
  private void printInfo(FaceInfo info)
607
    {
608
    android.util.Log.e("D", "vx="+info.vx+" vy="+info.vy+" vz="+info.vz);
609
    android.util.Log.e("D", "qx="+info.qx+" qy="+info.qy+" qz="+info.qz+" qw="+info.qw);
610
    android.util.Log.e("D", "scale="+info.scale);
611

  
612
    String ver="";
613

  
614
    int len = info.vertices.length/2;
615

  
616
    for(int i =0; i<len; i++)
617
      {
618
      ver += ("("+info.vertices[2*i]+","+info.vertices[2*i+1]+") ");
619
      }
620

  
621
    android.util.Log.e("D", "vertices= "+ver);
622
    }
623

  
587 624
///////////////////////////////////////////////////////////////////////////////////////////////////
588 625

  
589 626
  MeshBase createRoundedSolid(final float[][] vertices, final int[][] vertIndexes, final float[][] bands, final int[] bandIndexes)

Also available in: Unified diff