Project

General

Profile

« Previous | Next » 

Revision 350cc2f5

Added by Leszek Koltunski over 7 years ago

Make the WAVE effect 5D (extra parameter 'offset')

View differences:

src/main/java/org/distorted/library/Distorted.java
85 85
  private static final String TAG = Distorted.class.getSimpleName();
86 86
  private static boolean mInitialized = false;
87 87
  
88
  static int mPositionH;      // pass in model position information
89
  static int mTextureUniformH;// pass in the texture.
90
  static int mNormalH;        // pass in model normal information.
91
  static int mTextureCoordH;  // pass in model texture coordinate information.
92
  static int mProgramH;       // This is a handle to our shading program.  
88
  static int mPositionH;        // pass in model position information
89
  static int mTextureUniformH;  // pass in the texture.
90
  static int mNormalH;          // pass in model normal information.
91
  static int mTextureCoordH;    // pass in model texture coordinate information.
92
  static int mProgramH;         // This is a handle to our shading program.
93 93

  
94 94
  static DistortedProjection mProjection = new DistortedProjection();
95 95
  static float mFOV = 60.0f;
src/main/java/org/distorted/library/DistortedBitmap.java
104 104
 * Copy constructor.
105 105
 *
106 106
 * @param db Object to copy
107
 * @param flags {@see DistortedObject#DistortedObject(DistortedObject,int)}
107
 * @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
108 108
 */
109 109
   public DistortedBitmap(DistortedBitmap db, int flags)
110 110
     {
src/main/java/org/distorted/library/DistortedCubes.java
102 102

  
103 103
///////////////////////////////////////////////////////////////////////////////////////////////////
104 104
/**
105
 * Convenience constructor
105
 * Convenience constructor.
106 106
 */
107 107
 public DistortedCubes(int cols, String desc, int gridSize)
108 108
   {
......
114 114
 * Copy constructor.
115 115
 *
116 116
 * @param dc Object to copy
117
 * @param flags {@see DistortedObject#DistortedObject(DistortedObject,int)}
117
 * @param flags see {@see DistortedObject#DistortedObject(DistortedObject,int)}
118 118
 */
119 119
 public DistortedCubes(DistortedCubes dc, int flags)
120 120
   {
src/main/java/org/distorted/library/DistortedObject.java
29 29
import org.distorted.library.type.Data2D;
30 30
import org.distorted.library.type.Data3D;
31 31
import org.distorted.library.type.Data4D;
32
import org.distorted.library.type.Data5D;
32 33
import org.distorted.library.type.Static3D;
33 34

  
34 35
///////////////////////////////////////////////////////////////////////////////////////////////////
......
816 817
/**
817 818
 * Directional, sinusoidal wave effect.
818 819
 *
819
 * @param wave   A 4-dimensional data structure describing the wave: first member is the amplitude,
820
 *               second is the wave length, and the next two describe the 'direction' of the wave.
820
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
821
 *               second is the wave length, third is the offset (i.e. when offset = PI/2, the sine
822
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
823
 *               describe the 'direction' of the wave.
821 824
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
822 825
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
823 826
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
......
830 833
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
831 834
 *               YZ-plane with be sine shapes.
832 835
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
833
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V.
836
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
837
 *               value if sin at this point.
834 838
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
835 839
 * @return       ID of the effect added, or -1 if we failed to add one.
836 840
 */
837
  public long wave(Data4D wave, Data2D center)
841
  public long wave(Data5D wave, Data2D center)
838 842
    {
839 843
    return mV.add(EffectNames.WAVE, wave, center, null);
840 844
    }
......
843 847
/**
844 848
 * Directional, sinusoidal wave effect.
845 849
 *
846
 * @param wave   A 4-dimensional data structure describing the wave: first member is the amplitude,
847
 *               second is the wave length, and the next two describe the 'direction' of the wave.
848
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
849
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
850
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
851
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
852
 *
853
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
854
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
855
 *               will be sine shapes.
856
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
857
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
858
 *               YZ-plane with be sine shapes.
859
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
860
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V.
861
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
850
 * @param wave   see {@see wave(Data5D,Data2D)}
851
 * @param center see {@see wave(Data5D,Data2D)}
862 852
 * @param region Region that masks the Effect.
863 853
 * @return       ID of the effect added, or -1 if we failed to add one.
864 854
 */
865
  public long wave(Data4D wave, Data2D center, Data4D region)
855
  public long wave(Data5D wave, Data2D center, Data4D region)
866 856
    {
867 857
    return mV.add(EffectNames.WAVE, wave, center, region);
868 858
    }
src/main/java/org/distorted/library/EffectQueueFragment.java
44 44
  
45 45
///////////////////////////////////////////////////////////////////////////////////////////////////
46 46
   
47
  public EffectQueueFragment(DistortedObject obj)
47
  EffectQueueFragment(DistortedObject obj)
48 48
    { 
49 49
    super(obj,NUM_UNIFORMS,INDEX);
50 50
    }
src/main/java/org/distorted/library/EffectQueueMatrix.java
50 50
  
51 51
///////////////////////////////////////////////////////////////////////////////////////////////////
52 52
   
53
  public EffectQueueMatrix(DistortedObject obj)
53
  EffectQueueMatrix(DistortedObject obj)
54 54
    { 
55 55
    super(obj,NUM_UNIFORMS, INDEX );
56 56
    }
src/main/java/org/distorted/library/EffectQueueVertex.java
26 26
import org.distorted.library.type.Data2D;
27 27
import org.distorted.library.type.Data3D;
28 28
import org.distorted.library.type.Data4D;
29
import org.distorted.library.type.Data5D;
29 30
import org.distorted.library.type.Dynamic1D;
30 31
import org.distorted.library.type.Dynamic2D;
31 32
import org.distorted.library.type.Dynamic3D;
32 33
import org.distorted.library.type.Dynamic4D;
34
import org.distorted.library.type.Dynamic5D;
33 35
import org.distorted.library.type.Static1D;
34 36
import org.distorted.library.type.Static2D;
35 37
import org.distorted.library.type.Static3D;
36 38
import org.distorted.library.type.Static4D;
39
import org.distorted.library.type.Static5D;
37 40

  
38 41
///////////////////////////////////////////////////////////////////////////////////////////////////
39 42

  
......
47 50
  
48 51
///////////////////////////////////////////////////////////////////////////////////////////////////
49 52
   
50
  public EffectQueueVertex(DistortedObject obj)
53
  EffectQueueVertex(DistortedObject obj)
51 54
    { 
52 55
    super(obj,NUM_UNIFORMS,INDEX);
53 56
    }
......
157 160
///////////////////////////////////////////////////////////////////////////////////////////////////
158 161
// Do various post-processing on already computed effects.
159 162
// 1) here unlike in the fragment queue, we don't have to multiply the points by ModelView matrix because that gets done in the shader.
160
// 2) in case of SWIRL, switch the angle from degrees to radians
163
// 2) in case of SWIRL, switch the angles from degrees to radians
161 164
// 3) likewise in case of WAVE
162 165
// 4) In case of DISTORT, invert the Y-axis
163 166
  
164
  void postprocess(int effect)
167
  private void postprocess(int effect)
165 168
    {
166 169
    if( mName[effect]==EffectNames.SWIRL.ordinal() )
167 170
      {
......
171 174
      {
172 175
      mUniforms[NUM_UNIFORMS*effect+2] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+2]/180);
173 176
      mUniforms[NUM_UNIFORMS*effect+3] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+3]/180);
177
      mUniforms[NUM_UNIFORMS*effect+4] = (float)(Math.PI*mUniforms[NUM_UNIFORMS*effect+4]/180);
174 178
      }
175 179
    if( mName[effect]==EffectNames.DISTORT.ordinal() )
176 180
      {
......
181 185
///////////////////////////////////////////////////////////////////////////////////////////////////
182 186
// wave
183 187

  
184
  synchronized long add(EffectNames eln, Data4D data, Data2D center, Data4D region)
188
  synchronized long add(EffectNames eln, Data5D data, Data2D center, Data4D region)
185 189
    {
186 190
    if( mMax[INDEX]>mNumEffects )
187 191
      {
188 192
      EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects);
189 193

  
190
      if( data instanceof Dynamic4D)
191
        mInter[0][mNumEffects] = (Dynamic4D)data;
192
      else if( data instanceof Static4D)
194
      if( data instanceof Dynamic5D)
195
        mInter[0][mNumEffects] = (Dynamic5D)data;
196
      else if( data instanceof Static5D)
193 197
        {
198
        Static5D tmp = (Static5D)data;
199

  
194 200
        mInter[0][mNumEffects] = null;
195
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static4D)data).getX();
196
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static4D)data).getY();
197
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static4D)data).getZ();
198
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = ((Static4D)data).getW();
201
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = tmp.getX();
202
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = tmp.getY();
203
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = tmp.getZ();
204
        mUniforms[NUM_UNIFORMS*mNumEffects+3] = tmp.getW();
205
        mUniforms[NUM_UNIFORMS*mNumEffects+4] = tmp.getV();
199 206
        }
