Project

General

Profile

« Previous | Next » 

Revision 69ed1eb4

Added by Leszek Koltunski over 7 years ago

Progress with getting Mesh'es bounding rectangle.

View differences:

src/main/java/org/distorted/library/MeshCubes.java
72 72
   private int mEdgeNum;
73 73
   private int mSideWalls;
74 74

  
75
   private float[] mBoundingVert;
76

  
77
   private static float[] mBoundingVert1 = new float[] { -0.5f,-0.5f, FRONTZ,
78
                                                         +0.5f,-0.5f, FRONTZ,
79
                                                         -0.5f,+0.5f, FRONTZ,
80
                                                         +0.5f,+0.5f, FRONTZ };
81

  
82
   private static float[] mBoundingVert2 = new float[] { -0.5f,-0.5f, FRONTZ,
83
                                                         +0.5f,-0.5f, FRONTZ,
84
                                                         -0.5f,+0.5f, FRONTZ,
85
                                                         +0.5f,+0.5f, FRONTZ,
86
                                                         -0.5f,-0.5f, BACKZ ,
87
                                                         +0.5f,-0.5f, BACKZ ,
88
                                                         -0.5f,+0.5f, BACKZ ,
89
                                                         +0.5f,+0.5f, BACKZ  };
90

  
75 91
///////////////////////////////////////////////////////////////////////////////////////////////////
76 92
// a Block is split into two triangles along the NE-SW line iff it is in the top-right
77 93
// or bottom-left quadrant of the grid.
......
188 204
       dataLength = computeDataLength(frontOnly);
189 205

  
190 206
       remainingVert = dataLength;
207
       buildBoundingVert(mCubes,frontOnly);
191 208
       }
192 209
     }
193 210

  
......
213 230

  
214 231
       remainingVert = dataLength;
215 232
       }
233

  
234
     mBoundingVert = frontOnly ? mBoundingVert1 : mBoundingVert2;
216 235
     }
217 236

  
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

  
239
  private float retLeftmost(short[][] cubes, int row)
240
    {
241

  
242
    return 0.0f;
243
    }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
 private float retRightmost(short[][] cubes, int row)
248
    {
249
    if( row==0 )
250
      {
251
      for(int i=0; i<mCols; i++)
252
        {
253

  
254
        }
255
      }
256
    else if(row==mRows)
257
      {
258
      for(int i=0; i<mCols; i++)
259
        {
260

  
261
        }
262
      }
263
    else
264
      {
265
      for(int i=0; i<mCols; i++)
266
        {
267

  
268
        }
269
      }
270

  
271
    return 0.0f;
272
    }
273

  
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

  
276
  private int addLeftmost(float[] temp, short[][] cubes, int row, int index)
277
    {
278
    float x2 = retLeftmost(cubes,row);
279
    float y2 = row/mRows - 0.5f;
280

  
281
    if( index>1 )
282
      {
283
      float x0 = temp[2*index-4];
284
      float y0 = temp[2*index-3];
285
      float x1 = temp[2*index-2];
286
      float y1 = temp[2*index-1];
287

  
288
      if( (x0-x2)*(y0-y1) <= (x0-x1)*(y0-y2) )
289
        {
290
        temp[2*index-2] = x2;
291
        temp[2*index-1] = y2;
292
        return index;
293
        }
294
      }
295

  
296
    temp[2*index+0] = x2;
297
    temp[2*index+1] = y2;
298
    return index+1;
299
    }
300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

  
303
  private int addRightmost(float[] temp, short[][] cubes, int row, int index)
304
    {
305
    float x2 = retRightmost(cubes,row);
306
    float y2 = row/mRows - 0.5f;
307

  
308
    if( index>1 )
309
      {
310
      float x0 = temp[2*index-4];
311
      float y0 = temp[2*index-3];
312
      float x1 = temp[2*index-2];
313
      float y1 = temp[2*index-1];
314

  
315
      if( (x0-x2)*(y0-y1) >= (x0-x1)*(y0-y2) )
316
        {
317
        temp[2*index-2] = x2;
318
        temp[2*index-1] = y2;
319
        return index;
320
        }
321
      }
322

  
323
    temp[2*index+0] = x2;
324
    temp[2*index+1] = y2;
325
    return index+1;
326
    }
327

  
328
///////////////////////////////////////////////////////////////////////////////////////////////////
329
// fill up the mBoundingVert array with the smallest set of vertices which form the same convex hull
330
// like the whole thing.
331

  
332
  private void buildBoundingVert(short[][] cubes, boolean frontOnly)
333
    {
334
    int lVert=0, rVert=0;
335
    float[] tempL = new float[2*(mRows+1)];
336
    float[] tempR = new float[2*(mRows+1)];
337

  
338
    for(int i=0; i<=mRows; i++)
339
      {
340
      lVert = addLeftmost (tempL,cubes,i,lVert);
341
      rVert = addRightmost(tempR,cubes,i,rVert);
342
      }
343

  
344
    int numVert = lVert+rVert;
345

  
346
    mBoundingVert = new float[ numVert*(frontOnly ? 3:6) ];
347

  
348
    for(int i=0; i<lVert; i++)
349
      {
350
      mBoundingVert[3*i  ] = tempL[2*i  ];
351
      mBoundingVert[3*i+1] = tempL[2*i+1];
352
      mBoundingVert[3*i+2] = FRONTZ;
353
      }
354

  
355
    for(int i=0; i<rVert; i++)
356
      {
357
      mBoundingVert[3*(i+lVert)  ] = tempR[2*i  ];
358
      mBoundingVert[3*(i+lVert)+1] = tempR[2*i+1];
359
      mBoundingVert[3*(i+lVert)+2] = FRONTZ;
360
      }
361

  
362
    if( !frontOnly )
363
      {
364
      for(int i=0; i<numVert; i++)
365
        {
366
        mBoundingVert[3*(i+numVert)  ] = mBoundingVert[3*i  ];
367
        mBoundingVert[3*(i+numVert)+1] = mBoundingVert[3*i+1];
368
        mBoundingVert[3*(i+numVert)+2] = BACKZ;
369
        }
370
      }
371
    }
372

  
218 373
///////////////////////////////////////////////////////////////////////////////////////////////////
219 374
// Mark all the 'regions' of our grid  - i.e. separate pieces of 'land' (connected blocks that will 
220 375
// be rendered) and 'water' (connected holes in between) with integers. Each connected block of land
......
742 897

  
743 898
///////////////////////////////////////////////////////////////////////////////////////////////////
744 899

  
745
   boolean canUsePostprocessingShortcut()
746
      {
747
      return false;
748
      }
900
   float[] getBoundingVertices()
901
     {
902
     return mBoundingVert;
903
     }
749 904

  
750 905
///////////////////////////////////////////////////////////////////////////////////////////////////
751 906
// PUBLIC API

Also available in: Unified diff