Project

General

Profile

Download (5.62 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effect / VertexEffectWave.java @ 0dd98279

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.library.type.Dynamic3D;
26
import org.distorted.library.type.Dynamic4D;
27
import org.distorted.library.type.Dynamic5D;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static4D;
30
import org.distorted.library.type.Static5D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public class VertexEffectWave extends VertexEffect
35
  {
36
  private Data5D mWave;
37
  private Data3D mCenter;
38
  private Data4D mRegion;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
/**
42
 * Directional, sinusoidal wave effect.
43
 *
44
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
45
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
46
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
47
 *               describe the 'direction' of the wave.
48
 *               <p>
49
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
50
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
51
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
52
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
53
 *               <p>
54
 *               <p>
55
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
56
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
57
 *               will be sine shapes.
58
 *               <p>
59
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
60
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
61
 *               YZ-plane with be sine shapes.
62
 *               <p>
63
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
64
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
65
 *               value if sin at this point.
66
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
67
 * @param region Region that masks the Effect.
68
 */
69
  public VertexEffectWave(Data5D wave, Data3D center, Data4D region)
70
    {
71
    super(EffectName.WAVE);
72
    mWave   = wave;
73
    mCenter = center;
74
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
/**
79
 * Directional, sinusoidal wave effect.
80
 *
81
 * @param wave   see {@link VertexEffectWave(Data5D,Data3D)}
82
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
83
 */
84
  public VertexEffectWave(Data5D wave, Data3D center)
85
    {
86
    super(EffectName.WAVE);
87
    mWave   = wave;
88
    mCenter = center;
89
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
95
    {
96
    mCenter.get(uniforms,index+5,currentDuration,step);
97
    mRegion.get(uniforms,index+8,currentDuration,step);
98
    boolean ret = mWave.get(uniforms,index,currentDuration,step);
99

    
100
    uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180);
101
    uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180);
102
    uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180);
103
    uniforms[index+9] =-uniforms[index+9];
104

    
105
    return ret;
106
    }
107
  }
(25-25/25)