1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
71c8884f
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
bc0a685b
|
Leszek Koltunski
|
// //
|
6 |
71c8884f
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
bc0a685b
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
71c8884f
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
bc0a685b
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
71c8884f
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
758303a3
|
Leszek Koltunski
|
package org.distorted.examples.effectqueue;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
e4330c89
|
Leszek Koltunski
|
import android.app.ActivityManager;
|
23 |
427ab7bf
|
Leszek Koltunski
|
import android.content.Context;
|
24 |
e4330c89
|
Leszek Koltunski
|
import android.content.pm.ConfigurationInfo;
|
25 |
427ab7bf
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
26 |
|
|
import android.view.MotionEvent;
|
27 |
|
|
import android.util.AttributeSet;
|
28 |
|
|
|
29 |
a4d59c0b
|
Leszek Koltunski
|
import org.distorted.library.effect.Effect;
|
30 |
8dfa45c4
|
leszek
|
import org.distorted.library.effect.FragmentEffectAlpha;
|
31 |
|
|
import org.distorted.library.effect.FragmentEffectChroma;
|
32 |
|
|
import org.distorted.library.effect.FragmentEffectSaturation;
|
33 |
|
|
import org.distorted.library.effect.VertexEffectDistort;
|
34 |
|
|
import org.distorted.library.effect.VertexEffectSink;
|
35 |
59759251
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
36 |
|
|
import org.distorted.library.type.Static1D;
|
37 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
38 |
|
|
import org.distorted.library.type.Static4D;
|
39 |
|
|
import org.distorted.library.type.Dynamic3D;
|
40 |
427ab7bf
|
Leszek Koltunski
|
|
41 |
8eed34d3
|
Leszek Koltunski
|
import static org.distorted.examples.effectqueue.EffectQueueRenderer.*;
|
42 |
|
|
|
43 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
427ab7bf
|
Leszek Koltunski
|
|
45 |
758303a3
|
Leszek Koltunski
|
public class EffectQueueSurfaceView extends GLSurfaceView
|
46 |
bc0a685b
|
Leszek Koltunski
|
{
|
47 |
5601cfa6
|
Leszek Koltunski
|
private static final float RADIUS = 0.15f;
|
48 |
30c47368
|
Leszek Koltunski
|
|
49 |
758303a3
|
Leszek Koltunski
|
private EffectQueueRenderer mRenderer;
|
50 |
3f07bedc
|
Leszek Koltunski
|
private int mCurrentEffect;
|
51 |
|
|
private int mScrW, mScrH;
|
52 |
427ab7bf
|
Leszek Koltunski
|
|
53 |
3f07bedc
|
Leszek Koltunski
|
private Dynamic1D mInterA, mInterB, mInterC, mInterS;
|
54 |
|
|
private Dynamic3D mInterD;
|
55 |
f9afbbf3
|
Leszek Koltunski
|
|
56 |
a4d59c0b
|
Leszek Koltunski
|
private final static Static3D RED = new Static3D(1,0,0);
|
57 |
|
|
private final static Static3D REGION_F = new Static3D(RADIUS,RADIUS,RADIUS);
|
58 |
|
|
private final static Static4D REGION_V = new Static4D(0,0,0,RADIUS);
|
59 |
f9afbbf3
|
Leszek Koltunski
|
|
60 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
427ab7bf
|
Leszek Koltunski
|
|
62 |
41a81a14
|
Leszek Koltunski
|
public EffectQueueSurfaceView(Context context, AttributeSet attrs)
|
63 |
bc0a685b
|
Leszek Koltunski
|
{
|
64 |
41a81a14
|
Leszek Koltunski
|
super(context, attrs);
|
65 |
427ab7bf
|
Leszek Koltunski
|
|
66 |
3f07bedc
|
Leszek Koltunski
|
int duration = 10000;
|
67 |
|
|
float count = 1.0f;
|
68 |
5601cfa6
|
Leszek Koltunski
|
float h = 50.0f/BWID;
|
69 |
|
|
float r = 20.0f/BWID;
|
70 |
59759251
|
Leszek Koltunski
|
|
71 |
3f07bedc
|
Leszek Koltunski
|
mInterD = new Dynamic3D(duration,count);
|
72 |
59759251
|
Leszek Koltunski
|
|
73 |
3f07bedc
|
Leszek Koltunski
|
mInterD.add(new Static3D( 0, r, h ));
|
74 |
|
|
mInterD.add(new Static3D(-r, 0, h ));
|
75 |
|
|
mInterD.add(new Static3D( 0,-r, h ));
|
76 |
|
|
mInterD.add(new Static3D( r, 0, h ));
|
77 |
59759251
|
Leszek Koltunski
|
|
78 |
3f07bedc
|
Leszek Koltunski
|
mInterA = new Dynamic1D(duration,count);
|
79 |
59759251
|
Leszek Koltunski
|
mInterA.add(new Static1D(1));
|
80 |
|
|
mInterA.add(new Static1D(0));
|
81 |
|
|
|
82 |
3f07bedc
|
Leszek Koltunski
|
mInterS = new Dynamic1D(duration,count);
|
83 |
b5cc7760
|
Leszek Koltunski
|
mInterS.add(new Static1D(1.0f));
|
84 |
|
|
mInterS.add(new Static1D(0.3f));
|
85 |
|
|
|
86 |
3f07bedc
|
Leszek Koltunski
|
mInterC = new Dynamic1D(duration,count);
|
87 |
f9afbbf3
|
Leszek Koltunski
|
mInterC.add(new Static1D(1));
|
88 |
|
|
mInterC.add(new Static1D(0));
|
89 |
59759251
|
Leszek Koltunski
|
|
90 |
3f07bedc
|
Leszek Koltunski
|
mInterB = new Dynamic1D(duration,count);
|
91 |
bdfec906
|
Leszek Koltunski
|
mInterB.add(new Static1D(0));
|
92 |
|
|
mInterB.add(new Static1D(1));
|
93 |
427ab7bf
|
Leszek Koltunski
|
|
94 |
bc0a685b
|
Leszek Koltunski
|
if(!isInEditMode())
|
95 |
|
|
{
|
96 |
|
|
setFocusable(true);
|
97 |
|
|
setFocusableInTouchMode(true);
|
98 |
758303a3
|
Leszek Koltunski
|
mRenderer = new EffectQueueRenderer(this);
|
99 |
e4330c89
|
Leszek Koltunski
|
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
100 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
101 |
|
|
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
|
102 |
bc0a685b
|
Leszek Koltunski
|
setRenderer(mRenderer);
|
103 |
a4d59c0b
|
Leszek Koltunski
|
setEffect(0);
|
104 |
427ab7bf
|
Leszek Koltunski
|
}
|
105 |
bc0a685b
|
Leszek Koltunski
|
}
|
106 |
427ab7bf
|
Leszek Koltunski
|
|
107 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
427ab7bf
|
Leszek Koltunski
|
|
109 |
758303a3
|
Leszek Koltunski
|
EffectQueueRenderer getRenderer()
|
110 |
3f07bedc
|
Leszek Koltunski
|
{
|
111 |
|
|
return mRenderer;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
|
|
public void setScreenSize(int width, int height)
|
117 |
bc0a685b
|
Leszek Koltunski
|
{
|
118 |
|
|
mScrW = width;
|
119 |
|
|
mScrH = height;
|
120 |
|
|
}
|
121 |
427ab7bf
|
Leszek Koltunski
|
|
122 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
427ab7bf
|
Leszek Koltunski
|
|
124 |
3f07bedc
|
Leszek Koltunski
|
public void setEffect(int effect)
|
125 |
bc0a685b
|
Leszek Koltunski
|
{
|
126 |
|
|
mCurrentEffect = effect;
|
127 |
|
|
}
|
128 |
427ab7bf
|
Leszek Koltunski
|
|
129 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
427ab7bf
|
Leszek Koltunski
|
|
131 |
a4d59c0b
|
Leszek Koltunski
|
@Override
|
132 |
|
|
public boolean onTouchEvent(MotionEvent event)
|
133 |
bc0a685b
|
Leszek Koltunski
|
{
|
134 |
5601cfa6
|
Leszek Koltunski
|
int action = event.getAction();
|
135 |
a4d59c0b
|
Leszek Koltunski
|
Effect effect;
|
136 |
8dfa45c4
|
leszek
|
boolean success;
|
137 |
5601cfa6
|
Leszek Koltunski
|
float x,y;
|
138 |
af225332
|
Leszek Koltunski
|
|
139 |
5601cfa6
|
Leszek Koltunski
|
if(action==MotionEvent.ACTION_DOWN)
|
140 |
427ab7bf
|
Leszek Koltunski
|
{
|
141 |
5601cfa6
|
Leszek Koltunski
|
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 |
|
|
}
|
169 |
427ab7bf
|
Leszek Koltunski
|
}
|
170 |
af225332
|
Leszek Koltunski
|
|
171 |
bc0a685b
|
Leszek Koltunski
|
return true;
|
172 |
|
|
}
|
173 |
af225332
|
Leszek Koltunski
|
|
174 |
427ab7bf
|
Leszek Koltunski
|
}
|