Project

General

Profile

« Previous | Next » 

Revision fd836c4e

Added by Leszek Koltunski over 3 years ago

Convert the two Squares to the new scheme.

View differences:

src/main/java/org/distorted/objects/TwistySquare.java
166 166
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
167 167
    }
168 168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  MeshBase createMiddleCubitMesh()
172
    {
173
    if( mMeshes[0]==null )
174
      {
175
      float[][] bands= new float[][]
176
        {
177
           {0.040f,35,0.8f,1.0f,5,2,1},
178
           {0.020f,35,0.8f,1.0f,5,2,1},
179
           {0.001f,35,0.8f,1.0f,5,2,1}
180
        };
181
      int[] bandIndexes   = new int[] { 2,2,1,1,0,2 };
182
      float[][] corners   = new float[][] { {0.03f,0.05f} };
183
      int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
184
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
185
      int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
186

  
187
      FactoryCubit factory = FactoryCubit.getInstance();
188
      factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
189
      mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
190
                                              bands, bandIndexes,
191
                                              corners, cornerIndexes,
192
                                              centers, centerIndexes,
193
                                              getNumCubitFaces(), null );
194
      }
195

  
196
    return mMeshes[0].copy(true);
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  MeshBase createEdgeCubitMesh()
202
    {
203
    if( mMeshes[1]==null )
204
       {
205
       float[][] bands= new float[][]
206
         {
207
           {0.038f,35,0.5f,0.9f, 5,2,1},
208
           {0.001f,35,0.5f,0.9f, 5,2,1}
209
         };
210
       int[] bandIndexes   = new int[] { 0,1,0,1,1 };
211
       float[][] corners   = new float[][] { {0.04f,0.15f} };
212
       int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
213
       float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
214
       int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
215

  
216
       FactoryCubit factory = FactoryCubit.getInstance();
217
       factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
218
       mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
219
                                               bands, bandIndexes,
220
                                               corners, cornerIndexes,
221
                                               centers, centerIndexes,
222
                                               getNumCubitFaces(), null );
223
       }
224
    return mMeshes[1].copy(true);
225
    }
226

  
227 169
///////////////////////////////////////////////////////////////////////////////////////////////////
228 170

  
229 171
  Static4D[] getQuats()
src/main/java/org/distorted/objects/TwistySquare1.java
22 22
import android.content.res.Resources;
23 23

  
24 24
import org.distorted.helpers.FactoryCubit;
25
import org.distorted.helpers.ObjectShape;
25 26
import org.distorted.helpers.ObjectSticker;
26 27
import org.distorted.library.effect.MatrixEffectQuaternion;
27 28
import org.distorted.library.main.DistortedEffects;
......
181 182

  
182 183
///////////////////////////////////////////////////////////////////////////////////////////////////
183 184

  
184
  private Static4D getQuat(int cubit)
185
  ObjectShape getObjectShape(int cubit, int numLayers)
