Revision 16b22aab
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
63 | 63 |
|
64 | 64 |
private Static4D mRegion; |
65 | 65 |
private int scrHeight, scrWidth; |
66 |
private int textureWidth, textureHeight; |
|
66 | 67 |
private float mRadius; |
67 | 68 |
|
68 | 69 |
private EffectName mMode = EffectName.DISTORT; |
... | ... | |
173 | 174 |
mRegion.set4(mRadius*scrWidth); |
174 | 175 |
|
175 | 176 |
Canvas stretchCanvas; |
176 |
int w=width/2;
|
|
177 |
int h=height/2;
|
|
177 |
textureWidth = (int)(0.6f*width);
|
|
178 |
textureHeight= (int)(0.6f*height);
|
|
178 | 179 |
|
179 | 180 |
if( stretchMesh!=null ) stretchMesh.markForDeletion(); |
180 | 181 |
|
181 |
stretchMesh = new MeshFlat(50,50*h/w);
|
|
182 |
Bitmap stretchBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
|
|
182 |
stretchMesh = new MeshFlat(50,50*textureHeight/textureWidth);
|
|
183 |
Bitmap stretchBitmap = Bitmap.createBitmap(textureWidth,textureHeight, Bitmap.Config.ARGB_8888);
|
|
183 | 184 |
stretchCanvas = new Canvas(stretchBitmap); |
184 | 185 |
|
185 | 186 |
Paint paint = new Paint(); |
186 | 187 |
paint.setColor(0xff008800); |
187 | 188 |
paint.setStyle(Style.FILL); |
188 |
stretchCanvas.drawRect(0, 0, w, h, paint);
|
|
189 |
stretchCanvas.drawRect(0, 0, textureWidth, textureHeight, paint);
|
|
189 | 190 |
paint.setColor(0xffffffff); |
190 | 191 |
|
191 | 192 |
for(int i=0; i<=NUM_LINES ; i++ ) |
192 | 193 |
{ |
193 |
stretchCanvas.drawRect(w*i/NUM_LINES-1, 0, w*i/NUM_LINES+1, h , paint);
|
|
194 |
stretchCanvas.drawRect( 0, h*i/NUM_LINES-1, w , h*i/NUM_LINES+1, paint);
|
|
194 |
stretchCanvas.drawRect(textureWidth*i/NUM_LINES-1, 0, textureWidth*i/NUM_LINES+1, textureHeight , paint);
|
|
195 |
stretchCanvas.drawRect( 0, textureHeight*i/NUM_LINES-1, textureWidth , textureHeight*i/NUM_LINES+1, paint);
|
|
195 | 196 |
} |
196 | 197 |
|
197 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(w,h);
|
|
198 |
if( stretchTexture==null ) stretchTexture = new DistortedTexture(textureWidth,textureHeight);
|
|
198 | 199 |
stretchTexture.setTexture(stretchBitmap); |
199 | 200 |
|
200 | 201 |
mScreen.detachAll(); |
... | ... | |
223 | 224 |
|
224 | 225 |
void down(int x, int y) |
225 | 226 |
{ |
226 |
int xt = x-scrWidth /4; |
|
227 |
int yt = y-scrHeight/4; |
|
228 |
|
|
229 |
if( xt<0 ) xt=0; |
|
230 |
if( xt>scrWidth /2 ) xt=scrWidth/2; |
|
231 |
if( yt<0 ) yt=0; |
|
232 |
if( yt>scrHeight/2 ) yt=scrHeight/2; |
|
233 |
|
|
234 |
mTouchPoint.set(xt, scrHeight/2-yt,0); // OpenGL coord system and 2D coords have inverted Y axis |
|
227 |
int xt = x-(scrWidth -textureWidth )/2; |
|
228 |
int yt = y-(scrHeight-textureHeight)/2; |
|
229 |
|
|
230 |
yt = textureHeight - yt; // OpenGL coord system and 2D coords have inverted Y axis |
|
235 | 231 |
|
236 | 232 |
switch(mMode) |
237 | 233 |
{ |
238 | 234 |
case DISTORT: vDistort[0].set(0,0,0); |
239 | 235 |
stretchEffects.apply(mMovingDistort); |
240 | 236 |
mLastEffect = mMovingDistort.getID(); |
237 |
mTouchPoint.set(xt,yt,0); |
|
241 | 238 |
break; |
242 | 239 |
case DEFORM : vDeform[0].set(0,0,0); |
243 | 240 |
stretchEffects.apply(mMovingDeform); |
244 | 241 |
mLastEffect = mMovingDeform.getID(); |
242 |
mTouchPoint.set(xt,yt,0); |
|
245 | 243 |
break; |
246 | 244 |
case SHEAR : vShear[0].set(0,0,0); |
247 | 245 |
stretchEffects.apply(mMovingShear); |
248 | 246 |
mLastEffect = mMovingShear.getID(); |
247 |
mTouchPoint.set(xt-textureWidth/2,yt-textureHeight/2,0); |
|
249 | 248 |
break; |
250 | 249 |
} |
251 | 250 |
} |
... | ... | |
260 | 259 |
break; |
261 | 260 |
case DEFORM: vDeform[0].set(x,-y,0); |
262 | 261 |
break; |
263 |
case SHEAR: vShear[0].set( (float)x/(scrWidth/2), (float)(-y)/(scrHeight/2), 0);
|
|
262 |
case SHEAR: vShear[0].set( (float)x/textureWidth, (float)(-y)/textureHeight, 0);
|
|
264 | 263 |
break; |
265 | 264 |
} |
266 | 265 |
} |
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.