Project

General

Profile

« Previous | Next » 

Revision e7daa161

Added by Leszek Koltunski over 2 years ago

- remove the retarded NODE_RATIO from TwistyObject
- more correctly estimate Cuboid's 'realSize' as an average of their 3 sizes.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
82 82
  public static final float SQ5 = (float)Math.sqrt(5);
83 83
  public static final float SQ6 = (float)Math.sqrt(6);
84 84

  
85
  private static final float NODE_RATIO = 1.60f;
86 85
  private static final float MAX_SIZE_CHANGE = 1.35f;
87 86
  private static final float MIN_SIZE_CHANGE = 0.75f;
88 87

  
......
103 102
  private final Static3D[] mAxis;
104 103
  private final float[][] mCuts;
105 104
  private final int[] mNumCuts;
106
  private final int mNodeSize;
105
  private final int mNodeW, mNodeH;
107 106
  private final float[][] mOrigPos;
108 107
  private final Static3D mNodeScale;
109 108
  private final Static4D mQuat;
110 109
  private final int[] mNumLayers;
111
  private final int mRealSize;
110
  private final float mRealSize;
112 111
  private final DistortedEffects mEffects;
113 112
  private final VertexEffectRotate mRotateEffect;
114 113
  private final Dynamic1D mRotationAngle;
......
139 138

  
140 139
///////////////////////////////////////////////////////////////////////////////////////////////////
141 140

  
142
  TwistyObject(int[] numLayers, int realSize, Static4D quat, Static3D move, DistortedTexture nodeTexture,
143
               MeshSquare nodeMesh, DistortedEffects nodeEffects, Resources res, int screenWidth)
141
  TwistyObject(int[] numLayers, float realSize, Static4D quat, Static3D move, DistortedTexture nodeTexture,
142
               MeshSquare nodeMesh, DistortedEffects nodeEffects, Resources res, int surfaceW, int surfaceH)
144 143
    {
145 144
    super(nodeTexture,nodeEffects,nodeMesh);
146 145

  
147
    mNodeSize = screenWidth;
146
    mNodeW = surfaceW;
147
    mNodeH = surfaceH;
148 148

  
149
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
149
    resizeFBO(mNodeW,mNodeH);
150 150

  
151 151
    mNumLayers = numLayers;
152 152
    mRealSize = realSize;
153 153
    mOrigPos = getCubitPositions(mNumLayers);
154 154
    mAxis = getRotationAxis();
155 155
    mInitScreenRatio = getScreenRatio();
156
    mObjectScreenRatio = 1.0f;
157 156
    mNumCubitFaces = getNumCubitFaces();
158 157
    mSolvedFunctionIndex = getSolvedFunctionIndex();
159 158

  
......
190 189

  
191 190
    mQuatDebug = new int[NUM_CUBITS];
192 191

  
193
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
194
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
195

  
196
    mNodeScale= new Static3D(screenWidth,NODE_RATIO*screenWidth,screenWidth);
192
    mNodeScale= new Static3D(surfaceW,surfaceH,surfaceW);
197 193
    mQuat = quat;
198 194

  
199 195
    mRotationAngle= new Dynamic1D();
......
204 200
    mRotationAngleMiddle = new Static1D(0);
205 201
    mRotationAngleFinal  = new Static1D(0);
206 202

  
207
    float scale  = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
208
    mObjectScale = new Static3D(scale,scale,scale);
203
    mObjectScale = new Static3D(1,1,1);
204
    setObjectRatioNow(1.0f);
205

  
209 206
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
210 207
    MatrixEffectQuaternion quatEffect  = new MatrixEffectQuaternion(quat, CENTER);
211 208
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
......
247 244

  
248 245
    float fov = getFOV();
249 246
    double halfFOV = fov * (Math.PI/360);
250
    mCameraDist = 0.5f*NODE_RATIO / (float)Math.tan(halfFOV);
247
    mCameraDist = (0.5f*mNodeH) / ((float)Math.tan(halfFOV)*mNodeW);
251 248

  
252 249
    setProjection( fov, 0.1f);
253 250
    }
......
1098 1095

  
1099 1096
///////////////////////////////////////////////////////////////////////////////////////////////////
1100 1097

  
1101
  void recomputeScaleFactor(int scrWidth)
1098
  void recomputeScaleFactor(int surfaceW, int surfaceH)
1102 1099
    {
1103
    mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth);
1100
    mNodeScale.set(surfaceW,surfaceH,surfaceW);
1104 1101
    }
1105 1102

  
1106 1103
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1146 1143
  void setObjectRatioNow(float sc)
1147 1144
    {
1148 1145
    mObjectScreenRatio = sc;
1149
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
1146
    int nodeMinSize = Math.min(mNodeW,mNodeH);
1147
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeMinSize/mRealSize;
1150 1148
    mObjectScale.set(scale,scale,scale);
1151 1149
    }
1152 1150

  
......
1159 1157
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1160 1158
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1161 1159

  
1162
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
1163
    mObjectScale.set(scale,scale,scale);
1160
    setObjectRatioNow(mObjectScreenRatio);
1164 1161
    }
1165 1162

  
1166 1163
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1250 1247

  
1251 1248
///////////////////////////////////////////////////////////////////////////////////////////////////
1252 1249

  
1253
  public int getNodeSize()
1250
  public int getNodeWidth()
1254 1251
    {
1255
    return mNodeSize;
1252
    return mNodeW;
1256 1253
    }
1257 1254

  
1258 1255
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff