Project

General

Profile

« Previous | Next » 

Revision 209ea1c7

Added by Leszek Koltunski almost 5 years ago

1. library: new API DistortedNode.setProjection()
2. cube: adjustments for Pyraminx.

View differences:

src/main/java/org/distorted/library/main/DistortedNode.java
39 39
 */
40 40
public class DistortedNode implements InternalChildrenList.Parent
41 41
  {
42
  private static final int DEFAULT_FBO_SIZE = 100;
43

  
42 44
  private MeshBase mMesh;
43 45
  private DistortedEffects mEffects;
44 46
  private InternalSurface mSurface;
......
49 51

  
50 52
  private int mFboW, mFboH, mFboDepthStencil;
51 53
  private boolean mRenderWayOIT;
54
  private float mFOV, mNear;
52 55

  
53 56
///////////////////////////////////////////////////////////////////////////////////////////////////
54 57

  
......
257 260
        }
258 261
      else
259 262
        {
260
        width = 100;
261
        height= 100;
263
        width = DEFAULT_FBO_SIZE;
264
        height= DEFAULT_FBO_SIZE;
262 265
        }
263 266
      }
264 267

  
265
    return new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
268
    DistortedFramebuffer fbo = new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height);
269

  
270
    if( mFOV!=InternalOutputSurface.DEFAULT_FOV || mNear!=InternalOutputSurface.DEFAULT_NEAR )
271
      {
272
      fbo.setProjection(mFOV,mNear);
273
      }
274

  
275
    return fbo;
266 276
    }
267 277

  
268 278
///////////////////////////////////////////////////////////////////////////////////////////////////
......
292 302
    mParent        = null;
293 303
    mRenderWayOIT  = false;
294 304

  
305
    mFOV = InternalOutputSurface.DEFAULT_FOV;
306
    mNear= InternalOutputSurface.DEFAULT_NEAR;
307

  
295 308
    mFboW            = 0;  // i.e. take this from
296 309
    mFboH            = 0;  // mEffects's stretch{X,Y}
297 310
    mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
......
317 330
    mParent       = null;
318 331
    mRenderWayOIT = false;
319 332

  
333
    mFOV = InternalOutputSurface.DEFAULT_FOV;
334
    mNear= InternalOutputSurface.DEFAULT_NEAR;
335

  
320 336
    mFboW            = node.mFboW;
321 337
    mFboH            = node.mFboH;
322 338
    mFboDepthStencil = node.mFboDepthStencil;
......
523 539
      }
524 540
    }
525 541

  
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
/**
544
 * Set Projection Matrix for the Framebuffer contained in this Node.
545
 * <p>
546
 * If this Node is a Leaf and has no Framebuffer in it, this call does nothing.
547
 *
548
 * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
549
 *            Valid values: 0<=fov<180. FOV==0 means 'parallel projection'.
550
 * @param near The Near plane.
551
 */
552
  public void setProjection(float fov, float near)
553
    {
554
    if( fov < 180.0f && fov >=0.0f )
555
      {
556
      mFOV = fov;
557
      }
558

  
559
    if( near<   1.0f && near> 0.0f )
560
      {
561
      mNear= near;
562
      }
563
    else if( near<=0.0f )
564
      {
565
      mNear = 0.01f;
566
      }
567
    else if( near>=1.0f )
568
      {
569
      mNear=0.99f;
570
      }
571

  
572
    if( mData.mFBO!=null )
573
      {
574
      mData.mFBO.setProjection(mFOV,mNear);
575
      }
576
    }
577

  
526 578
///////////////////////////////////////////////////////////////////////////////////////////////////
527 579
/**
528 580
 * Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
src/main/java/org/distorted/library/main/InternalOutputSurface.java
38 38
  public static final int DEPTH_NO_STENCIL    = 1;
39 39
  public static final int BOTH_DEPTH_STENCIL  = 2;
40 40

  
41
  public static final float DEFAULT_FOV = 60.0f;
42
  public static final float DEFAULT_NEAR=  0.1f;
43

  
41 44
  float mFOV, mDistance, mNear, mMipmap;
42 45
  float[] mProjectionMatrix;
43 46
  int mDepthStencilCreated, mDepthStencil;
......
74 77

  
75 78
    mProjectionMatrix = new float[16];
76 79

  
77
    mFOV = 60.0f;
78
    mNear=  0.5f;
80
    mFOV = DEFAULT_FOV;
81
    mNear= DEFAULT_NEAR;
79 82

  
80 83
    mDepthStencilCreated= (depthStencil== NO_DEPTH_NO_STENCIL ? DONT_CREATE:NOT_CREATED_YET);
81 84
    mDepthStencil = depthStencil;
......
227 230

  
228 231
        surface.createProjection();
229 232

  
230
        int maxw = surface.mWidth  > surface.mRealWidth  ? surface.mWidth  : surface.mRealWidth;
231
        int maxh = surface.mHeight > surface.mRealHeight ? surface.mHeight : surface.mRealHeight;
233
        int maxw = Math.max(surface.mWidth , surface.mRealWidth );
234
        int maxh = Math.max(surface.mHeight, surface.mRealHeight);
232 235

  
233 236
        if (maxw > surface.mRealWidth || maxh > surface.mRealHeight)
234 237
          {

Also available in: Unified diff