Revision dc10a48d
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/examples/meshjoin/MeshJoinRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.meshjoin; |
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.MatrixEffectQuaternion; |
29 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
30 | 33 |
import org.distorted.library.effect.VertexEffectDeform; |
... | ... | |
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 MeshJoinRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
|
58 |
class MeshJoinRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
|
54 | 59 |
{ |
55 |
private GLSurfaceView mView; |
|
60 |
private final GLSurfaceView mView; |
|
61 |
private final Resources mResources; |
|
62 |
private final DistortedScreen mScreen; |
|
63 |
private final DistortedEffects mEffects; |
|
64 |
private final Static3D mScale; |
|
65 |
private final VertexEffectSink mSink; |
|
66 |
|
|
56 | 67 |
private DistortedTexture mTexture; |
57 |
private DistortedScreen mScreen; |
|
58 |
private DistortedEffects mEffects; |
|
59 |
private Static3D mScale; |
|
60 | 68 |
private MeshBase mMesh; |
61 | 69 |
private int mSinkAssociation; |
62 |
private VertexEffectSink mSink; |
|
63 | 70 |
|
64 | 71 |
Static4D mQuat1, mQuat2; |
65 | 72 |
int mScreenMin; |
... | ... | |
69 | 76 |
MeshJoinRenderer(GLSurfaceView v) |
70 | 77 |
{ |
71 | 78 |
mView = v; |
79 |
mResources = v.getResources(); |
|
80 |
|
|
72 | 81 |
mScreen = new DistortedScreen(); |
73 | 82 |
mScale= new Static3D(1,1,1); |
74 | 83 |
Static3D center=new Static3D(0,0,0); |
... | ... | |
131 | 140 |
|
132 | 141 |
VertexEffectSink.enable(); |
133 | 142 |
|
134 |
DistortedLibrary.onSurfaceCreated(mView.getContext(), this); |
|
135 |
} |
|
136 |
|
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
|
|
139 |
public void distortedException(Exception ex) |
|
140 |
{ |
|
141 |
android.util.Log.e("MeshJoin", ex.getMessage() ); |
|
143 |
DistortedLibrary.onSurfaceCreated(this); |
|
142 | 144 |
} |
143 | 145 |
|
144 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
249 | 251 |
Static1D angle = new Static1D(angleFaces); |
250 | 252 |
Static3D axis1 = new Static3D( -1, 0, 0); |
251 | 253 |
Static3D axis2 = new Static3D(0.5f, 0, -SQ3/2); |
252 |
Static3D axis3 = new Static3D(0.5f, 0, +SQ3/2);
|
|
254 |
Static3D axis3 = new Static3D(0.5f, 0, SQ3/2);
|
|
253 | 255 |
Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6); |
254 |
Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
|
|
256 |
Static3D center2= new Static3D(0,-SQ3*SQ2/12, SQ3/3);
|
|
255 | 257 |
|
256 | 258 |
VertexEffectScale effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) ); |
257 | 259 |
VertexEffectRotate effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) ); |
... | ... | |
285 | 287 |
|
286 | 288 |
return result; |
287 | 289 |
} |
290 |
|
|
291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
292 |
|
|
293 |
public void distortedException(Exception ex) |
|
294 |
{ |
|
295 |
android.util.Log.e("MeshJoin", ex.getMessage() ); |
|
296 |
} |
|
297 |
|
|
298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
299 |
|
|
300 |
public int openGlVersion() |
|
301 |
{ |
|
302 |
Context context = mView.getContext(); |
|
303 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
304 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
305 |
int glESversion = configurationInfo.reqGlEsVersion; |
|
306 |
int major = glESversion >> 16; |
|
307 |
int minor = glESversion & 0xff; |
|
308 |
|
|
309 |
return 100*major + 10*minor; |
|
310 |
} |
|
311 |
|
|
312 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
313 |
|
|
314 |
public InputStream localFile(int fileID) |
|
315 |
{ |
|
316 |
return mResources.openRawResource(fileID); |
|
317 |
} |
|
318 |
|
|
319 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
320 |
|
|
321 |
public void logMessage(String message) |
|
322 |
{ |
|
323 |
android.util.Log.e("MeshJoin", message ); |
|
324 |
} |
|
288 | 325 |
} |
Also available in: Unified diff
Decouple (to a large degree) the OpenGL Library from Android.