Project

General

Profile

« Previous | Next » 

Revision fbd18fc7

Added by Leszek Koltunski almost 2 years ago

Crazy Planets: progress

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
151 151
  private int[][] mBasicAngles;
152 152
  private int mIconMode;
153 153
  private final InitData mInitData;
154
  private float[][] mRowOffset;
154
  private float[][] mRowOffsets;
155
  private boolean[] mBelongs;
156
  private float[] mTmp;
155 157

  
156 158
  //////////////////// SOLVED1 ////////////////////////
157 159

  
......
196 198
    mObjectQuats = getQuats();
197 199
    mNumQuats = mObjectQuats.length;
198 200
    mOrigPos = getCubitPositions(mNumLayers);
201
    mRowOffsets = new float[getNumFaces()][3];
202
    mTmp = new float[4];
199 203

  
200 204
    int numAxis = mAxis.length;
201 205
    mMaxNumLayers = -1;
......
210 214
    mNumCubits = mOrigPos.length;
211 215
    mNumFaceColors = getNumFaceColors();
212 216
    mNumAxis = mAxis.length;
213
    mRowOffset = getRowOffset();
217
    mBelongs = new boolean[mNumCubits];
214 218

  
215 219
    int scramblingType = getScrambleType();
216 220
    ScrambleState[] states = getScrambleStates();
......
411 415

  
412 416
    for(int i=0; i<mNumCubits; i++)
413 417
      {
414
      mCubits[i] = new Cubit(this,mOrigPos[i], mNumAxis,i);
418
      mCubits[i] = new Cubit(this,mOrigPos[i],mNumAxis,i);
415 419
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
416 420
      }
417 421
    }
......
578 582

  
579 583
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
580 584
    {
581
    ObjectShape shape = getObjectShape(variant);
582
    float[][] vertices = shape.getVertices();
585
    float[][] vertices = mShapes[variant].getVertices();
583 586
    Static3D[] axis = getFaceAxis();
584 587
    float[] dist3D = getDist3D(mNumLayers);
585 588

  
......
715 718

  
716 719
///////////////////////////////////////////////////////////////////////////////////////////////////
717 720

  
718
  public float[][] getRowOffset()
721
  public int getCubitRotationType(int cubit)
719 722
    {
720
    return new float[mNumCubits][3];
723
    return Cubit.TYPE_NORMAL;
724
    }
725

  
726
///////////////////////////////////////////////////////////////////////////////////////////////////
727

  
728
  float[] getCharacteristicVertex(int cubitIndex, int cubitType)
729
    {
730
    if( cubitType!=Cubit.TYPE_NORMAL )
731
      {
732
      int variant = getCubitVariant(cubitIndex,mNumLayers);
733
      int[][] indices = mShapes[variant].getVertIndices();
734
      int faces = indices.length;
735
      int outer=-1;
736

  
737
      for(int i=0; i<faces; i++)
738
        {
739
        if( mVariantFaceIsOuter[variant][i]==1 )
740
          {
741
          outer=i;
742
          break;
743
          }
744
        }
745

  
746
      if( outer>=0 )
747
        {
748
        int vertIndex = indices[outer][0];
749
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
750
        float[] ret = new float[3];
751
        float[] curpos = mOrigPos[cubitIndex];
752
        Static4D quat = mOrigQuat[cubitIndex];
753
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
754

  
755
        ret[0] = mTmp[0]+computeAvg(curpos,0);
756
        ret[1] = mTmp[1]+computeAvg(curpos,1);
757
        ret[2] = mTmp[2]+computeAvg(curpos,2);
758

  
759
        return ret;
760
        }
761
      else
762
        {
763
        android.util.Log.e("D", "Error in getCharacteristic vertex: no outer face??");
764
        }
765
      }
766

  
767
    return null;
768
    }
769

  
770
///////////////////////////////////////////////////////////////////////////////////////////////////
771

  
772
  public int computeCurrentPuzzleFace(int type, float[] vertex)
773
    {
774
    if( type!=Cubit.TYPE_NORMAL )
775
      {
776
      Static3D[] axis = getFaceAxis();
777
      float[] dist3D = getDist3D(mNumLayers);
778
      final float MAXERR = 0.98f;
779
      int numAxis = axis.length;
780
      float x = vertex[0];
781
      float y = vertex[1];
782
      float z = vertex[2];
783

  
784
      for(int i=0; i<numAxis; i++)
785
        {
786
        Static3D ax = axis[i];
787
        float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
788
        if( len>mSize*dist3D[i]*MAXERR ) return i;
789
        }
790
      }
791

  
792
    return -1;
793
    }
794

  
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796

  
797
  public float[] getCubitRowOffset(int cubitIndex)
798
    {
799
    return null;
800
    }
801

  
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803

  
804
  void setRotationRowOffset(int puzzleFace, float[] offset)
805
    {
806
    mRowOffsets[puzzleFace][0] = offset[0];
807
    mRowOffsets[puzzleFace][1] = offset[1];
808
    mRowOffsets[puzzleFace][2] = offset[2];
721 809
    }
722 810

  
723 811
///////////////////////////////////////////////////////////////////////////////////////////////////
......
941 1029

  
942 1030
///////////////////////////////////////////////////////////////////////////////////////////////////
943 1031

  
944
  int computeRow(float[] pos, int axisIndex, int cubitIndex)
1032
  int computeRow(float[] pos, int axisIndex, int cubitType, int puzzleFace)
945 1033
    {
946 1034
    int ret=0;
947 1035
    int len = pos.length / 3;
......
949 1037
    float axisX = axis.get0();
950 1038
    float axisY = axis.get1();
951 1039
    float axisZ = axis.get2();
952
    float casted;
1040
    float casted, xoff=0, yoff=0, zoff=0;
953 1041

  
954
    float xoff = mRowOffset[cubitIndex][0];
955
    float yoff = mRowOffset[cubitIndex][1];
956
    float zoff = mRowOffset[cubitIndex][2];
1042
    if( cubitType!=Cubit.TYPE_NORMAL )
1043
      {
1044
      xoff = mRowOffsets[puzzleFace][0];
1045
      yoff = mRowOffsets[puzzleFace][1];
1046
      zoff = mRowOffsets[puzzleFace][2];
1047
      }
957 1048

  
958 1049
    for(int i=0; i<len; i++)
959 1050
      {
......
1028 1119
                                                            // at the moment this is always true as
1029 1120
                                                            // there are no bandaged objects with
1030 1121
                                                            // different per-layer BasicAngles.
1031
        quat     = makeQuaternion(axis,angle);
1122
        quat = makeQuaternion(axis,angle);
1123

  
1124
        for(int j=0; j<mNumCubits; j++)
1125
          {
1126
          mBelongs[j] = belongsToRotation(j,axis,rowBitmap);
1127
          if( mBelongs[j] ) mCubits[j].rotateCubit(quat);
1128
          }
1032 1129

  
1033 1130
        for(int j=0; j<mNumCubits; j++)
1034
          if( belongsToRotation(j,axis,rowBitmap) )
1131
          {
1132
          if( mBelongs[j] )
1035 1133
            {
1036
            index = mCubits[j].removeRotationNow(quat);
1134
            index = mCubits[j].postRotateCubit(quat);
1037 1135
            setCubitQuat(j,mCubits[j].computeAssociation(),index);
1038 1136
            }
1137
          else if( mCubits[j].getCubitType()==Cubit.TYPE_FOLLOWER )
1138
            {
1139
            mCubits[j].adjustRotRowPostRotateADecider();
1140
            setCubitQuat(j,mCubits[j].computeAssociation(),mCubits[j].mQuatIndex);
1141
            }
1142
          }
1039 1143
        }
1040 1144
      }
1041 1145
    }
