Project

General

Profile

« Previous | Next » 

Revision 270c27bc

Added by Leszek Koltunski almost 7 years ago

Progress with Stencils in postprocessing.

View differences:

src/main/java/org/distorted/library/EffectQueueMatrix.java
105 105

  
106 106
///////////////////////////////////////////////////////////////////////////////////////////////////
107 107

  
108
  private void magnify(float halfX, float halfY, float halfZ, DistortedOutputSurface projection)
108
  private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
109 109
    {
110
    float scale;
110
    float scale, nx, ny;
111 111
    float[] result= new float[4];
112 112
    float[] point = new float[4];
113 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;
119
    point[3] = 0.0f;
114
    float minx = Integer.MAX_VALUE;
115
    float maxx = Integer.MIN_VALUE;
116
    float miny = Integer.MAX_VALUE;
117
    float maxy = Integer.MIN_VALUE;
118

  
119
    point[3] = 1.0f;
120 120

  
121 121
    Matrix.multiplyMM(matrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
122 122

  
123 123
    point[0] = +halfX; point[1] = +halfY; point[2] = +halfZ;
124 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);
125
    nx = result[0]/result[3];
126
    ny = result[1]/result[3];
127
    if( nx<minx ) minx = nx;
128
    if( nx>maxx ) maxx = nx;
129
    if( ny<miny ) miny = ny;
130
    if( ny>maxy ) maxy = ny;
128 131

  
129 132
    point[0] = +halfX; point[1] = +halfY; point[2] = -halfZ;
130 133
    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
    nx = result[0]/result[3];
135
    ny = result[1]/result[3];
136
    if( nx<minx ) minx = nx;
137
    if( nx>maxx ) maxx = nx;
138
    if( ny<miny ) miny = ny;
139
    if( ny>maxy ) maxy = ny;
134 140

  
135 141
    point[0] = +halfX; point[1] = -halfY; point[2] = +halfZ;
136 142
    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);
143
    nx = result[0]/result[3];
144
    ny = result[1]/result[3];
145
    if( nx<minx ) minx = nx;
146
    if( nx>maxx ) maxx = nx;
147
    if( ny<miny ) miny = ny;
148
    if( ny>maxy ) maxy = ny;
140 149

  
141 150
    point[0] = +halfX; point[1] = -halfY; point[2] = -halfZ;
142 151
    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);
152
    nx = result[0]/result[3];
153
    ny = result[1]/result[3];
154
    if( nx<minx ) minx = nx;
155
    if( nx>maxx ) maxx = nx;
156
    if( ny<miny ) miny = ny;
157
    if( ny>maxy ) maxy = ny;
146 158

  
147 159
    point[0] = -halfX; point[1] = +halfY; point[2] = +halfZ;
148 160
    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);
161
    nx = result[0]/result[3];
162
    ny = result[1]/result[3];
163
    if( nx<minx ) minx = nx;
164
    if( nx>maxx ) maxx = nx;
165
    if( ny<miny ) miny = ny;
166
    if( ny>maxy ) maxy = ny;
152 167

  
153 168
    point[0] = -halfX; point[1] = +halfY; point[2] = -halfZ;
154 169
    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);
170
    nx = result[0]/result[3];
171
    ny = result[1]/result[3];
172
    if( nx<minx ) minx = nx;
173
    if( nx>maxx ) maxx = nx;
174
    if( ny<miny ) miny = ny;
175
    if( ny>maxy ) maxy = ny;
158 176

  
159 177
    point[0] = -halfX; point[1] = -halfY; point[2] = +halfZ;
160 178
    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);
179
    nx = result[0]/result[3];
180
    ny = result[1]/result[3];
181
    if( nx<minx ) minx = nx;
182
    if( nx>maxx ) maxx = nx;
183
    if( ny<miny ) miny = ny;
184
    if( ny>maxy ) maxy = ny;
164 185

  
165 186
    point[0] = -halfX; point[1] = -halfY; point[2] = -halfZ;
166 187
    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);
188
    nx = result[0]/result[3];
189
    ny = result[1]/result[3];
190
    if( nx<minx ) minx = nx;
191
    if( nx>maxx ) maxx = nx;
192
    if( ny<miny ) miny = ny;
193
    if( ny>maxy ) maxy = ny;
170 194

  
171
    sum = (d1+d2+d3+d4+d5+d6+d7+d8)/8;
195
    float xlen = projection.mWidth *(maxx-minx)/2;
196
    float ylen = projection.mHeight*(maxy-miny)/2;
172 197

  
173
    scale = 1.0f + (float)(Distorted.mMargin/sum);
198
    scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen );
174 199

  
175
    android.util.Log.d("scale", "scale="+scale+" sum="+sum+" "+d1+" "+d2+" "+d3+" "+d4+" "+d5+" "+d6+" "+d7+" "+d8);
200
   // android.util.Log.d("scale", "scale= "+scale+" xlen="+xlen+" ylen="+ylen);
176 201

  
177 202
    Matrix.scaleM(mViewMatrix, 0, scale, scale, scale);
178 203
    }
......
180 205
///////////////////////////////////////////////////////////////////////////////////////////////////
181 206
// here construct the ModelView and the ModelViewProjection Matrices
182 207

  
183
  private void constructMatrices(DistortedOutputSurface projection, float halfX, float halfY, float halfZ)
208
  private void constructMatrices(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
184 209
    {
185 210
    Matrix.setIdentityM(mViewMatrix, 0);
186 211
    Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance);
......
261 286

  
262 287
    Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ);
263 288

  
264
    if( Distorted.mMargin!=0 ) magnify(halfX,halfY,halfZ,projection);
289
    if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels);
265 290

  
266 291
    Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
267 292
    }
......
336 361

  
337 362
///////////////////////////////////////////////////////////////////////////////////////////////////
338 363

  
339
  synchronized void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ)
364
  synchronized void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
340 365
    {
341
    constructMatrices(projection,halfX,halfY,halfZ);
366
    constructMatrices(projection,halfX,halfY,halfZ, marginInPixels);
342 367

  
343 368
    GLES30.glUniform3f( mObjDH , halfX, halfY, halfZ);
344 369
    GLES30.glUniformMatrix4fv(mMVMatrixH , 1, false, mViewMatrix, 0);

Also available in: Unified diff