Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectSwirl.java @ 6bb59aad

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 String NAME = "SWIRL";
37
  private static final float[] UNITIES = new float[] {0.0f};
38
  private static final int DIMENSION = 1;
39
  private static final boolean SUPPORTS_CENTER = true;
40
  private static final boolean SUPPORTS_REGION = true;
41

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

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

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

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

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

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

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

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

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

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

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

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

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

    
152

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

    
155
    return ret;
156
    }
157
  }
158

    
(22-22/23)