Project

General

Profile

« Previous | Next » 

Revision b72400a3

Added by Leszek Koltunski 7 months ago

much better rot model for Ghosts. Should be fully correct in case of mode 'not always permitted' (i.e. when mGhostAngle does not divide basicAngle). In 'always permitted' mode (Ghost Pyramid!), we still need to do some more work.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObjectGhost.java
145 145
    {
146 146
    if( mGhostAngle!=0 )
147 147
      {
148
      int intAngle = (int)angle;
149 148
      int basicDeg = 360/mBasicAngles[axis][row];
150
      int numRot = (int)(angle/basicDeg + 0.5f);
151
      if( angle< -(basicDeg*0.5) ) numRot -= 1;
152
      int distToNormalAngle = Math.abs(intAngle-numRot*basicDeg);
153
      mNumRot = (int)(angle/ mGhostAngle + 0.5f);
154
      if( angle< -(mGhostAngle *0.5) ) mNumRot -= 1;
155
      int distToGhostAngle = Math.abs(intAngle-mNumRot*mGhostAngle);
156

  
157
      if( distToNormalAngle>distToGhostAngle && (!mBlocked || axis==mAxisParallelTo) )
149
      mNumRot = (int)(angle/mGhostAngle + 0.5f);
150
      if( angle< -(mGhostAngle*0.5) ) mNumRot -= 1;
151

  
152
      if( mModeAlwaysPermitted )
153
        {
154
        int max = basicDeg/mGhostAngle;
155
        while( mNumRot>= max ) mNumRot -= max;
156
        while( mNumRot<=-max ) mNumRot += max;
157
        }
158
      else if( !mBlocked || axis==mAxisParallelTo )
158 159
        {
159
        if( !mModeAlwaysPermitted )
160
        int intAngle = (int)angle;
161
        int numRows = mBasicAngles[axis].length;
162
        int numRot = (int)(angle/basicDeg + 0.5f);
163
        if( angle< -(basicDeg*0.5) ) numRot -= 1;
164
        int rowL = row==        0 ? mRowState[row+1] : mRowState[row-1];
165
        int rowR = row==numRows-1 ? mRowState[row-1] : mRowState[row+1];
166
        int maxRot = Math.min(rowL,rowR)+1 - mRowState[row];
167
        int minRot = Math.max(rowL,rowR)-1 - mRowState[row];
168
        int minDist = Integer.MAX_VALUE;
169

  
170
        for(int r=minRot; r<=maxRot; r++)
160 171
          {
161
          int numRows = mBasicAngles[axis].length;
162
          int thisRow = mRowState[row];
172
          int dist = Math.abs(intAngle - numRot*basicDeg - r*mGhostAngle);
163 173

  
164
          boolean can1U = (row==numRows-1 || thisRow>=mRowState[row+1]) && (row==0 || thisRow>=mRowState[row-1]);
165
          boolean can1D = (row==numRows-1 || thisRow<=mRowState[row+1]) && (row==0 || thisRow<=mRowState[row-1]);
166
          boolean can2U = (row==numRows-1 || thisRow> mRowState[row+1]) && (row==0 || thisRow> mRowState[row-1]);
167
          boolean can2D = (row==numRows-1 || thisRow< mRowState[row+1]) && (row==0 || thisRow< mRowState[row-1]);
168

  
169
          int maxU = can2U ? -2 : (can1U ? -1 : 0);
170
          int maxD = can2D ?  2 : (can1D ?  1 : 0);
171

  
172
          if( mNumRot>maxD ) mNumRot = maxD;
173
          if( mNumRot<maxU ) mNumRot = maxU;
174
          if( dist<minDist )
175
            {
176
            minDist = dist;
177
            mNumRot = r;
178
            }
174 179
          }
175

  
176
        return mNumRot*mGhostAngle;
177 180
        }
181
      else
182
        {
183
        mNumRot=0;
184
        }
185

  
186
      return mNumRot*mGhostAngle;
178 187
      }
179 188

  
180 189
    return 0;
src/main/java/org/distorted/objectlib/objects/TwistyGhostCube.java
51 51
  public String printColor(int color) { return color>=0 ? ShapeColors.getColorName(FACE_COLORS[color]) : "UNKNOWN"; }
52 52

  
53 53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
// mGhostAngle must be >=0 and <= (360/mBasicAngles[mGhostAxis][0])/2  [here: >=0 and <=45]
54 55

  
55 56
  @Override public int getGhostAngle()
56 57
    {
src/main/java/org/distorted/objectlib/objects/TwistyGhostPyramid.java
52 52
  public String printColor(int color) { return color>=0 ? ShapeColors.getColorName(FACE_COLORS[color]) : "UNKNOWN"; }
53 53

  
54 54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
// mGhostAngle must be >=0 and <= (360/mBasicAngles[mGhostAxis][0])/2 [here: >=0 and <=60]
55 56

  
56 57
  @Override public int getGhostAngle()      { return 60; }
57 58
  @Override public int[] getColorTable()    { return FACE_COLORS; }

Also available in: Unified diff