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 |
|
|
import org.distorted.library.type.Data3D;
|
23 |
|
|
import org.distorted.library.type.Data4D;
|
24 |
|
|
import org.distorted.library.type.Data5D;
|
25 |
15aa7d94
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
26 |
125cee3d
|
Leszek Koltunski
|
|
27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
|
|
|
29 |
|
|
public class VertexEffectWave extends VertexEffect
|
30 |
|
|
{
|
31 |
0dd98279
|
Leszek Koltunski
|
private Data5D mWave;
|
32 |
|
|
private Data3D mCenter;
|
33 |
|
|
private Data4D mRegion;
|
34 |
|
|
|
35 |
125cee3d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
6bb59aad
|
Leszek Koltunski
|
/**
|
37 |
|
|
* Directional, sinusoidal wave effect.
|
38 |
|
|
*
|
39 |
|
|
* @param wave A 5-dimensional data structure describing the wave: first member is the amplitude,
|
40 |
|
|
* second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
|
41 |
|
|
* wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
|
42 |
|
|
* describe the 'direction' of the wave.
|
43 |
|
|
* <p>
|
44 |
|
|
* Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
|
45 |
|
|
* need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
|
46 |
|
|
* forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
|
47 |
|
|
* the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
|
48 |
|
|
* <p>
|
49 |
|
|
* <p>
|
50 |
|
|
* Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
|
51 |
|
|
* in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
|
52 |
|
|
* will be sine shapes.
|
53 |
|
|
* <p>
|
54 |
|
|
* Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
|
55 |
|
|
* but this time it waves in the Y-direction, i.e. cross sections of the surface and the
|
56 |
|
|
* YZ-plane with be sine shapes.
|
57 |
|
|
* <p>
|
58 |
|
|
* Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
|
59 |
|
|
* is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
|
60 |
|
|
* value if sin at this point.
|
61 |
|
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
62 |
0dd98279
|
Leszek Koltunski
|
* @param region Region that masks the Effect.
|
63 |
6bb59aad
|
Leszek Koltunski
|
*/
|
64 |
0dd98279
|
Leszek Koltunski
|
public VertexEffectWave(Data5D wave, Data3D center, Data4D region)
|
65 |
125cee3d
|
Leszek Koltunski
|
{
|
66 |
9d0d8530
|
leszek
|
super(EffectName.WAVE);
|
67 |
0dd98279
|
Leszek Koltunski
|
mWave = wave;
|
68 |
|
|
mCenter = center;
|
69 |
|
|
mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
|
70 |
125cee3d
|
Leszek Koltunski
|
}
|
71 |
|
|
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
6bb59aad
|
Leszek Koltunski
|
/**
|
74 |
|
|
* Directional, sinusoidal wave effect.
|
75 |
|
|
*
|
76 |
|
|
* @param wave see {@link VertexEffectWave(Data5D,Data3D)}
|
77 |
|
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
78 |
|
|
*/
|
79 |
0dd98279
|
Leszek Koltunski
|
public VertexEffectWave(Data5D wave, Data3D center)
|
80 |
125cee3d
|
Leszek Koltunski
|
{
|
81 |
9d0d8530
|
leszek
|
super(EffectName.WAVE);
|
82 |
0dd98279
|
Leszek Koltunski
|
mWave = wave;
|
83 |
|
|
mCenter = center;
|
84 |
|
|
mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
85 |
15aa7d94
|
Leszek Koltunski
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
90 |
|
|
{
|
91 |
0dd98279
|
Leszek Koltunski
|
mCenter.get(uniforms,index+5,currentDuration,step);
|
92 |
|
|
mRegion.get(uniforms,index+8,currentDuration,step);
|
93 |
|
|
boolean ret = mWave.get(uniforms,index,currentDuration,step);
|
94 |
15aa7d94
|
Leszek Koltunski
|
|
95 |
|
|
uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180);
|
96 |
|
|
uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180);
|
97 |
|
|
uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180);
|
98 |
82d6f93a
|
Leszek Koltunski
|
uniforms[index+9] =-uniforms[index+9];
|
99 |
15aa7d94
|
Leszek Koltunski
|
|
100 |
|
|
return ret;
|
101 |
125cee3d
|
Leszek Koltunski
|
}
|
102 |
|
|
}
|