200 207

  
201 208
      return addPriv(eln,center,region);
......
217 224
        mInter[0][mNumEffects] = (Dynamic3D)data;
218 225
      else if( data instanceof Static3D)
219 226
        {
227
        Static3D tmp = (Static3D)data;
228

  
220 229
        mInter[0][mNumEffects] = null;
221
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = ((Static3D)data).getX();
222
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static3D)data).getY();
223
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static3D)data).getZ();
230
        mUniforms[NUM_UNIFORMS*mNumEffects  ] = tmp.getX();
231
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = tmp.getY();
232
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = tmp.getZ();
224 233
        }
225 234

  
226 235
      return addPriv(eln,center,region);
src/main/java/org/distorted/library/type/Dynamic1D.java
24 24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 25
/** 
26 26
* A 1-dimensional implementation of the Dynamic class to interpolate between a list
27
* of Float1Ds.
27
* of Static1Ds.
28 28
*/
29 29

  
30 30
public class Dynamic1D extends Dynamic implements Data1D
src/main/java/org/distorted/library/type/Dynamic2D.java
24 24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 25
/** 
26 26
* A 2-dimensional implementation of the Dynamic class to interpolate between a list
27
* of Float2Ds.
27
* of Static2Ds.
28 28
*/
29 29

  
30 30
public class Dynamic2D extends Dynamic implements Data2D
src/main/java/org/distorted/library/type/Dynamic3D.java
24 24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 25
/** 
26 26
* A 3-dimensional implementation of the Dynamic class to interpolate between a list
27
* of Float3Ds.
27
* of Static3Ds.
28 28
*/
29 29

  
30 30
public class Dynamic3D extends Dynamic implements Data3D
src/main/res/raw/main_vertex_shader.glsl
425 425

  
426 426
  if( deg != 0.0 && length != 0.0 )
427 427
    {
428
    float alpha = vUniforms[effect].z;
429
    float beta  = vUniforms[effect].w;
428
    float offset= vUniforms[effect  ].z;
429
    float alpha = vUniforms[effect  ].w;
430
    float beta  = vUniforms[effect+1].x;
430 431

  
431 432
    float sinA = sin(alpha);
432 433
    float cosA = cos(alpha);
433 434
    float sinB = sin(beta);
434 435
    float cosB = cos(beta);
435 436

  
436
    float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length;
437
    float angle= 1.578*(ps.x*cosB-ps.y*sinB) / length + offset;
437 438

  
438
    vec3 dir   = vec3(sinB*cosA,cosB*cosA,sinA);
439
    vec3 dir= vec3(sinB*cosA,cosB*cosA,sinA);
439 440

  
440 441
    v.xyz += sin(angle)*deg*dir;
441 442

  

Also available in: Unified diff