Project

General

Profile

« Previous | Next » 

Revision 98455aa2

Added by Leszek Koltunski over 7 years ago

Turn the former 'FOV' app into 'Projection' app that also checks the (x,y) the camera looks at.

View differences:

src/main/java/org/distorted/library/DistortedFramebuffer.java
63 63

  
64 64
  private void createProjection()
65 65
    {
66
    if( mFOV>0.0f )  // perspective projection
66
    if( mWidth>0 && mHeight>0 )
67 67
      {
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));
74
      mDistance = (int)(mHeight*near/(top-bottom));
75
      float far = 2*mDistance-near;
76
      mDepth = (int)((far-near)/2);
77

  
78
      if( far<=0 )
68
      if( mFOV>0.0f )  // perspective projection
79 69
        {
80
        android.util.Log.e("FBO", "error: far<=0. width="+mWidth+" height="+mHeight+
81
                           " mFOV="+mFOV+" mDistance="+mDistance+" far="+far+" near="+near);
82
        }
83
      else
70
        float left   =(-mX-mWidth )/mHeight;
71
        float right  =(-mX+mWidth )/mHeight;
72
        float bottom =(-mY-mHeight)/mHeight;
73
        float top    =(-mY+mHeight)/mHeight;
74
        float near= (float)( (top-bottom) / (2*Math.tan(mFOV*Math.PI/360)) );
75
        mDistance = (int)(mHeight*near/(top-bottom));
76
        float far = 2*mDistance-near;
77
        mDepth = (int)((far-near)/2);
78

  
84 79
        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
85
      }
86
    else             // parallel projection
87
      {
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));
93
      mDistance = (int)(mHeight*near/(top-bottom));
94
      float far = 2*mDistance-near;
95
      mDepth = (int)((far-near)/2);
96

  
97
      Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
80
        }
81
      else             // parallel projection
82
        {
83
        float left   =-mX-mWidth/2;
84
        float right  =-mX+mWidth/2;
85
        float bottom =-mY-mHeight/2;
86
        float top    =-mY+mHeight/2;
87
        float near= (float)( (top-bottom) / (2*Math.tan(Math.PI/360)) );
88
        mDistance = (int)(mHeight*near/(top-bottom));
89
        float far = 2*mDistance-near;
90
        mDepth = (int)((far-near)/2);
91

  
92
        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
93
        }
98 94
      }
99 95
    }
100 96

  

Also available in: Unified diff