1 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2017 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 |
|
|
package org.distorted.library.effect;
|
21 |
|
|
|
22 |
15aa7d94
|
Leszek Koltunski
|
import org.distorted.library.type.Data2D;
|
23 |
125cee3d
|
Leszek Koltunski
|
import org.distorted.library.type.Data3D;
|
24 |
|
|
import org.distorted.library.type.Data4D;
|
25 |
15aa7d94
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
26 |
125cee3d
|
Leszek Koltunski
|
|
27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
faa3ff56
|
Leszek Koltunski
|
/**
|
29 |
|
|
* Pull all points around the center of the Effect towards a line passing through the center
|
30 |
|
|
* (that's if degree>=1) or push them away from the line (degree<=1).
|
31 |
|
|
*/
|
32 |
125cee3d
|
Leszek Koltunski
|
public class VertexEffectPinch extends VertexEffect
|
33 |
|
|
{
|
34 |
0dd98279
|
Leszek Koltunski
|
private Data2D mPinch;
|
35 |
|
|
private Data3D mCenter;
|
36 |
|
|
private Data4D mRegion;
|
37 |
|
|
|
38 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
6bb59aad
|
Leszek Koltunski
|
/**
|
40 |
faa3ff56
|
Leszek Koltunski
|
* Only for use by the library itself.
|
41 |
6bb59aad
|
Leszek Koltunski
|
*
|
42 |
faa3ff56
|
Leszek Koltunski
|
* @y.exclude
|
43 |
6bb59aad
|
Leszek Koltunski
|
*/
|
44 |
15aa7d94
|
Leszek Koltunski
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
45 |
|
|
{
|
46 |
0dd98279
|
Leszek Koltunski
|
mCenter.get(uniforms,index+5,currentDuration,step);
|
47 |
|
|
mRegion.get(uniforms,index+8,currentDuration,step);
|
48 |
|
|
boolean ret = mPinch.get(uniforms,index,currentDuration,step);
|
49 |
15aa7d94
|
Leszek Koltunski
|
|
50 |
|
|
uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180);
|
51 |
82d6f93a
|
Leszek Koltunski
|
uniforms[index+9] =-uniforms[index+9];
|
52 |
15aa7d94
|
Leszek Koltunski
|
|
53 |
|
|
return ret;
|
54 |
125cee3d
|
Leszek Koltunski
|
}
|
55 |
7cd24173
|
leszek
|
|
56 |
faa3ff56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
// PUBLIC API
|
58 |
7cd24173
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
// Pull P=(v.x,v.y) towards the line that
|
60 |
|
|
// a) passes through the center of the effect
|
61 |
|
|
// b) forms angle defined in the 2nd interpolated value with the X-axis
|
62 |
|
|
// with P' = P + (1-h)*dist(line to P)
|
63 |
|
|
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P)
|
64 |
faa3ff56
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
|
|
/**
|
66 |
|
|
* Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work.
|
67 |
|
|
*/
|
68 |
7cd24173
|
leszek
|
public static void enable()
|
69 |
|
|
{
|
70 |
|
|
addEffect(EffectName.PINCH,
|
71 |
|
|
|
72 |
|
|
"vec2 center = vUniforms[effect+1].yz; \n"
|
73 |
|
|
+ "vec2 ps = center-v.xy; \n"
|
74 |
|
|
+ "float h = vUniforms[effect].x; \n"
|
75 |
|
|
+ "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n"
|
76 |
|
|
+ "float angle = vUniforms[effect].y; \n"
|
77 |
|
|
+ "vec2 dir = vec2(sin(angle),-cos(angle)); \n"
|
78 |
|
|
+ "v.xy += t*dot(ps,dir)*dir;"
|
79 |
|
|
);
|
80 |
|
|
}
|
81 |
faa3ff56
|
Leszek Koltunski
|
|
82 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83 |
|
|
/**
|
84 |
|
|
* Pull all points around the center of the Effect towards a line passing through the center
|
85 |
|
|
* (that's if degree>=1) or push them away from the line (degree<=1)
|
86 |
|
|
*
|
87 |
|
|
* @param pinch The current degree of the Effect + angle the line forms with X-axis
|
88 |
|
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
89 |
|
|
* @param region Region that masks the Effect.
|
90 |
|
|
*/
|
91 |
|
|
public VertexEffectPinch(Data2D pinch, Data3D center, Data4D region)
|
92 |
|
|
{
|
93 |
|
|
super(EffectName.PINCH);
|
94 |
|
|
mPinch = pinch;
|
95 |
|
|
mCenter = center;
|
96 |
|
|
mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100 |
|
|
/**
|
101 |
|
|
* Pull all points around the center of the Effect towards a line passing through the center
|
102 |
|
|
* (that's if degree>=1) or push them away from the line (degree<=1)
|
103 |
|
|
*
|
104 |
|
|
* @param pinch The current degree of the Effect + angle the line forms with X-axis
|
105 |
|
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
106 |
|
|
*/
|
107 |
|
|
public VertexEffectPinch(Data2D pinch, Data3D center)
|
108 |
|
|
{
|
109 |
|
|
super(EffectName.PINCH);
|
110 |
|
|
mPinch = pinch;
|
111 |
|
|
mCenter = center;
|
112 |
|
|
mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
113 |
|
|
}
|
114 |
125cee3d
|
Leszek Koltunski
|
}
|