105 |
105 |
|
106 |
106 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
107 |
|
108 |
|
private void magnify(float halfX, float halfY, float halfZ, float[] projection)
|
|
108 |
private void magnify(float halfX, float halfY, float halfZ, DistortedOutputSurface projection)
|
109 |
109 |
{
|
110 |
|
float scale = Distorted.mMagnify;
|
|
110 |
float scale;
|
|
111 |
float[] result= new float[4];
|
111 |
112 |
float[] point = new float[4];
|
|
113 |
float[] matrix= new float[16];
|
|
114 |
double d1, d2, d3, d4, d5, d6, d7, d8;
|
|
115 |
float nx, ny;
|
|
116 |
float w = projection.mWidth/2;
|
|
117 |
float h = projection.mHeight/2;
|
|
118 |
double sum = 0.0;
|
112 |
119 |
point[3] = 0.0f;
|
113 |
120 |
|
|
121 |
Matrix.multiplyMM(matrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
|
|
122 |
|
|
123 |
point[0] = +halfX; point[1] = +halfY; point[2] = +halfZ;
|
|
124 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
125 |
nx = w*result[0]/result[3];
|
|
126 |
ny = h*result[1]/result[3];
|
|
127 |
d1 = Math.sqrt(nx*nx+ny*ny);
|
|
128 |
|
|
129 |
point[0] = +halfX; point[1] = +halfY; point[2] = -halfZ;
|
|
130 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
131 |
nx = w*result[0]/result[3];
|
|
132 |
ny = h*result[1]/result[3];
|
|
133 |
d2 = Math.sqrt(nx*nx+ny*ny);
|
|
134 |
|
|
135 |
point[0] = +halfX; point[1] = -halfY; point[2] = +halfZ;
|
|
136 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
137 |
nx = w*result[0]/result[3];
|
|
138 |
ny = h*result[1]/result[3];
|
|
139 |
d3 = Math.sqrt(nx*nx+ny*ny);
|
|
140 |
|
|
141 |
point[0] = +halfX; point[1] = -halfY; point[2] = -halfZ;
|
|
142 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
143 |
nx = w*result[0]/result[3];
|
|
144 |
ny = h*result[1]/result[3];
|
|
145 |
d4 = Math.sqrt(nx*nx+ny*ny);
|
|
146 |
|
|
147 |
point[0] = -halfX; point[1] = +halfY; point[2] = +halfZ;
|
|
148 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
149 |
nx = w*result[0]/result[3];
|
|
150 |
ny = h*result[1]/result[3];
|
|
151 |
d5 = Math.sqrt(nx*nx+ny*ny);
|
|
152 |
|
|
153 |
point[0] = -halfX; point[1] = +halfY; point[2] = -halfZ;
|
|
154 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
155 |
nx = w*result[0]/result[3];
|
|
156 |
ny = h*result[1]/result[3];
|
|
157 |
d6 = Math.sqrt(nx*nx+ny*ny);
|
|
158 |
|
|
159 |
point[0] = -halfX; point[1] = -halfY; point[2] = +halfZ;
|
|
160 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
161 |
nx = w*result[0]/result[3];
|
|
162 |
ny = h*result[1]/result[3];
|
|
163 |
d7 = Math.sqrt(nx*nx+ny*ny);
|
|
164 |
|
|
165 |
point[0] = -halfX; point[1] = -halfY; point[2] = -halfZ;
|
|
166 |
Matrix.multiplyMV(result,0,matrix,0,point,0);
|
|
167 |
nx = w*result[0]/result[3];
|
|
168 |
ny = h*result[1]/result[3];
|
|
169 |
d8 = Math.sqrt(nx*nx+ny*ny);
|
|
170 |
|
|
171 |
sum = (d1+d2+d3+d4+d5+d6+d7+d8)/8;
|
|
172 |
|
|
173 |
scale = 1.0f + (float)(Distorted.mMargin/sum);
|
|
174 |
|
|
175 |
android.util.Log.d("scale", "scale="+scale+" sum="+sum+" "+d1+" "+d2+" "+d3+" "+d4+" "+d5+" "+d6+" "+d7+" "+d8);
|
|
176 |
|
114 |
177 |
Matrix.scaleM(mViewMatrix, 0, scale, scale, scale);
|
115 |
178 |
}
|
116 |
179 |
|
... | ... | |
198 |
261 |
|
199 |
262 |
Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ);
|
200 |
263 |
|
201 |
|
if( Distorted.mMagnify!=1.0f ) magnify(halfX,halfY,halfZ, projection.mProjectionMatrix);
|
|
264 |
if( Distorted.mMargin!=0 ) magnify(halfX,halfY,halfZ,projection);
|
202 |
265 |
|
203 |
266 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
|
204 |
267 |
}
|
Progress with Magnify.