Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/deform/DeformRenderer.java | ||
---|---|---|
40 | 40 |
import org.distorted.library.type.Static3D; |
41 | 41 |
import org.distorted.library.type.Static4D; |
42 | 42 |
|
43 |
import android.app.ActivityManager; |
|
44 |
import android.content.Context; |
|
45 |
import android.content.pm.ConfigurationInfo; |
|
46 |
import android.content.res.Resources; |
|
43 | 47 |
import android.graphics.Bitmap; |
44 | 48 |
import android.graphics.Canvas; |
45 | 49 |
import android.graphics.Paint; |
46 | 50 |
import android.graphics.Paint.Style; |
47 | 51 |
import android.opengl.GLSurfaceView; |
48 | 52 |
|
53 |
import java.io.InputStream; |
|
54 |
|
|
49 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 56 |
|
51 |
class DeformRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.ExceptionListener
|
|
57 |
class DeformRenderer implements GLSurfaceView.Renderer, EffectListener, DistortedLibrary.LibraryUser
|
|
52 | 58 |
{ |
53 | 59 |
private static final int NUM_VECTORS = 8; |
54 | 60 |
private static final int NUM_LINES = 10; |
55 | 61 |
private static final float QUOT = 0.6f; |
56 | 62 |
|
57 |
private GLSurfaceView mView; |
|
58 |
private DistortedTexture mTexture; |
|
59 |
private DistortedEffects mEffects; |
|
60 |
private MeshBase mMesh; |
|
61 |
private DistortedScreen mScreen; |
|
62 |
private Static3D mTouchPoint, mScale; |
|
63 |
|
|
64 |
private Static3D[] vDistort; |
|
65 |
private Static3D[] vDeform; |
|
66 |
private Static3D[] vShear; |
|
63 |
private final GLSurfaceView mView; |
|
64 |
private final Resources mResources; |
|
65 |
private final DistortedTexture mTexture; |
|
66 |
private final DistortedEffects mEffects; |
|
67 |
private final DistortedScreen mScreen; |
|
68 |
private final Static3D mTouchPoint, mScale; |
|
69 |
private final Static3D[] vDistort, vDeform, vShear; |
|
70 |
private final Static4D mRegion; |
|
71 |
private final MatrixEffectShear mMovingShear, mReleasedShear; |
|
72 |
private final VertexEffectDistort mMovingDistort, mReleasedDistort; |
|
73 |
private final VertexEffectDeform mMovingDeform, mReleasedDeform; |
|
74 |
private final Dynamic3D mReleasedDistortDynamic, mReleasedDeformDynamic, mReleasedShearDynamic; |
|
67 | 75 |
|
68 |
private Static4D mRegion; |
|
76 |
private MeshBase mMesh; |
|
77 |
private EffectName mMode = EffectName.DISTORT; |
|
69 | 78 |
private int scrHeight, scrWidth; |
70 | 79 |
private int textureWidth, textureHeight; |
71 | 80 |
private float mRadius; |
72 |
|
|
73 |
private EffectName mMode = EffectName.DISTORT; |
|
74 | 81 |
private long mLastEffect = -1; |
75 | 82 |
|
76 |
private MatrixEffectShear mMovingShear, mReleasedShear; |
|
77 |
private VertexEffectDistort mMovingDistort, mReleasedDistort; |
|
78 |
private VertexEffectDeform mMovingDeform, mReleasedDeform; |
|
79 |
|
|
80 |
private Dynamic3D mReleasedDistortDynamic, mReleasedDeformDynamic, mReleasedShearDynamic; |
|
81 |
|
|
82 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 84 |
|
84 | 85 |
DeformRenderer(GLSurfaceView view) |
85 | 86 |
{ |
86 | 87 |
mView = view; |
88 |
mResources = view.getResources(); |
|
87 | 89 |
|
88 | 90 |
mTexture = new DistortedTexture(); |
89 | 91 |
mEffects = new DistortedEffects(); |
... | ... | |
233 | 235 |
VertexEffectDistort.enable(); |
234 | 236 |
VertexEffectDeform.enable(); |
235 | 237 |
|
236 |
DistortedLibrary.onSurfaceCreated(mView.getContext(),this); |
|
237 |
} |
|
238 |
|
|
239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
240 |
|
|
241 |
public void distortedException(Exception ex) |
|
242 |
{ |
|
243 |
android.util.Log.e("Deform", ex.getMessage() ); |
|
238 |
DistortedLibrary.onSurfaceCreated(this); |
|
244 | 239 |
} |
245 | 240 |
|
246 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
327 | 322 |
break; |
328 | 323 |
} |
329 | 324 |
} |
325 |
|
|
326 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
327 |
|
|
328 |
public void distortedException(Exception ex) |
|
329 |
{ |
|
330 |
android.util.Log.e("Deform", ex.getMessage() ); |
|
331 |
} |
|
332 |
|
|
333 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
334 |
|
|
335 |
public int openGlVersion() |
|
336 |
{ |
|
337 |
Context context = mView.getContext(); |
|
338 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
339 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
340 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
341 |
int major = glESversion >> 16; |
|
342 |
int minor = glESversion & 0xff; |
|
343 |
|
|
344 |
return 100*major + 10*minor; |
|
345 |
} |
|
346 |
|
|
347 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
348 |
|
|
349 |
public InputStream localFile(int fileID) |
|
350 |
{ |
|
351 |
return mResources.openRawResource(fileID); |
|
352 |
} |
|
353 |
|
|
354 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
355 |
|
|
356 |
public void logMessage(String message) |
|
357 |
{ |
|
358 |
android.util.Log.e("Deform", message ); |
|
359 |
} |
|
330 | 360 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.