Project

General

Profile

« Previous | Next » 

Revision 71c3fecc

Added by Leszek Koltunski almost 8 years ago

Javadoc

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
28 28
///////////////////////////////////////////////////////////////////////////////////////////////////
29 29
/**
30 30
 * Class which represents a OpenGL Framebuffer object.
31
 *
31
 * <p>
32 32
 * User is able to create either WRITE-only Framebuffers from objects already constructed outside
33 33
 * of the library (the first constructor; primary use case: the screen) or an offscreen READ-WRITE
34 34
 * FBOs (used by the DistortedNode, but also can be used by external users of the library)
35
 *
35
 * <p>
36 36
 * Also, keep all objects created in a static LinkedList. The point: we need to be able to mark
37 37
 * Framebuffers for deletion, and delete all marked objects later at a convenient time (that's
38 38
 * because we can only delete from a thread that holds the OpenGL context so here we provide a
......
63 63

  
64 64
  private void createProjection()
65 65
    {
66
    float ratio  = (float) mWidth / mHeight;
67
    float left   =-ratio;          //
68
    float right  = ratio;          // Create a new perspective projection matrix.
69
    float bottom = -1.0f;          //
70
    float top    =  1.0f;          // any change to those values will have serious consequences!
71
    float near, far;
72

  
73 66
    if( mFOV>0.0f )  // perspective projection
74 67
      {
75
      near= (float)(top / Math.tan(mFOV*Math.PI/360));
68
      float ratio  = (float) mWidth / mHeight;
69
      float left   =-ratio;
70
      float right  = ratio;
71
      float bottom = -1.0f;
72
      float top    =  1.0f;
73
      float near= (float)(top / Math.tan(mFOV*Math.PI/360));
76 74
      mDistance = (int)(mHeight*near/(top-bottom));
77
      far = 2*mDistance-near;
75
      float far = 2*mDistance-near;
76
      mDepth = (int)((far-near)/2);
78 77

  
79 78
      if( far<=0 )
80 79
        {
......
84 83
      else
85 84
        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
86 85
      }
87
    else                      // parallel projection
86
    else             // parallel projection
88 87
      {
89
      near= (float)(top / Math.tan(Math.PI/360));
88
      float left   =-mWidth/2;
89
      float right  = mWidth/2;
90
      float bottom =-mHeight/2;
91
      float top    = mHeight/2;
92
      float near= (float)(top / Math.tan(Math.PI/360));
90 93
      mDistance = (int)(mHeight*near/(top-bottom));
91
      far = 2*mDistance-near;
94
      float far = 2*mDistance-near;
95
      mDepth = (int)((far-near)/2);
92 96

  
93
      Matrix.orthoM(mProjectionMatrix, 0, -mWidth/2, mWidth/2,-mHeight/2, mHeight/2, near, far);
97
      Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
94 98
      }
95

  
96
    mDepth = (int)((far-near)/2);
97 99
    }
98 100

  
99 101
///////////////////////////////////////////////////////////////////////////////////////////////////
......
257 259
 * Create new Projection matrix.
258 260
 *
259 261
 * @param fov Vertical 'field of view' of the Projection frustrum (in degrees).
260
 * @param x X-coordinate of the point at which our camera looks at. -1<x<1
261
 * @param y Y-coordinate of the point at which our camera looks at. -1<y<1
262
 * @param x X-coordinate of the point at which our camera looks at. -mWidth/2 &lt; x &lt; mWidth/2
263
 * @param y Y-coordinate of the point at which our camera looks at. -mHeight/2 &lt; y &lt; mHeight/2
262 264
 */
263 265
  public void setProjection(float fov, float x, float y)
264 266
    {
......
276 278
 * As the Framebuffer is not created until the first render, typical usage of this API is actually
277 279
 * to set the size of an not-yet-created Framebuffer of an object that has been created with the
278 280
 * second constructor.
279
 *
281
 * <p>
280 282
 * Fully creating an object, rendering to it, then resizing mid-render is also possible.
281 283
 *
282 284
 * @param width The new width.
......
300 302
 * Set this as the Framebuffer to write to.
301 303
 */
302 304

  
303
  public void setOutput()
305
  public void setAsOutput()
304 306
    {
305 307
    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
306 308

  
......
312 314
 * Set this as the Framebuffer to read from.
313 315
 */
314 316

  
315
  public void setInput()
317
  public void setAsInput()
316 318
    {
317 319
    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
318 320

  
src/main/java/org/distorted/library/DistortedNode.java
93 93
      if( !mData.mRendered )
94 94
        {
95 95
        mData.mRendered = true;
96
        mData.mDF.setOutput();
96
        mData.mDF.setAsOutput();
97 97

  
98 98
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
99 99
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
......
113 113
          }
114 114
        }
115 115

  
116
      df.setOutput();
117
      mData.mDF.setInput();
116
      df.setAsOutput();
117
      mData.mDF.setAsInput();
118 118
      }
119 119
    
120 120
    mObject.drawPriv(currTime, df);

Also available in: Unified diff