Project

General

Profile

« Previous | Next » 

Revision 98455aa2

Added by Leszek Koltunski about 8 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/Distorted.java
91 91
  static int mTextureCoordH;    // pass in model texture coordinate information.
92 92
  static int mProgramH;         // This is a handle to our shading program.
93 93

  
94
  static DistortedFramebuffer mFramebuffer = new DistortedFramebuffer(0);
94
  static DistortedFramebuffer mFramebuffer = new DistortedFramebuffer(0); // output to the screen
95 95

  
96 96
///////////////////////////////////////////////////////////////////////////////////////////////////
97 97

  
......
284 284
// Public API
285 285
///////////////////////////////////////////////////////////////////////////////////////////////////
286 286
/**
287
 * Sets Vertical Field of View angle. This changes the Projection Matrix.  
287
 * Sets Vertical Field of View angle and the point the camera is looking at. This changes the Projection Matrix.
288 288
 *   
289 289
 * @param fov Vertical Field Of View angle, in degrees. If T is the middle of the top edge of the 
290 290
 *            screen, E is the eye point, and B is the middle of the bottom edge of the screen, then 
291 291
 *            fov = angle(TEB)
292
 * @param x   X-coordinate of the point the camera is looking at. -scrWidth/2 < x < scrWidth/2
293
 * @param y   Y-coordinate of the point the camera is looking at. -scrHeight/2 < y < scrHeight/2
292 294
 */
293
  public static void setFov(float fov)
295
  public static void setProjection(float fov, float x, float y)
294 296
    {
295
    mFramebuffer.setProjection(fov,0.0f,0.0f);
297
    mFramebuffer.setProjection(fov,x,y);
296 298
    }
297 299
  
298 300
///////////////////////////////////////////////////////////////////////////////////////////////////
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

  
src/main/java/org/distorted/library/EffectTypes.java
63 63
                      // EffectQueueMatrix.setMax(int)
64 64

  
65 65
    maxtable[1] = 5;  // Max 5 VERTEX Effects
66
    maxtable[2] = 3;  // Max 3 FRAGMENT Effects
66
    maxtable[2] = 5;  // Max 3 FRAGMENT Effects
67 67
    }
68 68
///////////////////////////////////////////////////////////////////////////////////////////////////
69 69
  }

Also available in: Unified diff