......
1089 1193
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
1090 1194
// Do so only if minimal Error is appropriately low (shape-shifting puzzles - Square-1)
1091 1195

  
1092
  int clampPos(float[] pos, int offset)
1196
  void clampPos(float[] pos, int offset)
1093 1197
    {
1094 1198
    float currError, minError = Float.MAX_VALUE;
1095 1199
    int minErrorIndex1 = -1;
......
1127 1231
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1128 1232
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1129 1233
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1130
      return minErrorIndex1;
1131 1234
      }
1132

  
1133
    return 0;
1134 1235
    }
1135 1236

  
1136 1237
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1223 1324
    mRotationAngleStatic.set0(0);
1224 1325

  
1225 1326
    for(int i=0; i<mNumCubits; i++)
1226
      if( belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap) )
1327
      {
1328
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1329
      if( mBelongs[i] ) mCubits[i].rotateCubit(quat);
1330
      }
1331

  
1332
    for(int i=0; i<mNumCubits; i++)
1333
      {
1334
      if( mBelongs[i] )
1227 1335
        {
1228
        int index = mCubits[i].removeRotationNow(quat);
1336
        int index = mCubits[i].postRotateCubit(quat);
1229 1337
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1230 1338
        }
1339
      else if( mCubits[i].getCubitType()==Cubit.TYPE_FOLLOWER )
1340
        {
1341
        mCubits[i].adjustRotRowPostRotateADecider();
1342
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1343
        }
1344
      }
1231 1345
    }
1232 1346

  
1233 1347
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1412 1526

  
1413 1527
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1414 1528
        {
1415
        mCubits[i].modifyCurrentPosition(mObjectQuats[mQuatDebug[i]]);
1529
        mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1530
        }
1531
      else
1532
        {
1533
        error = true;
1534
        }
1535
      }
1536

  
1537
    for(int i=0; i<mNumCubits; i++)
1538
      {
1539
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1540
        {
1541
        mCubits[i].computeRotationRow();
1416 1542
        setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1417 1543
        }
1418 1544
      else

Also available in: Unified diff