| 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 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 42 |
427ab7bf
|
Leszek Koltunski
|
|
| 43 |
758303a3
|
Leszek Koltunski
|
public class EffectQueueSurfaceView extends GLSurfaceView
|
| 44 |
bc0a685b
|
Leszek Koltunski
|
{
|
| 45 |
1585ba24
|
Leszek Koltunski
|
private static final int RADIUS = EffectQueueRenderer.BWID/6;
|
| 46 |
30c47368
|
Leszek Koltunski
|
|
| 47 |
758303a3
|
Leszek Koltunski
|
private EffectQueueRenderer mRenderer;
|
| 48 |
3f07bedc
|
Leszek Koltunski
|
private int mCurrentEffect;
|
| 49 |
|
|
private int mScrW, mScrH;
|
| 50 |
427ab7bf
|
Leszek Koltunski
|
|
| 51 |
3f07bedc
|
Leszek Koltunski
|
private Dynamic1D mInterA, mInterB, mInterC, mInterS;
|
| 52 |
|
|
private Dynamic3D mInterD;
|
| 53 |
f9afbbf3
|
Leszek Koltunski
|
|
| 54 |
a4d59c0b
|
Leszek Koltunski
|
private final static Static3D RED = new Static3D(1,0,0);
|
| 55 |
|
|
private final static Static3D REGION_F = new Static3D(RADIUS,RADIUS,RADIUS);
|
| 56 |
|
|
private final static Static4D REGION_V = new Static4D(0,0,0,RADIUS);
|
| 57 |
f9afbbf3
|
Leszek Koltunski
|
|
| 58 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 59 |
427ab7bf
|
Leszek Koltunski
|
|
| 60 |
41a81a14
|
Leszek Koltunski
|
public EffectQueueSurfaceView(Context context, AttributeSet attrs)
|
| 61 |
bc0a685b
|
Leszek Koltunski
|
{
|
| 62 |
41a81a14
|
Leszek Koltunski
|
super(context, attrs);
|
| 63 |
427ab7bf
|
Leszek Koltunski
|
|
| 64 |
3f07bedc
|
Leszek Koltunski
|
int duration = 10000;
|
| 65 |
|
|
float count = 1.0f;
|
| 66 |
59759251
|
Leszek Koltunski
|
int h = 30;
|
| 67 |
|
|
int r = 20;
|
| 68 |
|
|
|
| 69 |
3f07bedc
|
Leszek Koltunski
|
mInterD = new Dynamic3D(duration,count);
|
| 70 |
59759251
|
Leszek Koltunski
|
|
| 71 |
3f07bedc
|
Leszek Koltunski
|
mInterD.add(new Static3D( 0, r, h ));
|
| 72 |
|
|
mInterD.add(new Static3D(-r, 0, h ));
|
| 73 |
|
|
mInterD.add(new Static3D( 0,-r, h ));
|
| 74 |
|
|
mInterD.add(new Static3D( r, 0, h ));
|
| 75 |
59759251
|
Leszek Koltunski
|
|
| 76 |
3f07bedc
|
Leszek Koltunski
|
mInterA = new Dynamic1D(duration,count);
|
| 77 |
59759251
|
Leszek Koltunski
|
mInterA.add(new Static1D(1));
|
| 78 |
|
|
mInterA.add(new Static1D(0));
|
| 79 |
|
|
|
| 80 |
3f07bedc
|
Leszek Koltunski
|
mInterS = new Dynamic1D(duration,count);
|
| 81 |
b5cc7760
|
Leszek Koltunski
|
mInterS.add(new Static1D(1.0f));
|
| 82 |
|
|
mInterS.add(new Static1D(0.3f));
|
| 83 |
|
|
|
| 84 |
3f07bedc
|
Leszek Koltunski
|
mInterC = new Dynamic1D(duration,count);
|
| 85 |
f9afbbf3
|
Leszek Koltunski
|
mInterC.add(new Static1D(1));
|
| 86 |
|
|
mInterC.add(new Static1D(0));
|
| 87 |
59759251
|
Leszek Koltunski
|
|
| 88 |
3f07bedc
|
Leszek Koltunski
|
mInterB = new Dynamic1D(duration,count);
|
| 89 |
bdfec906
|
Leszek Koltunski
|
mInterB.add(new Static1D(0));
|
| 90 |
|
|
mInterB.add(new Static1D(1));
|
| 91 |
427ab7bf
|
Leszek Koltunski
|
|
| 92 |
bc0a685b
|
Leszek Koltunski
|
if(!isInEditMode())
|
| 93 |
|
|
{
|
| 94 |
|
|
setFocusable(true);
|
| 95 |
|
|
setFocusableInTouchMode(true);
|
| 96 |
758303a3
|
Leszek Koltunski
|
mRenderer = new EffectQueueRenderer(this);
|
| 97 |
e4330c89
|
Leszek Koltunski
|
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| 98 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
| 99 |
|
|
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
|
| 100 |
bc0a685b
|
Leszek Koltunski
|
setRenderer(mRenderer);
|
| 101 |
a4d59c0b
|
Leszek Koltunski
|
setEffect(0);
|
| 102 |
427ab7bf
|
Leszek Koltunski
|
}
|
| 103 |
bc0a685b
|
Leszek Koltunski
|
}
|
| 104 |
427ab7bf
|
Leszek Koltunski
|
|
| 105 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 106 |
427ab7bf
|
Leszek Koltunski
|
|
| 107 |
758303a3
|
Leszek Koltunski
|
EffectQueueRenderer getRenderer()
|
| 108 |
3f07bedc
|
Leszek Koltunski
|
{
|
| 109 |
|
|
return mRenderer;
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 113 |
|
|
|
| 114 |
|
|
public void setScreenSize(int width, int height)
|
| 115 |
bc0a685b
|
Leszek Koltunski
|
{
|
| 116 |
|
|
mScrW = width;
|
| 117 |
|
|
mScrH = height;
|
| 118 |
|
|
}
|
| 119 |
427ab7bf
|
Leszek Koltunski
|
|
| 120 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 121 |
427ab7bf
|
Leszek Koltunski
|
|
| 122 |
3f07bedc
|
Leszek Koltunski
|
public void setEffect(int effect)
|
| 123 |
bc0a685b
|
Leszek Koltunski
|
{
|
| 124 |
|
|
mCurrentEffect = effect;
|
| 125 |
|
|
}
|
| 126 |
427ab7bf
|
Leszek Koltunski
|
|
| 127 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 128 |
427ab7bf
|
Leszek Koltunski
|
|
| 129 |
a4d59c0b
|
Leszek Koltunski
|
@Override
|
| 130 |
|
|
public boolean onTouchEvent(MotionEvent event)
|
| 131 |
bc0a685b
|
Leszek Koltunski
|
{
|
| 132 |
8dfa45c4
|
leszek
|
int x,y,action = event.getAction();
|
| 133 |
a4d59c0b
|
Leszek Koltunski
|
Effect effect;
|
| 134 |
8dfa45c4
|
leszek
|
boolean success;
|
| 135 |
af225332
|
Leszek Koltunski
|
|
| 136 |
bc0a685b
|
Leszek Koltunski
|
switch(action)
|
| 137 |
427ab7bf
|
Leszek Koltunski
|
{
|
| 138 |
a4d59c0b
|
Leszek Koltunski
|
case MotionEvent.ACTION_DOWN: x = (int)event.getX()* EffectQueueRenderer.BWID/mScrW;
|
| 139 |
|
|
y = EffectQueueRenderer.BHEI-(int)event.getY()* EffectQueueRenderer.BHEI/mScrH;
|
| 140 |
758303a3
|
Leszek Koltunski
|
EffectQueueActivity act = (EffectQueueActivity)getContext();
|
| 141 |
a4d59c0b
|
Leszek Koltunski
|
Static3D center = new Static3D(x,y,0);
|
| 142 |
59759251
|
Leszek Koltunski
|
|
| 143 |
427ab7bf
|
Leszek Koltunski
|
switch(mCurrentEffect)
|
| 144 |
|
|
{
|
| 145 |
a4d59c0b
|
Leszek Koltunski
|
case 0: effect = new VertexEffectDistort (mInterD, center, REGION_V);
|
| 146 |
|
|
success= mRenderer.getEffects().apply(effect);
|
| 147 |
|
|
act.effectAdded(success,effect);
|
| 148 |
e763f1ee
|
Leszek Koltunski
|
break;
|
| 149 |
a4d59c0b
|
Leszek Koltunski
|
case 1: effect = new VertexEffectSink (mInterS, center, REGION_V);
|
| 150 |
|
|
success= mRenderer.getEffects().apply(effect);
|
| 151 |
|
|
act.effectAdded(success,effect);
|
| 152 |
e763f1ee
|
Leszek Koltunski
|
break;
|
| 153 |
a4d59c0b
|
Leszek Koltunski
|
case 2: effect = new FragmentEffectAlpha (mInterA, center, REGION_F, true);
|
| 154 |
|
|
success= mRenderer.getEffects().apply(effect);
|
| 155 |
|
|
act.effectAdded(success,effect);
|
| 156 |
e763f1ee
|
Leszek Koltunski
|
break;
|
| 157 |
a4d59c0b
|
Leszek Koltunski
|
case 3: effect = new FragmentEffectSaturation(mInterB, center, REGION_F, false);
|
| 158 |
|
|
success= mRenderer.getEffects().apply(effect);
|
| 159 |
|
|
act.effectAdded(success,effect);
|
| 160 |
e763f1ee
|
Leszek Koltunski
|
break;
|
| 161 |
a4d59c0b
|
Leszek Koltunski
|
case 4: effect = new FragmentEffectChroma (mInterC, RED, center, REGION_F, true);
|
| 162 |
|
|
success= mRenderer.getEffects().apply(effect);
|
| 163 |
|
|
act.effectAdded(success,effect);
|
| 164 |
e763f1ee
|
Leszek Koltunski
|
break;
|
| 165 |
427ab7bf
|
Leszek Koltunski
|
}
|
| 166 |
af225332
|
Leszek Koltunski
|
|
| 167 |
427ab7bf
|
Leszek Koltunski
|
break;
|
| 168 |
|
|
}
|
| 169 |
af225332
|
Leszek Koltunski
|
|
| 170 |
bc0a685b
|
Leszek Koltunski
|
return true;
|
| 171 |
|
|
}
|
| 172 |
af225332
|
Leszek Koltunski
|
|
| 173 |
427ab7bf
|
Leszek Koltunski
|
}
|