Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.singlemesh; |
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.Canvas; |
24 | 28 |
import android.graphics.Paint; |
25 | 29 |
import android.opengl.GLSurfaceView; |
26 | 30 |
|
27 |
import org.distorted.library.effect.EffectType; |
|
28 | 31 |
import org.distorted.library.effect.MatrixEffectMove; |
29 | 32 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
30 | 33 |
import org.distorted.library.effect.MatrixEffectScale; |
... | ... | |
45 | 48 |
import org.distorted.library.type.Static3D; |
46 | 49 |
import org.distorted.library.type.Static4D; |
47 | 50 |
|
51 |
import java.io.InputStream; |
|
52 |
|
|
48 | 53 |
import javax.microedition.khronos.egl.EGLConfig; |
49 | 54 |
import javax.microedition.khronos.opengles.GL10; |
50 | 55 |
|
51 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
52 | 57 |
|
53 |
class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
58 |
class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
54 | 59 |
{ |
55 | 60 |
private static final float DIST = 0.5f; |
56 | 61 |
|
57 |
private static Static3D[] AXIS = new Static3D[] |
|
62 |
private static final Static3D[] AXIS = new Static3D[]
|
|
58 | 63 |
{ |
59 | 64 |
new Static3D(1,0,0), |
60 | 65 |
new Static3D(0,1,0), |
... | ... | |
102 | 107 |
new Static3D(+DIST,+DIST,+DIST), |
103 | 108 |
}; |
104 | 109 |
|
105 |
private GLSurfaceView mView; |
|
110 |
private final GLSurfaceView mView; |
|
111 |
private final Resources mResources; |
|
112 |
private final DistortedScreen mScreen; |
|
113 |
private final DistortedEffects mEffects; |
|
114 |
private final Static3D mScale; |
|
115 |
private final VertexEffectRotate mRotate; |
|
116 |
private final Dynamic1D mAngleDyn; |
|
117 |
private final Static1D mAngle; |
|
118 |
private final Static3D mAxis; |
|
119 |
|
|
106 | 120 |
private DistortedTexture mTexture; |
107 |
private DistortedScreen mScreen; |
|
108 |
private DistortedEffects mEffects; |
|
109 |
private Static3D mScale; |
|
110 | 121 |
private MeshBase mMesh; |
111 |
private VertexEffectRotate mRotate; |
|
112 |
private Dynamic1D mAngleDyn; |
|
113 |
private Static1D mAngle; |
|
114 |
private Static3D mAxis; |
|
115 | 122 |
|
116 | 123 |
Static4D mQuat1, mQuat2; |
117 | 124 |
int mScreenMin; |
... | ... | |
121 | 128 |
SingleMeshRenderer(GLSurfaceView v) |
122 | 129 |
{ |
123 | 130 |
mView = v; |
131 |
mResources = v.getResources(); |
|
132 |
|
|
124 | 133 |
mScreen = new DistortedScreen(); |
125 | 134 |
mScale= new Static3D(1,1,1); |
126 | 135 |
Static3D center=new Static3D(0,0,0); |
... | ... | |
184 | 193 |
|
185 | 194 |
VertexEffectRotate.enable(); |
186 | 195 |
|
187 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this); |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
public void distortedException(Exception ex) |
|
193 |
{ |
|
194 |
android.util.Log.e("SingleMesh", ex.getMessage() ); |
|
196 |
DistortedLibrary.onSurfaceCreated(this); |
|
195 | 197 |
} |
196 | 198 |
|
197 | 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
270 | 272 |
float d2 =-0.05f; |
271 | 273 |
float d3 = 0.12f; |
272 | 274 |
|
273 |
Static3D dCen0 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(+0.5f) );
|
|
274 |
Static3D dCen1 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(-0.5f) );
|
|
275 |
Static3D dCen2 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(+0.5f) );
|
|
276 |
Static3D dCen3 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(-0.5f) );
|
|
277 |
Static3D dCen4 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(+0.5f) );
|
|
278 |
Static3D dCen5 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(-0.5f) );
|
|
279 |
Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(+0.5f) );
|
|
275 |
Static3D dCen0 = new Static3D( d1*( 0.5f), d1*( 0.5f), d1*( 0.5f) );
|
|
276 |
Static3D dCen1 = new Static3D( d1*( 0.5f), d1*( 0.5f), d1*(-0.5f) );
|
|
277 |
Static3D dCen2 = new Static3D( d1*( 0.5f), d1*(-0.5f), d1*( 0.5f) );
|
|
278 |
Static3D dCen3 = new Static3D( d1*( 0.5f), d1*(-0.5f), d1*(-0.5f) );
|
|
279 |
Static3D dCen4 = new Static3D( d1*(-0.5f), d1*( 0.5f), d1*( 0.5f) );
|
|
280 |
Static3D dCen5 = new Static3D( d1*(-0.5f), d1*( 0.5f), d1*(-0.5f) );
|
|
281 |
Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*( 0.5f) );
|
|
280 | 282 |
Static3D dCen7 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(-0.5f) ); |
281 | 283 |
|
282 |
Static3D dVec0 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(+0.5f) );
|
|
283 |
Static3D dVec1 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(-0.5f) );
|
|
284 |
Static3D dVec2 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(+0.5f) );
|
|
285 |
Static3D dVec3 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(-0.5f) );
|
|
286 |
Static3D dVec4 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(+0.5f) );
|
|
287 |
Static3D dVec5 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(-0.5f) );
|
|
288 |
Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(+0.5f) );
|
|
284 |
Static3D dVec0 = new Static3D( d2*( 0.5f), d2*( 0.5f), d2*( 0.5f) );
|
|
285 |
Static3D dVec1 = new Static3D( d2*( 0.5f), d2*( 0.5f), d2*(-0.5f) );
|
|
286 |
Static3D dVec2 = new Static3D( d2*( 0.5f), d2*(-0.5f), d2*( 0.5f) );
|
|
287 |
Static3D dVec3 = new Static3D( d2*( 0.5f), d2*(-0.5f), d2*(-0.5f) );
|
|
288 |
Static3D dVec4 = new Static3D( d2*(-0.5f), d2*( 0.5f), d2*( 0.5f) );
|
|
289 |
Static3D dVec5 = new Static3D( d2*(-0.5f), d2*( 0.5f), d2*(-0.5f) );
|
|
290 |
Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*( 0.5f) );
|
|
289 | 291 |
Static3D dVec7 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(-0.5f) ); |
290 | 292 |
|
291 | 293 |
Static4D dReg = new Static4D(0,0,0,d3); |
... | ... | |
369 | 371 |
|
370 | 372 |
return result; |
371 | 373 |
} |
374 |
|
|
375 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
376 |
|
|
377 |
public void distortedException(Exception ex) |
|
378 |
{ |
|
379 |
android.util.Log.e("SingleMesh", ex.getMessage() ); |
|
380 |
} |
|
381 |
|
|
382 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
383 |
|
|
384 |
public int openGlVersion() |
|
385 |
{ |
|
386 |
Context context = mView.getContext(); |
|
387 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
388 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
389 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
390 |
int major = glESversion >> 16; |
|
391 |
int minor = glESversion & 0xff; |
|
392 |
|
|
393 |
return 100*major + 10*minor; |
|
394 |
} |
|
395 |
|
|
396 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
397 |
|
|
398 |
public InputStream localFile(int fileID) |
|
399 |
{ |
|
400 |
return mResources.openRawResource(fileID); |
|
401 |
} |
|
402 |
|
|
403 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
404 |
|
|
405 |
public void logMessage(String message) |
|
406 |
{ |
|
407 |
android.util.Log.e("SingleMesh", message ); |
|
408 |
} |
|
372 | 409 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.