Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/earth/EarthRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.earth; |
21 | 21 |
|
22 |
import android.app.ActivityManager; |
|
23 |
import android.content.Context; |
|
24 |
import android.content.pm.ConfigurationInfo; |
|
25 |
import android.content.res.Resources; |
|
22 | 26 |
import android.graphics.Bitmap; |
23 | 27 |
import android.graphics.BitmapFactory; |
24 | 28 |
import android.opengl.GLSurfaceView; |
... | ... | |
62 | 66 |
|
63 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 68 |
|
65 |
class EarthRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
69 |
class EarthRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
66 | 70 |
{ |
67 | 71 |
private static final float RADIUS_V= 1.0f/ 8; |
68 | 72 |
private static final float RADIUS_F= 1.0f/15; |
... | ... | |
71 | 75 |
private static final float NEAR = 0.1f; |
72 | 76 |
private static final float SCALE = 1.10f; |
73 | 77 |
|
74 |
private GLSurfaceView mView; |
|
75 |
private DistortedTexture mTexture; |
|
76 |
private DistortedEffects mEffects; |
|
77 |
private MeshBase mMesh; |
|
78 |
private DistortedScreen mScreen; |
|
79 |
private float mObjWidth, mObjHeight, mObjDepth; |
|
80 |
private Static3D mMove, mScaleFactor; |
|
78 |
private final GLSurfaceView mView; |
|
79 |
private final Resources mResources; |
|
80 |
private final DistortedTexture mTexture; |
|
81 |
private final DistortedEffects mEffects; |
|
82 |
private final MeshBase mMesh; |
|
83 |
private final DistortedScreen mScreen; |
|
84 |
private final Static1D mStrength, mSwirl; |
|
85 |
private final Static3D mMove, mScaleFactor, mColor,mRegionF,mPinch; |
|
86 |
private final Static4D mRegionV; |
|
87 |
private final float mObjWidth, mObjHeight, mObjDepth; |
|
81 | 88 |
|
82 | 89 |
private int mScrWidth, mScrHeight; |
83 | 90 |
private float mLevel; |
84 | 91 |
|
85 |
private Static3D mColor; |
|
86 |
private Static3D mRegionF; |
|
87 |
private Static4D mRegionV; |
|
88 |
private Static1D mStrength; |
|
89 |
private Static3D mPinch; |
|
90 |
private Static1D mSwirl; |
|
91 |
|
|
92 | 92 |
Static4D mQuat1, mQuat2; |
93 | 93 |
int mScreenMin; |
94 | 94 |
|
... | ... | |
97 | 97 |
EarthRenderer(GLSurfaceView v) |
98 | 98 |
{ |
99 | 99 |
mView = v; |
100 |
mResources = v.getResources(); |
|
100 | 101 |
|
101 | 102 |
mLevel = SCALE; |
102 | 103 |
|
... | ... | |
204 | 205 |
|
205 | 206 |
switch(name) |
206 | 207 |
{ |
207 |
case DISTORT : vector = new Static3D( +x*mObjWidth/CORR, +y*mObjHeight/CORR, +z*mObjDepth/CORR);
|
|
208 |
case DISTORT : vector = new Static3D( x*mObjWidth/CORR, y*mObjHeight/CORR, z*mObjDepth/CORR);
|
|
208 | 209 |
effect = new VertexEffectDistort( vector, center, mRegionV); break; |
209 |
case DEFORM : vector = new Static3D( +x*mObjWidth/CORR, +y*mObjHeight/CORR, +z*mObjDepth/CORR);
|
|
210 |
case DEFORM : vector = new Static3D( x*mObjWidth/CORR, y*mObjHeight/CORR, z*mObjDepth/CORR);
|
|
210 | 211 |
Static1D radius = new Static1D(mObjWidth/2); |
211 | 212 |
effect = new VertexEffectDeform ( vector, radius, center, mRegionV); break; |
212 | 213 |
case SINK : effect = new VertexEffectSink (mStrength, center, mRegionV); break; |
... | ... | |
232 | 233 |
case CONTRAST : effect = new FragmentEffectContrast (mStrength, center, mRegionF, false); break; |
233 | 234 |
case SMOOTH_CONTRAST : effect = new FragmentEffectContrast (mStrength, center, mRegionF, true ); break; |
234 | 235 |
|
235 |
default : android.util.Log.e("EarthRenderer", "unexpected effect: "+name.toString() );
|
|
236 |
default : android.util.Log.e("EarthRenderer", "unexpected effect: "+name ); |
|
236 | 237 |
} |
237 | 238 |
|
238 | 239 |
if( effect!=null ) |
... | ... | |
276 | 277 |
|
277 | 278 |
Effect.enableEffects(EffectType.FRAGMENT); |
278 | 279 |
Effect.enableEffects(EffectType.VERTEX); |
279 |
|
|
280 | 280 |
DistortedLibrary.setMax(EffectType.FRAGMENT, 20); |
281 |
|
|
282 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this); |
|
281 |
DistortedLibrary.onSurfaceCreated(this); |
|
283 | 282 |
} |
284 | 283 |
|
285 | 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
288 | 287 |
{ |
289 | 288 |
android.util.Log.e("Earth", ex.getMessage() ); |
290 | 289 |
} |
290 |
|
|
291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
292 |
|
|
293 |
public int openGlVersion() |
|
294 |
{ |
|
295 |
Context context = mView.getContext(); |
|
296 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
297 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
298 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
299 |
int major = glESversion >> 16; |
|
300 |
int minor = glESversion & 0xff; |
|
301 |
|
|
302 |
return 100*major + 10*minor; |
|
303 |
} |
|
304 |
|
|
305 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
306 |
|
|
307 |
public InputStream localFile(int fileID) |
|
308 |
{ |
|
309 |
return mResources.openRawResource(fileID); |
|
310 |
} |
|
311 |
|
|
312 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
313 |
|
|
314 |
public void logMessage(String message) |
|
315 |
{ |
|
316 |
android.util.Log.e("Earth", message ); |
|
317 |
} |
|
291 | 318 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.