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