Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectWave.java @ a1d92a36

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

    
68
    if( wave instanceof Dynamic5D)
69
      {
70
      mDynamic0 = (Dynamic5D)wave;
71
      }
72
    else if ( wave instanceof Static5D)
73
      {
74
      mStatic0  = (Static5D)wave;
75
      }
76

    
77
    if( center instanceof Static3D)
78
      {
79
      mStaticCenter = (Static3D)center;
80
      }
81
    else if( center instanceof Dynamic3D )
82
      {
83
      mDynamicCenter = (Dynamic3D)center;
84
      }
85

    
86
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
/**
91
 * Directional, sinusoidal wave effect.
92
 *
93
 * @param wave   see {@link VertexEffectWave(Data5D,Data3D)}
94
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
95
 * @param region Region that masks the Effect.
96
 */
97
  public VertexEffectWave(Data5D wave, Data3D center, Data4D region)
98
    {
99
    super(EffectName.WAVE);
100

    
101
    if( wave instanceof Dynamic5D)
102
      {
103
      mDynamic0 = (Dynamic5D)wave;
104
      }
105
    else if ( wave instanceof Static5D)
106
      {
107
      mStatic0  = (Static5D)wave;
108
      }
109

    
110
    if( center instanceof Static3D)
111
      {
112
      mStaticCenter = (Static3D)center;
113
      }
114
    else if( center instanceof Dynamic3D)
115
      {
116
      mDynamicCenter = (Dynamic3D)center;
117
      }
118

    
119
    if( region == null )
120
      {
121
      mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
122
      }
123
    else
124
      {
125
      if (region instanceof Static4D)
126
        {
127
        mStaticRegion = (Static4D) region;
128
        }
129
      else if (region instanceof Dynamic4D)
130
        {
131
        mDynamicRegion = (Dynamic4D) region;
132
        }
133
      }
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
139
    {
140
    boolean ret = false;
141

    
142
    if( mDynamicCenter!=null )
143
      {
144
      mDynamicCenter.get(uniforms,index+5,currentDuration,step);
145
      }
146
    else
147
      {
148
      uniforms[index+5] = mStaticCenter.getX();
149
      uniforms[index+6] = mStaticCenter.getY();
150
      uniforms[index+7] = mStaticCenter.getZ();
151
      }
152

    
153
    if( mDynamicRegion!=null )
154
      {
155
      mDynamicRegion.get(uniforms,index+8,currentDuration,step);
156
      }
157
    else
158
      {
159
      uniforms[index+ 8] = mStaticRegion.getX();
160
      uniforms[index+ 9] = mStaticRegion.getY();
161
      uniforms[index+10] = mStaticRegion.getZ();
162
      uniforms[index+11] = mStaticRegion.getW();
163
      }
164

    
165
    if( mDynamic0!=null )
166
      {
167
      ret = mDynamic0.get(uniforms,index,currentDuration,step);
168
      }
169
    else
170
      {
171
      uniforms[index  ] = ((Static5D)mStatic0).getX();
172
      uniforms[index+1] = ((Static5D)mStatic0).getY();
173
      uniforms[index+2] = ((Static5D)mStatic0).getZ();
174
      uniforms[index+3] = ((Static5D)mStatic0).getW();
175
      uniforms[index+4] = ((Static5D)mStatic0).getV();
176
      }
177

    
178
    uniforms[index+2] = (float)(Math.PI*uniforms[index+2]/180);
179
    uniforms[index+3] = (float)(Math.PI*uniforms[index+3]/180);
180
    uniforms[index+4] = (float)(Math.PI*uniforms[index+4]/180);
181
    uniforms[index+9] =-uniforms[index+9];
182

    
183
    return ret;
184
    }
185
  }
(25-25/25)