Revision 54fe333a
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedOutputSurface.java  

32  32 
private ArrayList<DistortedNode> mChildren; 
33  33 
private int mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added 
34  34  
35 
private float mX, mY, mFOV;


35 
private float mNear, mFOV;


36  36 
int mWidth,mHeight,mDepth; 
37  37 
float mDistance; 
38  38 
float[] mProjectionMatrix; 
...  ...  
53  53 
mHeight= height; 
54  54  
55  55 
mFOV = 60.0f; 
56 
mX = 0.0f; 

57 
mY = 0.0f; 

56 
mNear= 0.5f; 

58  57  
59  58 
mDepthCreated= createDepth; 
60  59 
mFBOH[0] = fbo; 
...  ...  
71  70 
{ 
72  71 
if( mFOV>0.0f ) // perspective projection 
73  72 
{ 
74 
float left = (mXmWidth /2.0f)/mHeight; 

75 
float right = (mX+mWidth /2.0f)/mHeight; 

76 
float bottom = (mYmHeight/2.0f)/mHeight; 

77 
float top = (mY+mHeight/2.0f)/mHeight; 

78 
float near = (topbottom) / (2.0f*(float)Math.tan(mFOV*Math.PI/360)); 

79 
mDistance = mHeight*near/(topbottom); 

73 
float a = 2.0f*(float)Math.tan(mFOV*Math.PI/360); 

74 
float q = (float)mWidth/mHeight; 

75 
float c = mHeight*mNear; 

76  
77 
float left = q*c/2; 

78 
float right = +q*c/2; 

79 
float bottom = c/2; 

80 
float top = +c/2; 

81 
float near = c/a; 

82  
83 
mDistance = mHeight/a; 

80  84 
float far = 2*mDistancenear; 
81  85 
mDepth = (int)((farnear)/2); 
82  86  
...  ...  
84  88 
} 
85  89 
else // parallel projection 
86  90 
{ 
87 
float left = mXmWidth /2.0f;


88 
float right = mX+mWidth /2.0f;


89 
float bottom = mYmHeight/2.0f;


90 
float top = mY+mHeight/2.0f;


91 
float near = (mWidth+mHeight)/2;


92 
mDistance = 2*near;


93 
float far = 3*near;


94 
mDepth = (int)near;


91 
float left = mWidth /2.0f; 

92 
float right = +mWidth /2.0f; 

93 
float bottom = mHeight/2.0f; 

94 
float top = +mHeight/2.0f; 

95 
float near = mWidth+mHeightmHeight*(1.0fmNear);


96 
mDistance = mWidth+mHeight;


97 
float far = mWidth+mHeight+mHeight*(1.0fmNear);


98 
mDepth = (int)((farnear)/2);


95  99  
96  100 
Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far); 
97  101 
} 
...  ...  
170  174 
* Create new Projection matrix. 
171  175 
* 
172  176 
* @param fov Vertical 'field of view' of the Projection frustrum (in degrees). 
173 
* @param x Xcoordinate of the point at which our camera looks at. 0 is the center. 

174 
* @param y Ycoordinate of the point at which our camera looks at. 0 is the center. 

177 
* Valid values: 0<=fov<180. FOV==0 means 'parallel projection'. 

178 
* @param near Distance between the screen plane and the near plane. 

179 
* Valid vaules: 0<near<1. When near==0, the Near Plane is exactly at the tip of the 

180 
* pyramid. When near==1 (illegal!) the near plane is equivalent to the screen plane. 

175  181 
*/ 
176 
public void setProjection(float fov, float x, float y)


182 
public void setProjection(float fov, float near)


177  183 
{ 
178 
mFOV = fov; 

179 
mX = x; 

180 
mY = y; 

184 
if( fov < 180.0f && fov >=0.0f ) mFOV = fov; 

185 
if( near< 1.0f && near> 0.0f ) mNear= near; 

181  186  
182  187 
createProjection(); 
183  188 
} 
Also available in: Unified diff
Fixes for zfighting.