Revision 4b7c432e
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/examples/predeform/PredeformRenderer.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.predeform; |
21 | 21 |
|
22 |
import android.graphics.Bitmap; |
|
23 | 22 |
import android.opengl.GLSurfaceView; |
24 | 23 |
|
24 |
import org.distorted.library.effect.FragmentEffectAlpha; |
|
25 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
25 | 26 |
import org.distorted.library.effect.MatrixEffectScale; |
27 |
import org.distorted.library.effect.VertexEffectScale; |
|
26 | 28 |
import org.distorted.library.main.DistortedEffects; |
27 | 29 |
import org.distorted.library.main.DistortedLibrary; |
28 | 30 |
import org.distorted.library.main.DistortedScreen; |
29 | 31 |
import org.distorted.library.main.DistortedTexture; |
30 | 32 |
import org.distorted.library.mesh.MeshBase; |
33 |
import org.distorted.library.type.DynamicQuat; |
|
34 |
import org.distorted.library.type.Static1D; |
|
31 | 35 |
import org.distorted.library.type.Static3D; |
36 |
import org.distorted.library.type.Static4D; |
|
32 | 37 |
|
33 | 38 |
import javax.microedition.khronos.egl.EGLConfig; |
34 | 39 |
import javax.microedition.khronos.opengles.GL10; |
... | ... | |
37 | 42 |
|
38 | 43 |
class PredeformRenderer implements GLSurfaceView.Renderer |
39 | 44 |
{ |
40 |
private static final float FOV = 0.0f;
|
|
45 |
private static final float FOV = 30.0f;
|
|
41 | 46 |
private static final float NEAR = 0.1f; |
42 | 47 |
|
43 | 48 |
private GLSurfaceView mView; |
... | ... | |
45 | 50 |
private DistortedEffects mEffects; |
46 | 51 |
private MeshBase mMesh; |
47 | 52 |
private DistortedScreen mScreen; |
53 |
private float mObjWidth, mObjHeight, mObjDepth; |
|
48 | 54 |
private Static3D mScale; |
55 |
private Static1D mAlpha; |
|
56 |
|
|
57 |
Static4D mQuat1, mQuat2; |
|
58 |
int mScreenMin; |
|
49 | 59 |
|
50 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 61 |
|
... | ... | |
53 | 63 |
{ |
54 | 64 |
mView = v; |
55 | 65 |
|
66 |
mAlpha = new Static1D(1.0f); |
|
56 | 67 |
mScale= new Static3D(1,1,1); |
57 |
mTexture = new DistortedTexture(); |
|
68 |
|
|
69 |
Static3D center=new Static3D(0,0,0); |
|
70 |
|
|
71 |
PredeformActivity2 act = (PredeformActivity2)v.getContext(); |
|
72 |
|
|
73 |
mTexture = act.getTexture(); |
|
74 |
mMesh = act.getMesh(); |
|
75 |
|
|
76 |
mObjWidth = act.getCols(); |
|
77 |
mObjHeight= act.getRows(); |
|
78 |
mObjDepth = act.getSlic(); |
|
79 |
|
|
80 |
mQuat1 = new Static4D(0,0,0,1); // unity |
|
81 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
|
82 |
|
|
83 |
DynamicQuat quatInt1 = new DynamicQuat(0,0.5f); |
|
84 |
DynamicQuat quatInt2 = new DynamicQuat(0,0.5f); |
|
85 |
|
|
86 |
quatInt1.add(mQuat1); |
|
87 |
quatInt2.add(mQuat2); |
|
88 |
|
|
58 | 89 |
mEffects = new DistortedEffects(); |
90 |
mEffects.apply( new VertexEffectScale(new Static3D(mObjWidth,mObjHeight,mObjDepth) ) ); |
|
59 | 91 |
mEffects.apply( new MatrixEffectScale(mScale)); |
92 |
mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) ); |
|
93 |
mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) ); |
|
94 |
mEffects.apply( new FragmentEffectAlpha(mAlpha)); |
|
60 | 95 |
|
61 | 96 |
mScreen = new DistortedScreen(); |
62 | 97 |
mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f); |
... | ... | |
64 | 99 |
} |
65 | 100 |
|
66 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
102 |
|
|
103 |
public void onDrawFrame(GL10 glUnused) |
|
104 |
{ |
|
105 |
mScreen.render( System.currentTimeMillis() ); |
|
106 |
} |
|
67 | 107 |
|
68 |
void setMesh(MeshBase mesh) |
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
|
|
110 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
69 | 111 |
{ |
70 |
mMesh = mesh; |
|
112 |
final float SCALE = 0.75f; |
|
113 |
|
|
114 |
mScreenMin = Math.min(width, height); |
|
115 |
float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight : (SCALE*width)/mObjWidth; |
|
116 |
mScale.set(factor,factor,factor); |
|
117 |
mScreen.resize(width, height); |
|
71 | 118 |
} |
72 | 119 |
|
73 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | 121 |
|
75 |
void setTexture(Bitmap bmp)
|
|
122 |
void setRenderModeToOIT(boolean oit)
|
|
76 | 123 |
{ |
77 |
mTexture.setTexture(bmp);
|
|
124 |
mScreen.setOrderIndependentTransparency(oit);
|
|
78 | 125 |
} |
79 | 126 |
|
80 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
81 | 128 |
|
82 |
public void onDrawFrame(GL10 glUnused)
|
|
129 |
void setTransparency(int level)
|
|
83 | 130 |
{ |
84 |
mScreen.render( System.currentTimeMillis() );
|
|
131 |
mAlpha.set((float)level/100.0f);
|
|
85 | 132 |
} |
86 | 133 |
|
87 | 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
88 |
|
|
89 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
135 |
|
|
136 |
float setLevel(int level)
|
|
90 | 137 |
{ |
91 |
final float SCALE = 0.75f; |
|
138 |
float inflateLevel = (level-50)/50.0f; |
|
139 |
mMesh.setInflate(inflateLevel); |
|
92 | 140 |
|
93 |
float factor = ( width > height ) ? SCALE*height : SCALE*width; |
|
94 |
mScale.set(factor,factor,factor); |
|
95 |
mScreen.resize(width, height); |
|
141 |
return inflateLevel; |
|
96 | 142 |
} |
97 | 143 |
|
98 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
99 | 145 |
|
100 | 146 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
101 | 147 |
{ |
102 |
PredeformActivity act = (PredeformActivity)mView.getContext();
|
|
148 |
PredeformActivity2 act = (PredeformActivity2)mView.getContext();
|
|
103 | 149 |
|
104 |
mMesh = act.getMesh(); |
|
105 | 150 |
mTexture.setTexture( act.getBitmap() ); |
106 | 151 |
mScreen.detachAll(); |
107 | 152 |
mScreen.attach(mTexture,mEffects,mMesh); |
108 | 153 |
|
154 |
VertexEffectScale.enable(); |
|
155 |
FragmentEffectAlpha.enable(); |
|
156 |
|
|
109 | 157 |
try |
110 | 158 |
{ |
111 | 159 |
DistortedLibrary.onCreate(act); |
Also available in: Unified diff
Progress (?) with Predeform: give up trying to render the Mesh in Activity1.