Revision aee0b581
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/library/effect/VertexEffectPinch.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effect; |
21 | 21 |
|
22 |
import org.distorted.library.type.Data2D; |
|
23 | 22 |
import org.distorted.library.type.Data3D; |
24 | 23 |
import org.distorted.library.type.Data4D; |
25 | 24 |
|
... | ... | |
35 | 34 |
*/ |
36 | 35 |
public class VertexEffectPinch extends VertexEffect |
37 | 36 |
{ |
38 |
private Data2D mPinch;
|
|
37 |
private Data3D mPinch;
|
|
39 | 38 |
private Data3D mCenter; |
40 | 39 |
private Data4D mRegion; |
41 | 40 |
|
... | ... | |
52 | 51 |
boolean ret = mPinch.get(uniforms,index,currentDuration,step); |
53 | 52 |
|
54 | 53 |
uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180); |
54 |
uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180); |
|
55 | 55 |
|
56 | 56 |
return ret; |
57 | 57 |
} |
... | ... | |
59 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | 60 |
// PUBLIC API |
61 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 |
// Pull P=(v.x,v.y) towards the line that |
|
63 |
// a) passes through the center of the effect |
|
64 |
// b) forms angle defined in the 2nd interpolated value with the X-axis |
|
65 |
// with P' = P + (1-h)*dist(line to P) |
|
62 |
// Pull P=(v.x,v.y) along a vector from the center of region sphere to a point on it defined by |
|
63 |
// the (latitude,longitude) pair of angles with P' = P + (1-h)*dist(line to P) |
|
66 | 64 |
// when h>1 we are pushing points away from S: P' = P + (1/h-1)*dist(line to P) |
65 |
// (where 'line' above passes through the center point and goes along the vector) |
|
67 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 67 |
/** |
69 | 68 |
* Have to call this before the shaders get compiled (i.e before Distorted.onCreate()) for the Effect to work. |
... | ... | |
72 | 71 |
{ |
73 | 72 |
addEffect(EffectName.PINCH, |
74 | 73 |
|
75 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
|
76 |
+ "vec3 ps = center-v; \n" |
|
77 |
+ "float h = vUniforms[effect].x; \n" |
|
78 |
+ "float t = degree(vUniforms[effect+2],center,ps) * (1.0-h)/max(1.0,h); \n" |
|
79 |
+ "float angle = vUniforms[effect].y; \n" |
|
80 |
+ "vec2 dir = vec2(sin(angle),-cos(angle)); \n" |
|
81 |
+ "v.xy += t*dot(ps.xy,dir)*dir;" |
|
74 |
"vec3 center = vUniforms[effect+1].yzw; \n" |
|
75 |
+ "vec3 ps = center-v; \n" |
|
76 |
+ "float h = vUniforms[effect].x; \n" |
|
77 |
+ "float deg = degree(vUniforms[effect+2],center,ps); \n" |
|
78 |
+ "float t = deg * (1.0-h)/max(1.0,h); \n" |
|
79 |
+ "float latitude = vUniforms[effect].y; \n" |
|
80 |
+ "float longitude = vUniforms[effect].z; \n" |
|
81 |
+ "float sinLAT = sin(latitude); \n" |
|
82 |
+ "float cosLAT = cos(latitude); \n" |
|
83 |
+ "float sinLON = sin(longitude); \n" |
|
84 |
+ "float cosLON = cos(longitude); \n" |
|
85 |
+ "vec3 dir = vec3(sinLON*cosLAT,sinLAT,cosLON*cosLAT);\n" |
|
86 |
+ "v += t*dot(ps,dir)*dir;" |
|
82 | 87 |
); |
83 | 88 |
} |
84 | 89 |
|
... | ... | |
87 | 92 |
* Pull all points around the center of the Effect towards a line passing through the center |
88 | 93 |
* (that's if degree>=1) or push them away from the line (degree<=1) |
89 | 94 |
* |
90 |
* @param pinch The current degree of the Effect + angle the line forms with X-axis |
|
95 |
* @param pinch The current degree of the Effect + (latitude,longitude) pair of angles defining the |
|
96 |
* * point towards which (and its antipode) the pinching power is strongest. |
|
91 | 97 |
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect. |
92 | 98 |
* @param region Region that masks the Effect. |
93 | 99 |
*/ |
94 |
public VertexEffectPinch(Data2D pinch, Data3D center, Data4D region)
|
|
100 |
public VertexEffectPinch(Data3D pinch, Data3D center, Data4D region)
|
|
95 | 101 |
{ |
96 | 102 |
super(EffectName.PINCH); |
97 | 103 |
mPinch = pinch; |
... | ... | |
104 | 110 |
* Pull all points around the center of the Effect towards a line passing through the center |
105 | 111 |
* (that's if degree>=1) or push them away from the line (degree<=1) |
106 | 112 |
* |
107 |
* @param pinch The current degree of the Effect + angle the line forms with X-axis |
|
113 |
* @param pinch The current degree of the Effect + (latitude,longitude) pair of angles defining the |
|
114 |
* point towards which (and its antipode) the pinching power is strongest. |
|
108 | 115 |
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect. |
109 | 116 |
*/ |
110 |
public VertexEffectPinch(Data2D pinch, Data3D center)
|
|
117 |
public VertexEffectPinch(Data3D pinch, Data3D center)
|
|
111 | 118 |
{ |
112 | 119 |
super(EffectName.PINCH); |
113 | 120 |
mPinch = pinch; |
Also available in: Unified diff
Make the 'PINCH' effect fully 3D (define its acting line in terms of (latitude,longitude) angle pair).
Still, something is not fully working in the Earth app with the effect - investigate.