Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectSwirl.java @ da9b3f07

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.Data1D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Data4D;
25
import org.distorted.library.type.Dynamic1D;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Dynamic4D;
28
import org.distorted.library.type.Static1D;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

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

    
34
public class VertexEffectSwirl extends VertexEffect
35
  {
36
  private static final float[] UNITIES         = new float[] {0.0f};
37
  private static final int     DIMENSION       = 1;
38
  private static final boolean SUPPORTS_CENTER = true;
39
  private static final boolean SUPPORTS_REGION = true;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
/**
43
 * Rotate part of the Object around the Center of the Effect by a certain angle.
44
 *
45
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
46
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
47
 * @param region Region that masks the Effect.
48
 */
49
  public VertexEffectSwirl(Data1D swirl, Data3D center, Data4D region)
50
    {
51
    super(EffectName.SWIRL,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
52

    
53
    if( swirl instanceof Dynamic1D)
54
      {
55
      mDynamic0 = (Dynamic1D)swirl;
56
      }
57
    else if ( swirl instanceof Static1D )
58
      {
59
      mStatic0  = (Static1D)swirl;
60
      }
61

    
62
    if( center instanceof Static3D)
63
      {
64
      mStaticCenter = (Static3D)center;
65
      }
66
    else if( center instanceof Dynamic3D)
67
      {
68
      mDynamicCenter = (Dynamic3D)center;
69
      }
70

    
71
    if( region instanceof Static4D)
72
      {
73
      mStaticRegion = (Static4D)region;
74
      }
75
    else if( region instanceof Dynamic4D)
76
      {
77
      mDynamicRegion = (Dynamic4D)region;
78
      }
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
/**
83
 * Rotate the whole Object around the Center of the Effect by a certain angle.
84
 *
85
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
86
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
87
 */
88
  public VertexEffectSwirl(Data1D swirl, Data3D center)
89
    {
90
    super(EffectName.SWIRL,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
91

    
92
    if( swirl instanceof Dynamic1D)
93
      {
94
      mDynamic0 = (Dynamic1D)swirl;
95
      }
96
    else if ( swirl instanceof Static1D )
97
      {
98
      mStatic0  = (Static1D)swirl;
99
      }
100

    
101
    if( center instanceof Static3D)
102
      {
103
      mStaticCenter = (Static3D)center;
104
      }
105
    else if( center instanceof Dynamic3D )
106
      {
107
      mDynamicCenter = (Dynamic3D)center;
108
      }
109

    
110
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
116
    {
117
    boolean ret = false;
118

    
119
    if( mDynamicCenter!=null )
120
      {
121
      mDynamicCenter.interpolateMain(uniforms,index+5,currentDuration,step);
122
      }
123
    else
124
      {
125
      uniforms[index+5] = mStaticCenter.getX();
126
      uniforms[index+6] = mStaticCenter.getY();
127
      uniforms[index+7] = mStaticCenter.getZ();
128
      }
129

    
130
    if( mDynamicRegion!=null )
131
      {
132
      mDynamicRegion.interpolateMain(uniforms,index+8,currentDuration,step);
133
      }
134
    else
135
      {
136
      uniforms[index+ 8] = mStaticRegion.getX();
137
      uniforms[index+ 9] = mStaticRegion.getY();
138
      uniforms[index+10] = mStaticRegion.getZ();
139
      uniforms[index+11] = mStaticRegion.getW();
140
      }
141

    
142
    if( mDynamic0!=null )
143
      {
144
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
145
      }
146
    else
147
      {
148
      uniforms[index  ] = ((Static1D)mStatic0).getX();
149
      }
150

    
151

    
152
    uniforms[index] = (float)(Math.PI*uniforms[index]/180);
153

    
154
    return ret;
155
    }
156
  }
157

    
(24-24/25)