1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// 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 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// 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 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
758303a3
|
Leszek Koltunski
|
package org.distorted.examples.effectqueue;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import android.content.Context;
|
23 |
|
|
import android.opengl.GLSurfaceView;
|
24 |
|
|
import android.view.MotionEvent;
|
25 |
|
|
import android.util.AttributeSet;
|
26 |
|
|
|
27 |
e763f1ee
|
Leszek Koltunski
|
import org.distorted.library.EffectNames;
|
28 |
|
|
import org.distorted.library.EffectTypes;
|
29 |
59759251
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
30 |
|
|
import org.distorted.library.type.Static1D;
|
31 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
32 |
|
|
import org.distorted.library.type.Static4D;
|
33 |
|
|
import org.distorted.library.type.Dynamic3D;
|
34 |
427ab7bf
|
Leszek Koltunski
|
|
35 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
427ab7bf
|
Leszek Koltunski
|
|
37 |
758303a3
|
Leszek Koltunski
|
public class EffectQueueSurfaceView extends GLSurfaceView
|
38 |
bc0a685b
|
Leszek Koltunski
|
{
|
39 |
758303a3
|
Leszek Koltunski
|
private EffectQueueRenderer mRenderer;
|
40 |
3f07bedc
|
Leszek Koltunski
|
private int mCurrentEffect;
|
41 |
|
|
private int mScrW, mScrH;
|
42 |
427ab7bf
|
Leszek Koltunski
|
|
43 |
3f07bedc
|
Leszek Koltunski
|
private Static4D mRegionV, mRegionF;
|
44 |
334c13fa
|
Leszek Koltunski
|
private Static3D mPoint;
|
45 |
3f07bedc
|
Leszek Koltunski
|
private Dynamic1D mInterA, mInterB, mInterC, mInterS;
|
46 |
|
|
private Dynamic3D mInterD;
|
47 |
f9afbbf3
|
Leszek Koltunski
|
|
48 |
|
|
private final static Static3D mRED = new Static3D(1,0,0);
|
49 |
|
|
|
50 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
427ab7bf
|
Leszek Koltunski
|
|
52 |
758303a3
|
Leszek Koltunski
|
public EffectQueueSurfaceView(Context c, AttributeSet attrs)
|
53 |
bc0a685b
|
Leszek Koltunski
|
{
|
54 |
|
|
super(c, attrs);
|
55 |
427ab7bf
|
Leszek Koltunski
|
|
56 |
3f07bedc
|
Leszek Koltunski
|
int duration = 10000;
|
57 |
|
|
float count = 1.0f;
|
58 |
59759251
|
Leszek Koltunski
|
int h = 30;
|
59 |
|
|
int r = 20;
|
60 |
|
|
|
61 |
3f07bedc
|
Leszek Koltunski
|
mInterD = new Dynamic3D(duration,count);
|
62 |
59759251
|
Leszek Koltunski
|
|
63 |
3f07bedc
|
Leszek Koltunski
|
mInterD.add(new Static3D( 0, r, h ));
|
64 |
|
|
mInterD.add(new Static3D(-r, 0, h ));
|
65 |
|
|
mInterD.add(new Static3D( 0,-r, h ));
|
66 |
|
|
mInterD.add(new Static3D( r, 0, h ));
|
67 |
59759251
|
Leszek Koltunski
|
|
68 |
3f07bedc
|
Leszek Koltunski
|
mInterA = new Dynamic1D(duration,count);
|
69 |
59759251
|
Leszek Koltunski
|
mInterA.add(new Static1D(1));
|
70 |
|
|
mInterA.add(new Static1D(0));
|
71 |
|
|
|
72 |
3f07bedc
|
Leszek Koltunski
|
mInterS = new Dynamic1D(duration,count);
|
73 |
b5cc7760
|
Leszek Koltunski
|
mInterS.add(new Static1D(1.0f));
|
74 |
|
|
mInterS.add(new Static1D(0.3f));
|
75 |
|
|
|
76 |
3f07bedc
|
Leszek Koltunski
|
mInterC = new Dynamic1D(duration,count);
|
77 |
f9afbbf3
|
Leszek Koltunski
|
mInterC.add(new Static1D(1));
|
78 |
|
|
mInterC.add(new Static1D(0));
|
79 |
59759251
|
Leszek Koltunski
|
|
80 |
3f07bedc
|
Leszek Koltunski
|
mInterB = new Dynamic1D(duration,count);
|
81 |
bdfec906
|
Leszek Koltunski
|
mInterB.add(new Static1D(0));
|
82 |
|
|
mInterB.add(new Static1D(1));
|
83 |
427ab7bf
|
Leszek Koltunski
|
|
84 |
bc0a685b
|
Leszek Koltunski
|
if(!isInEditMode())
|
85 |
|
|
{
|
86 |
|
|
setFocusable(true);
|
87 |
|
|
setFocusableInTouchMode(true);
|
88 |
|
|
setEGLContextClientVersion(2);
|
89 |
525699f4
|
Leszek Koltunski
|
|
90 |
758303a3
|
Leszek Koltunski
|
mRenderer = new EffectQueueRenderer(this);
|
91 |
bc0a685b
|
Leszek Koltunski
|
setRenderer(mRenderer);
|
92 |
af225332
|
Leszek Koltunski
|
|
93 |
334c13fa
|
Leszek Koltunski
|
mPoint = new Static3D(0,0,0);
|
94 |
3f07bedc
|
Leszek Koltunski
|
mRegionV= new Static4D(0,0,60,60);
|
95 |
|
|
mRegionF= new Static4D(0,0,60,60);
|
96 |
427ab7bf
|
Leszek Koltunski
|
|
97 |
bc0a685b
|
Leszek Koltunski
|
setEffect(0);
|
98 |
427ab7bf
|
Leszek Koltunski
|
}
|
99 |
bc0a685b
|
Leszek Koltunski
|
}
|
100 |
427ab7bf
|
Leszek Koltunski
|
|
101 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
427ab7bf
|
Leszek Koltunski
|
|
103 |
758303a3
|
Leszek Koltunski
|
EffectQueueRenderer getRenderer()
|
104 |
3f07bedc
|
Leszek Koltunski
|
{
|
105 |
|
|
return mRenderer;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
public void setScreenSize(int width, int height)
|
111 |
bc0a685b
|
Leszek Koltunski
|
{
|
112 |
|
|
mScrW = width;
|
113 |
|
|
mScrH = height;
|
114 |
|
|
}
|
115 |
427ab7bf
|
Leszek Koltunski
|
|
116 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
427ab7bf
|
Leszek Koltunski
|
|
118 |
3f07bedc
|
Leszek Koltunski
|
public void setEffect(int effect)
|
119 |
bc0a685b
|
Leszek Koltunski
|
{
|
120 |
|
|
mCurrentEffect = effect;
|
121 |
|
|
}
|
122 |
427ab7bf
|
Leszek Koltunski
|
|
123 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
427ab7bf
|
Leszek Koltunski
|
|
125 |
bc0a685b
|
Leszek Koltunski
|
@Override public boolean onTouchEvent(MotionEvent event)
|
126 |
|
|
{
|
127 |
|
|
int action = event.getAction();
|
128 |
|
|
int x, y;
|
129 |
84dd0d8f
|
Leszek Koltunski
|
long id;
|
130 |
af225332
|
Leszek Koltunski
|
|
131 |
bc0a685b
|
Leszek Koltunski
|
switch(action)
|
132 |
427ab7bf
|
Leszek Koltunski
|
{
|
133 |
3f07bedc
|
Leszek Koltunski
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* mRenderer.BWID/mScrW;
|
134 |
|
|
y = (int)event.getY()* mRenderer.BHEI/mScrH;
|
135 |
334c13fa
|
Leszek Koltunski
|
mPoint.set(x,y,0);
|
136 |
3f07bedc
|
Leszek Koltunski
|
mRegionF.set(x,y,60,60);
|
137 |
758303a3
|
Leszek Koltunski
|
EffectQueueActivity act = (EffectQueueActivity)getContext();
|
138 |
59759251
|
Leszek Koltunski
|
|
139 |
427ab7bf
|
Leszek Koltunski
|
switch(mCurrentEffect)
|
140 |
|
|
{
|
141 |
d04a4886
|
Leszek Koltunski
|
case 0: id = mRenderer.getEffects().distort(mInterD, mPoint, mRegionV);
|
142 |
e763f1ee
|
Leszek Koltunski
|
act.effectAdded(id, EffectNames.DISTORT, EffectTypes.VERTEX);
|
143 |
|
|
break;
|
144 |
d04a4886
|
Leszek Koltunski
|
case 1: id = mRenderer.getEffects().sink(mInterS, mPoint, mRegionV);
|
145 |
e763f1ee
|
Leszek Koltunski
|
act.effectAdded(id, EffectNames.SINK, EffectTypes.VERTEX);
|
146 |
|
|
break;
|
147 |
d04a4886
|
Leszek Koltunski
|
case 2: id = mRenderer.getEffects().alpha(mInterA, mRegionF, true);
|
148 |
e763f1ee
|
Leszek Koltunski
|
act.effectAdded(id, EffectNames.ALPHA, EffectTypes.FRAGMENT);
|
149 |
|
|
break;
|
150 |
d04a4886
|
Leszek Koltunski
|
case 3: id = mRenderer.getEffects().saturation(mInterB, mRegionF, false);
|
151 |
63fc1eaf
|
Leszek Koltunski
|
act.effectAdded(id, EffectNames.SATURATION, EffectTypes.FRAGMENT);
|
152 |
e763f1ee
|
Leszek Koltunski
|
break;
|
153 |
d04a4886
|
Leszek Koltunski
|
case 4: id = mRenderer.getEffects().chroma(mInterC, mRED, mRegionF, true);
|
154 |
e763f1ee
|
Leszek Koltunski
|
act.effectAdded(id, EffectNames.CHROMA, EffectTypes.FRAGMENT);
|
155 |
|
|
break;
|
156 |
427ab7bf
|
Leszek Koltunski
|
}
|
157 |
af225332
|
Leszek Koltunski
|
|
158 |
427ab7bf
|
Leszek Koltunski
|
break;
|
159 |
|
|
}
|
160 |
af225332
|
Leszek Koltunski
|
|
161 |
bc0a685b
|
Leszek Koltunski
|
return true;
|
162 |
|
|
}
|
163 |
af225332
|
Leszek Koltunski
|
|
164 |
427ab7bf
|
Leszek Koltunski
|
}
|