Project

General

Profile

« Previous | Next » 

Revision 57ef6378

Added by Leszek Koltunski over 2 years ago

Float vertices - scratchbook

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyIvy.java
237 237
    if( variant==0 )
238 238
      {
239 239
      final float angle = (float)Math.PI/(2*IVY_N);
240
      final float CORR  = 1.0f - 2*IVY_D;
240
      final float CORR  = 1-2*IVY_D;
241 241

  
242
      float[][] centers= new float[][] { {-1.0f,-1.0f,-1.0f} };
243
      float[][] corners= new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
242
      float[][] centers  = new float[][] { {-1.0f,-1.0f,-1.0f} };
243
      float[][] corners  = new float[][] { {0.05f,0.20f}, {0.04f,0.20f} };
244
      float[][] vertices = new float[3*(IVY_N+1)+4][3];
244 245
      int[] cornerIndices= new int[3*(IVY_N+1)+4];
245 246
      int[] centerIndices= new int[3*(IVY_N+1)+4];
246
      double[][] vertices= new double[3*(IVY_N+1)+4][3];
247 247
      int[][] vertIndices= new int[6][IVY_N+4];
248 248
      int[] bandIndices  = new int[] { 0,0,0,1,1,1 };
249 249

  
......
269 269
      centerIndices[2] = 0;
270 270
      centerIndices[3] = 0;
271 271

  
272
      vertices[0][0] = 0.0;
273
      vertices[0][1] = 0.0;
274
      vertices[0][2] = 0.0;
275
      vertices[1][0] =-2.0;
276
      vertices[1][1] = 0.0;
277
      vertices[1][2] = 0.0;
278
      vertices[2][0] = 0.0;
279
      vertices[2][1] =-2.0;
280
      vertices[2][2] = 0.0;
281
      vertices[3][0] = 0.0;
282
      vertices[3][1] = 0.0;
283
      vertices[3][2] =-2.0;
272
      vertices[0][0] = 0;
273
      vertices[0][1] = 0;
274
      vertices[0][2] = 0;
275
      vertices[1][0] =-2;
276
      vertices[1][1] = 0;
277
      vertices[1][2] = 0;
278
      vertices[2][0] = 0;
279
      vertices[2][1] =-2;
280
      vertices[2][2] = 0;
281
      vertices[3][0] = 0;
282
      vertices[3][1] = 0;
283
      vertices[3][2] =-2;
284 284

  
285 285
      vertIndices[0][0] = 2;
286 286
      vertIndices[0][1] = 0;
......
309 309

  
310 310
      for(int i=0; i<=IVY_N; i++)
311 311
        {
312
        double cos1 = Math.cos((IVY_N-i)*angle);
313
        double sin1 = Math.sin((IVY_N-i)*angle);
314
        double cos2 = Math.cos((      i)*angle);
315
        double sin2 = Math.sin((      i)*angle);
312
        float cos1 = (float)Math.cos((IVY_N-i)*angle);
313
        float sin1 = (float)Math.sin((IVY_N-i)*angle);
314
        float cos2 = (float)Math.cos((      i)*angle);
315
        float sin2 = (float)Math.sin((      i)*angle);
316 316

  
317
        vertices[N1+i][0] = CORR*(2*cos1-1.0) - 1.0;
318
        vertices[N1+i][1] = CORR*(2*sin1-1.0) - 1.0;
319
        vertices[N1+i][2] = 0.0;
317
        vertices[N1+i][0] = CORR*(2*cos1-1) - 1;
318
        vertices[N1+i][1] = CORR*(2*sin1-1) - 1;
319
        vertices[N1+i][2] = 0;
320 320

  
321
        vertices[N2+i][0] = 0.0;
322
        vertices[N2+i][1] = CORR*(2*sin2-1.0) - 1.0;
323
        vertices[N2+i][2] = CORR*(2*cos2-1.0) - 1.0;
321
        vertices[N2+i][0] = 0;
322
        vertices[N2+i][1] = CORR*(2*sin2-1) - 1;
323
        vertices[N2+i][2] = CORR*(2*cos2-1) - 1;
324 324

  
325
        vertices[N3+i][0] = CORR*(2*cos2-1.0) - 1.0;
326
        vertices[N3+i][1] = 0.0;
327
        vertices[N3+i][2] = CORR*(2*sin2-1.0) - 1.0;
325
        vertices[N3+i][0] = CORR*(2*cos2-1) - 1;
326
        vertices[N3+i][1] = 0;
327
        vertices[N3+i][2] = CORR*(2*sin2-1) - 1;
328 328

  
329 329
        vertIndices[0][i+3] = N1 + i;
330 330
        vertIndices[1][i+3] = N2 + i;
......
334 334
        vertIndices[5][i+3] = N3 + i;
335 335
        }
336 336

  
337
      float C = 1.0f - SQ2/2;
337
      float C = 1-SQ2/2;
338 338
      float[] convexCenter = new float[] {-C,-C,-C};
339 339
      return new ObjectShape(vertices,vertIndices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), convexCenter);
340 340
      }
341 341
    else
342 342
      {
343 343
      final float angle = (float)Math.PI/(2*IVY_N);
344
      final float CORR  = 1.0f - 2*IVY_D;
345
      double[][] vertices = new double[2*IVY_N][3];
344
      final float CORR  = 1-2*IVY_D;
345
      float[][] vertices = new float[2*IVY_N][3];
346 346
      int[][] vert_indices = new int[2][2*IVY_N];
347 347

  
348 348
      int[] bandIndices= new int[] { 0,1 };
......
352 352

  
353 353
      for(int i=0; i<IVY_N; i++)
354 354
        {
355
        double sin = Math.sin(i*angle);
356
        double cos = Math.cos(i*angle);
355
        float sin = (float)Math.sin(i*angle);
356
        float cos = (float)Math.cos(i*angle);
357 357

  
358
        vertices[i      ][0] = CORR*(1.0f-2*cos);
359
        vertices[i      ][1] = CORR*(1.0f-2*sin);
358
        vertices[i      ][0] = CORR*(1-2*cos);
359
        vertices[i      ][1] = CORR*(1-2*sin);
360 360
        vertices[i      ][2] = 0;
361
        vertices[i+IVY_N][0] = CORR*(2*cos-1.0f);
362
        vertices[i+IVY_N][1] = CORR*(2*sin-1.0f);
361
        vertices[i+IVY_N][0] = CORR*(2*cos-1);
362
        vertices[i+IVY_N][1] = CORR*(2*sin-1);
363 363
        vertices[i+IVY_N][2] = 0;
364 364
        }
365 365

  

Also available in: Unified diff