186
    {
187
    int variant = getCubitVariant(cubit,numLayers);
188

  
189
    if( variant==0 )
190
      {
191
      float[][] bands     = new float[][] { {0.040f,35,0.8f,1.0f,5,2,1}, {0.020f,35,0.8f,1.0f,5,2,1}, {0.001f,35,0.8f,1.0f,5,2,1} };
192
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
193
      float[][] corners   = new float[][] { {0.03f,0.05f} };
194
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
195
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
196
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
197

  
198
      return new ObjectShape(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
199
      }
200
    else if( variant==1 )
201
      {
202
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
203
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
204
      float[][] corners   = new float[][] { {0.04f,0.15f} };
205
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
206
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
207
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
208

  
209
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
210
      }
211
    else
212
      {
213
      float[][] bands     = new float[][] { {0.038f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
214
      int[] bandIndices   = new int[] { 0,1,0,0,1,1 };
215
      float[][] corners   = new float[][] { {0.05f,0.13f} };
216
      int[] cornerIndices = new int[] { 0,0,0,-1,0,0,0,-1 };
217
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
218
      int[] centerIndices = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
219

  
220
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
221
      }
222
    }
223

  
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

  
226
  private Static4D getQuat(int cubit, int numLayers)
185 227
    {
186 228
    return QUATS[QUAT_NUMBER[cubit]];
187 229
    }
188 230

  
189 231
///////////////////////////////////////////////////////////////////////////////////////////////////
190 232

  
191
  MeshBase createCornerCubitMesh()
233
  private int getNumCubitVariants(int numLayers)
192 234
    {
193
    if( mMeshes[2]==null )
194
      {
195
      float[][] bands= new float[][]
196
        {
197
          {0.038f,35,0.9f,1.0f, 5,2,1},
198
          {0.001f,35,0.9f,1.0f, 5,2,1}
199
        };
200
      int[] bandIndexes   = new int[] { 0,1,0,0,1,1 };
201
      float[][] corners   = new float[][] { {0.05f,0.13f} };
202
      int[] cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
203
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
204
      int[] centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
235
    return 3;
236
    }
205 237

  
206
      FactoryCubit factory = FactoryCubit.getInstance();
207
      factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
208
      mMeshes[2] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
209
                                              bands, bandIndexes,
210
                                              corners, cornerIndexes,
211
                                              centers, centerIndexes,
212
                                              getNumCubitFaces(), null );
213
      }
214
    return mMeshes[2].copy(true);
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  int getCubitVariant(int cubit, int numLayers)
241
    {
242
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
215 243
    }
216 244

  
217 245
///////////////////////////////////////////////////////////////////////////////////////////////////
218 246

  
219 247
  MeshBase createCubitMesh(int cubit, int numLayers)
220 248
    {
249
    int variant = getCubitVariant(cubit,numLayers);
250

  
221 251
    if( mMeshes==null )
222 252
      {
223 253
      FactoryCubit factory = FactoryCubit.getInstance();
224 254
      factory.clear();
225
      mMeshes = new MeshBase[4];
255
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
226 256
      }
227 257

  
228
    MeshBase mesh;
229

  
230
         if( cubit< 2 ) mesh = createMiddleCubitMesh();
231
    else if( cubit<10 ) mesh = createEdgeCubitMesh();
232
    else                mesh = createCornerCubitMesh();
258
    if( mMeshes[variant]==null )
259
      {
260
      ObjectShape shape = getObjectShape(cubit,numLayers);
261
      FactoryCubit factory = FactoryCubit.getInstance();
262
      factory.createNewFaceTransform(shape);
263
      mMeshes[variant] = factory.createRoundedSolid(shape);
264
      }
233 265

  
234
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
266
    MeshBase mesh = mMeshes[variant].copy(true);
267
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
235 268
    mesh.apply(quat,0xffffffff,0);
236 269

  
237 270
    return mesh;
......
262 295

  
263 296
  int getFaceColor(int cubit, int cubitface, int numLayers)
264 297
    {
265
    int type;
266

  
267
         if( cubit< 2 ) type = 0;
268
    else if( cubit<10 ) type = 1;
269
    else                type = 2;
270

  
271
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
298
    int variant = getCubitVariant(cubit,numLayers);
299
    return mStickerType[variant][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
272 300
    }
273 301

  
274 302
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistySquare2.java
22 22
import android.content.res.Resources;
23 23

  
24 24
import org.distorted.helpers.FactoryCubit;
25
import org.distorted.helpers.ObjectShape;
25 26
import org.distorted.helpers.ObjectSticker;
26 27
import org.distorted.library.effect.MatrixEffectQuaternion;
27 28
import org.distorted.library.main.DistortedEffects;
......
186 187

  
187 188
///////////////////////////////////////////////////////////////////////////////////////////////////
188 189

  
189
  private Static4D getQuat(int cubit)
190
  ObjectShape getObjectShape(int cubit, int numLayers)
190 191
    {
191
    return QUATS[QUAT_NUMBER[cubit]];
192
    }
192
    int variant = getCubitVariant(cubit,numLayers);
193 193

  
194
///////////////////////////////////////////////////////////////////////////////////////////////////
194
    if( variant==0 )
195
      {
196
      float[][] bands     = new float[][] { {0.040f,35,0.8f,1.0f,5,2,1}, {0.020f,35,0.8f,1.0f,5,2,1}, {0.001f,35,0.8f,1.0f,5,2,1} };
197
      int[] bandIndices   = new int[] { 2,2,1,1,0,2 };
198
      float[][] corners   = new float[][] { {0.03f,0.05f} };
199
      int[] cornerIndices = new int[] { 0,0,0,0,0,0,0,0 };
200
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
201
      int[] centerIndices = new int[] { 0,0,0,0,0,0,0,0 };
202

  
203
      return new ObjectShape(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
204
      }
205
    else if( variant==1 )
206
      {
207
      float[][] bands     = new float[][] { {0.038f,35,0.5f,0.9f, 5,2,1}, {0.001f,35,0.5f,0.9f, 5,2,1} };
208
      int[] bandIndices   = new int[] { 0,1,0,1,1 };
209
      float[][] corners   = new float[][] { {0.04f,0.15f} };
210
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
211
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
212
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
195 213

  
196
  MeshBase createCornerCubitMesh()
197
    {
198
    if( mMeshes[3]==null )
214
      return new ObjectShape(VERTICES_EDGE,VERT_INDEXES_EDGE,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
215
      }
216
    else
199 217
      {
200
      float[][] bands= new float[][]
201
        {
202
          {0.030f,35,0.9f,1.0f, 5,2,1},
203
          {0.001f,35,0.9f,1.0f, 5,2,1}
204
        };
205
      int[] bandIndexes   = new int[] { 0,0,0,1,1 };
218
      float[][] bands     = new float[][] { {0.030f,35,0.9f,1.0f, 5,2,1}, {0.001f,35,0.9f,1.0f, 5,2,1} };
219
      int[] bandIndices   = new int[] { 0,0,0,1,1 };
206 220
      float[][] corners   = new float[][] { {0.05f,0.13f} };
207
      int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
221
      int[] cornerIndices = new int[] { 0,0,-1,0,0,-1 };
208 222
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
209
      int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
223
      int[] centerIndices = new int[] { 0,0,-1,0,0,-1 };
210 224

  
211
      FactoryCubit factory = FactoryCubit.getInstance();
212
      factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
213
      mMeshes[3] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
214
                                              bands, bandIndexes,
215
                                              corners, cornerIndexes,
216
                                              centers, centerIndexes,
217
                                              getNumCubitFaces(), null );
225
      return new ObjectShape(VERTICES_CORNER,VERT_INDEXES_CORNER,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
218 226
      }
219
    return mMeshes[3].copy(true);
227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

  
231
  private Static4D getQuat(int cubit, int numLayers)
232
    {
233
    return QUATS[QUAT_NUMBER[cubit]];
234
    }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
  private int getNumCubitVariants(int numLayers)
239
    {
240
    return 3;
241
    }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
  int getCubitVariant(int cubit, int numLayers)
246
    {
247
    return cubit<2 ? 0 : (cubit<10 ? 1:2);
220 248
    }
221 249

  
222 250
///////////////////////////////////////////////////////////////////////////////////////////////////
223 251

  
224 252
  MeshBase createCubitMesh(int cubit, int numLayers)
225 253
    {
254
    int variant = getCubitVariant(cubit,numLayers);
255

  
226 256
    if( mMeshes==null )
227 257
      {
228 258
      FactoryCubit factory = FactoryCubit.getInstance();
229 259
      factory.clear();
230
      mMeshes = new MeshBase[4];
260
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
231 261
      }
232 262

  
233
    MeshBase mesh;
234

  
235
         if( cubit< 2 ) mesh = createMiddleCubitMesh();
236
    else if( cubit<10 ) mesh = createEdgeCubitMesh();
237
    else                mesh = createCornerCubitMesh();
263
    if( mMeshes[variant]==null )
264
      {
265
      ObjectShape shape = getObjectShape(cubit,numLayers);
266
      FactoryCubit factory = FactoryCubit.getInstance();
267
      factory.createNewFaceTransform(shape);
268
      mMeshes[variant] = factory.createRoundedSolid(shape);
269
      }
238 270

  
239
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
271
    MeshBase mesh = mMeshes[variant].copy(true);
272
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
240 273
    mesh.apply(quat,0xffffffff,0);
241 274

  
242 275
    return mesh;

Also available in: Unified diff