Project

General

Profile

« Previous | Next » 

Revision 7ba38dd4

Added by Leszek Koltunski over 2 years ago

Major change: separate the notion of a TwistyObject and its Node. Now,

1) the Node stays when we change objects (this makes transitions faster)
2) it's possible to just create an Object without adding it to the Screen (now app needs to explicitly create the Node and add it to its Screen itself)

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
41 41
import org.distorted.library.mesh.MeshBase;
42 42
import org.distorted.library.mesh.MeshFile;
43 43
import org.distorted.library.mesh.MeshJoined;
44
import org.distorted.library.mesh.MeshSquare;
45 44
import org.distorted.library.message.EffectListener;
46 45
import org.distorted.library.type.Dynamic1D;
47 46
import org.distorted.library.type.Static1D;
......
68 67

  
69 68
///////////////////////////////////////////////////////////////////////////////////////////////////
70 69

  
71
public abstract class TwistyObject extends DistortedNode
70
public abstract class TwistyObject
72 71
  {
73 72
  public static final int COLOR_YELLOW = 0xffffff00;
74 73
  public static final int COLOR_WHITE  = 0xffffffff;
......
108 107
  private final Static3D[] mAxis;
109 108
  private final float[][] mCuts;
110 109
  private final int[] mNumCuts;
111
  private final int mNodeW, mNodeH;
112 110
  private final float[][] mOrigPos;
113
  private final Static3D mNodeScale;
114 111
  private final Static4D mQuat;
115 112
  private final int[] mNumLayers;
116 113
  private final float mSize;
......
120 117
  private final Static3D mRotationAxis;
121 118
  private final Static3D mObjectScale;
122 119
  private final int[] mQuatDebug;
123
  private final float mCameraDist;
124 120
  private final Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
125 121
  private final DistortedTexture mTexture;
126 122
  private final float mInitScreenRatio;
......
138 134
  private Movement mMovement;
139 135
  private boolean[][] mLayerRotatable;
140 136
  private int[][][] mEnabled;
137
  private DistortedNode mNode;
141 138

  
142 139
  //////////////////// SOLVED1 ////////////////////////
143 140

  
......
147 144

  
148 145
///////////////////////////////////////////////////////////////////////////////////////////////////
149 146

  
150
  TwistyObject(int[] numLayers, float size, Static4D quat, Static3D move, DistortedTexture nodeTexture,
151
               MeshSquare nodeMesh, DistortedEffects nodeEffects, Resources res, int surfaceW, int surfaceH)
147
  TwistyObject(int[] numLayers, float size, Static4D quat, Static3D move, Resources res)
152 148
    {
153
    super(nodeTexture,nodeEffects,nodeMesh);
154

  
155
    mNodeW = surfaceW;
156
    mNodeH = surfaceH;
157

  
158
    resizeFBO(mNodeW,mNodeH);
159

  
160 149
    mNumLayers = numLayers;
161 150
    mSize = size;
162 151
    mOrigPos = getCubitPositions(mNumLayers);
......
195 184
      }
196 185

  
197 186
    mIsBandaged = bandaged;
198

  
199 187
    mQuatDebug = new int[NUM_CUBITS];
200

  
201
    mNodeScale= new Static3D(surfaceW,surfaceH,surfaceW);
202 188
    mQuat = quat;
203 189

  
204 190
    mRotationAngle= new Dynamic1D();
......
210 196
    mRotationAngleFinal  = new Static1D(0);
211 197

  
212 198
    mObjectScale = new Static3D(1,1,1);
213
    setObjectRatioNow(1.0f);
199
    setObjectRatioNow(1.0f,720);
214 200

  
215 201
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
216 202
    MatrixEffectQuaternion quatEffect  = new MatrixEffectQuaternion(quat, CENTER);
217 203
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
218 204

  
219
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
220
    nodeEffects.apply(nodeScaleEffect);
221

  
222 205
    mNumTexCols = NUM_STICKERS_IN_ROW;
223 206
    mNumTexRows = (NUM_TEXTURES+1)/NUM_STICKERS_IN_ROW;
224 207

  
......
245 228
    mEffects.apply(scaleEffect);
246 229
    mEffects.apply(moveEffect);
247 230

  
248
    // Now postprocessed effects (the glow when you solve an object) require component centers. In
249
    // order for the effect to be in front of the object, we need to set the center to be behind it.
250
    getMesh().setComponentCenter(0,0,0,-0.1f);
251

  
252
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
253

  
254
    float fov = getFOV();
255
    double halfFOV = fov * (Math.PI/360);
256
    mCameraDist = (0.5f*mNodeH) / ((float)Math.tan(halfFOV)*mNodeW);
257

  
258
    setProjection( fov, 0.1f);
231
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
259 232
    }
