Revision 5601cfa6
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/effectqueue/EffectQueueActivity.java | ||
---|---|---|
22 | 22 |
import org.distorted.library.effect.Effect; |
23 | 23 |
import org.distorted.library.effect.EffectName; |
24 | 24 |
import org.distorted.library.effect.EffectType; |
25 |
import org.distorted.library.main.DistortedEffects; |
|
25 | 26 |
import org.distorted.library.main.DistortedLibrary; |
26 | 27 |
import org.distorted.examples.R; |
27 | 28 |
|
... | ... | |
38 | 39 |
import android.widget.Toast; |
39 | 40 |
|
40 | 41 |
import java.util.ArrayList; |
41 |
import java.util.HashMap; |
|
42 | 42 |
|
43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 44 |
|
... | ... | |
50 | 50 |
private int mPosID, mPosName, mPosType; |
51 | 51 |
private TableLayout mLayoutList; |
52 | 52 |
|
53 |
private class EffectRow |
|
53 |
private static class EffectRow
|
|
54 | 54 |
{ |
55 | 55 |
Effect effect; |
56 | 56 |
TableRow row; |
... | ... | |
267 | 267 |
} |
268 | 268 |
|
269 | 269 |
EffectQueueSurfaceView v = findViewById(R.id.effects2dSurfaceView); |
270 |
v.getRenderer().getEffects().abortByType(type); |
|
270 |
|
|
271 |
DistortedEffects effects = v.getRenderer().getEffects(); |
|
272 |
effects.abortByType(type); |
|
271 | 273 |
} |
272 | 274 |
|
273 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/examples/effectqueue/EffectQueueRenderer.java | ||
---|---|---|
45 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 46 |
|
47 | 47 |
class EffectQueueRenderer implements GLSurfaceView.Renderer, EffectListener |
48 |
{
|
|
48 |
{ |
|
49 | 49 |
private static final int NUMLINES = 10; |
50 | 50 |
private static final int MESH_QUALITY = 100; |
51 | 51 |
static final int BWID = 600; |
... | ... | |
78 | 78 |
MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale); |
79 | 79 |
|
80 | 80 |
mMesh = new MeshRectangles(MESH_QUALITY,MESH_QUALITY*texHeight/texWidth); |
81 |
mMesh.setStretch(texWidth,texHeight,0); |
|
82 | 81 |
|
83 | 82 |
mTexture = new DistortedTexture(); |
84 | 83 |
mEffects = new DistortedEffects(); |
... | ... | |
135 | 134 |
|
136 | 135 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
137 | 136 |
{ |
138 |
mScale.set((float)width/texWidth,(float)height/texHeight,1); |
|
137 |
// (w+h)/2 because we need to stretch more or less uniformly in all 3 directions. |
|
138 |
// If we set it to 0, Distort would not be shaded. If we set it to 1, the Distorted normal |
|
139 |
// vectors would get stretched only in X and Y dirs, becoming very 'flat' and the Distorted |
|
140 |
// area very dark. |
|
141 |
mScale.set(width, height, (width+height)*0.5f); |
|
142 |
|
|
139 | 143 |
mScreen.resize(width,height); |
140 | 144 |
mView.setScreenSize(width,height); |
141 | 145 |
} |
src/main/java/org/distorted/examples/effectqueue/EffectQueueSurfaceView.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
public class EffectQueueSurfaceView extends GLSurfaceView |
46 | 46 |
{ |
47 |
private static final int RADIUS = EffectQueueRenderer.BWID/6;
|
|
47 |
private static final float RADIUS = 0.15f;
|
|
48 | 48 |
|
49 | 49 |
private EffectQueueRenderer mRenderer; |
50 | 50 |
private int mCurrentEffect; |
... | ... | |
65 | 65 |
|
66 | 66 |
int duration = 10000; |
67 | 67 |
float count = 1.0f; |
68 |
int h = 30;
|
|
69 |
int r = 20;
|
|
68 |
float h = 50.0f/BWID;
|
|
69 |
float r = 20.0f/BWID;
|
|
70 | 70 |
|
71 | 71 |
mInterD = new Dynamic3D(duration,count); |
72 | 72 |
|
... | ... | |
131 | 131 |
@Override |
132 | 132 |
public boolean onTouchEvent(MotionEvent event) |
133 | 133 |
{ |
134 |
int x,y,action = event.getAction();
|
|
134 |
int action = event.getAction(); |
|
135 | 135 |
Effect effect; |
136 | 136 |
boolean success; |
137 |
float x,y; |
|
137 | 138 |
|
138 |
switch(action)
|
|
139 |
if(action==MotionEvent.ACTION_DOWN)
|
|
139 | 140 |
{ |
140 |
case MotionEvent.ACTION_DOWN: x = (int)event.getX()*BWID/mScrW - BWID/2; |
|
141 |
y = BHEI/2 - (int)event.getY()*BHEI/mScrH; |
|
142 |
EffectQueueActivity act = (EffectQueueActivity)getContext(); |
|
143 |
Static3D center = new Static3D(x,y,0); |
|
144 |
|
|
145 |
switch(mCurrentEffect) |
|
146 |
{ |
|
147 |
case 0: effect = new VertexEffectDistort (mInterD, center, REGION_V); |
|
148 |
success= mRenderer.getEffects().apply(effect); |
|
149 |
act.effectAdded(success,effect); |
|
150 |
break; |
|
151 |
case 1: effect = new VertexEffectSink (mInterS, center, REGION_V); |
|
152 |
success= mRenderer.getEffects().apply(effect); |
|
153 |
act.effectAdded(success,effect); |
|
154 |
break; |
|
155 |
case 2: effect = new FragmentEffectAlpha (mInterA, center, REGION_F, true); |
|
156 |
success= mRenderer.getEffects().apply(effect); |
|
157 |
act.effectAdded(success,effect); |
|
158 |
break; |
|
159 |
case 3: effect = new FragmentEffectSaturation(mInterB, center, REGION_F, false); |
|
160 |
success= mRenderer.getEffects().apply(effect); |
|
161 |
act.effectAdded(success,effect); |
|
162 |
break; |
|
163 |
case 4: effect = new FragmentEffectChroma (mInterC, RED, center, REGION_F, true); |
|
164 |
success= mRenderer.getEffects().apply(effect); |
|
165 |
act.effectAdded(success,effect); |
|
166 |
break; |
|
167 |
} |
|
168 |
|
|
169 |
break; |
|
141 |
x = event.getX()/mScrW - 0.5f; |
|
142 |
y = 0.5f - event.getY()/mScrH; |
|
143 |
EffectQueueActivity act = (EffectQueueActivity)getContext(); |
|
144 |
Static3D center = new Static3D(x,y,0); |
|
145 |
|
|
146 |
switch(mCurrentEffect) |
|
147 |
{ |
|
148 |
case 0: effect = new VertexEffectDistort (mInterD, center, REGION_V); |
|
149 |
success= mRenderer.getEffects().apply(effect); |
|
150 |
act.effectAdded(success,effect); |
|
151 |
break; |
|
152 |
case 1: effect = new VertexEffectSink (mInterS, center, REGION_V); |
|
153 |
success= mRenderer.getEffects().apply(effect); |
|
154 |
act.effectAdded(success,effect); |
|
155 |
break; |
|
156 |
case 2: effect = new FragmentEffectAlpha (mInterA, center, REGION_F, true); |
|
157 |
success= mRenderer.getEffects().apply(effect); |
|
158 |
act.effectAdded(success,effect); |
|
159 |
break; |
|
160 |
case 3: effect = new FragmentEffectSaturation(mInterB, center, REGION_F, false); |
|
161 |
success= mRenderer.getEffects().apply(effect); |
|
162 |
act.effectAdded(success,effect); |
|
163 |
break; |
|
164 |
case 4: effect = new FragmentEffectChroma (mInterC, RED, center, REGION_F, true); |
|
165 |
success= mRenderer.getEffects().apply(effect); |
|
166 |
act.effectAdded(success,effect); |
|
167 |
break; |
|
168 |
} |
|
170 | 169 |
} |
171 | 170 |
|
172 | 171 |
return true; |
Also available in: Unified diff
Convert the last app, EffectQueue, to stretchless API.