260 233

  
261 234
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1108 1081
    for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
1109 1082
    }
1110 1083

  
1111
///////////////////////////////////////////////////////////////////////////////////////////////////
1112

  
1113
  void recomputeScaleFactor(int surfaceW, int surfaceH)
1114
    {
1115
    mNodeScale.set(surfaceW,surfaceH,surfaceW);
1116
    }
1117

  
1118 1084
///////////////////////////////////////////////////////////////////////////////////////////////////
1119 1085
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
1120 1086

  
......
1156 1122

  
1157 1123
///////////////////////////////////////////////////////////////////////////////////////////////////
1158 1124

  
1159
  void setObjectRatioNow(float sc)
1125
  void setObjectRatioNow(float sc, int nodeMinSize)
1160 1126
    {
1161 1127
    mObjectScreenRatio = sc;
1162
    int nodeMinSize = Math.min(mNodeW,mNodeH);
1163 1128
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeMinSize/mSize;
1164 1129
    mObjectScale.set(scale,scale,scale);
1165 1130
    }
1166 1131

  
1167 1132
///////////////////////////////////////////////////////////////////////////////////////////////////
1168 1133

  
1169
  void setObjectRatio(float sizeChange)
1134
  void setObjectRatio(float sizeChange, int nodeMinSize)
1170 1135
    {
1171 1136
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1172 1137

  
1173 1138
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1174 1139
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1175 1140

  
1176
    setObjectRatioNow(mObjectScreenRatio);
1141
    setObjectRatioNow(mObjectScreenRatio, nodeMinSize);
1177 1142
    }
1178 1143

  
1179 1144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1245 1210
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1246 1211
    }
1247 1212

  
1248
///////////////////////////////////////////////////////////////////////////////////////////////////
1249

  
1250
  float getCameraDist()
1251
    {
1252
    return mCameraDist;
1253
    }
1254

  
1255 1213
///////////////////////////////////////////////////////////////////////////////////////////////////
1256 1214
// INTERNAL API - those are called from 'effects' package
1257 1215
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1261 1219
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total);
1262 1220
    }
1263 1221

  
1264
///////////////////////////////////////////////////////////////////////////////////////////////////
1265

  
1266
  public int getNodeWidth()
1267
    {
1268
    return mNodeW;
1269
    }
1270

  
1271 1222
///////////////////////////////////////////////////////////////////////////////////////////////////
1272 1223

  
1273 1224
  public Static4D getRotationQuat()
......
1342 1293
      }
1343 1294
    }
1344 1295

  
1296
///////////////////////////////////////////////////////////////////////////////////////////////////
1297

  
1298
  public DistortedNode getNode()
1299
    {
1300
    return mNode;
1301
    }
1302

  
1345 1303
///////////////////////////////////////////////////////////////////////////////////////////////////
1346 1304

  
1347 1305
  public ObjectType getObjectType()
......
1383 1341

  
1384 1342
///////////////////////////////////////////////////////////////////////////////////////////////////
1385 1343

  
1386
  protected abstract int getFOV();
1387 1344
  protected abstract float getScreenRatio();
1388 1345
  protected abstract int getColor(int face);
1389 1346
  protected abstract int getResource(int[] numLayers);
......
1420 1377
  public abstract int getInventor(int[] numLayers);
1421 1378
  public abstract int getYearOfInvention(int[] numLayers);
1422 1379
  public abstract int getComplexity(int[] numLayers);
1380
  public abstract int getFOV();
1423 1381
  }

Also available in: Unified diff