Project

General

Profile

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

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

1 125cee3d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 15aa7d94 Leszek Koltunski
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Dynamic4D;
28 125cee3d Leszek Koltunski
import org.distorted.library.type.Static1D;
29 15aa7d94 Leszek Koltunski
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31 125cee3d Leszek Koltunski
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34
public class VertexEffectSink extends VertexEffect
35
  {
36 6bb59aad Leszek Koltunski
  private static final String NAME = "SINK";
37 125cee3d Leszek Koltunski
  private static final float[] UNITIES = new float[] {1.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 6bb59aad Leszek Koltunski
/**
44
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
45
 * away from the center (degree<=1)
46
 *
47
 * @param sink   The current degree of the Effect.
48
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
49
 * @param region Region that masks the Effect.
50
 */
51 125cee3d Leszek Koltunski
  public VertexEffectSink(Data1D sink, Data3D center, Data4D region)
52
    {
53 6bb59aad Leszek Koltunski
    super(SINK,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
54 125cee3d Leszek Koltunski
55
    if( sink instanceof Dynamic1D)
56
      {
57
      mDynamic0 = (Dynamic1D)sink;
58
      }
59
    else if ( sink instanceof Static1D )
60
      {
61
      mStatic0  = (Static1D)sink;
62
      }
63
64 15aa7d94 Leszek Koltunski
    if( center instanceof Static3D)
65
      {
66
      mStaticCenter = (Static3D)center;
67
      }
68
    else if( center instanceof Dynamic3D)
69
      {
70
      mDynamicCenter = (Dynamic3D)center;
71
      }
72
73
    if( region instanceof Static4D)
74
      {
75
      mStaticRegion = (Static4D)region;
76
      }
77
    else if( region instanceof Dynamic4D)
78
      {
79
      mDynamicRegion = (Dynamic4D)region;
80
      }
81 125cee3d Leszek Koltunski
    }
82
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84 6bb59aad Leszek Koltunski
/**
85
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
86
 * away from the center (degree<=1)
87
 *
88
 * @param sink   The current degree of the Effect.
89
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
90
 */
91 125cee3d Leszek Koltunski
  public VertexEffectSink(Data1D sink, Data3D center)
92
    {
93 6bb59aad Leszek Koltunski
    super(SINK,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
94 125cee3d Leszek Koltunski
95
    if( sink instanceof Dynamic1D)
96
      {
97
      mDynamic0 = (Dynamic1D)sink;
98
      }
99
    else if ( sink instanceof Static1D )
100
      {
101
      mStatic0  = (Static1D)sink;
102
      }
103
104 15aa7d94 Leszek Koltunski
    if( center instanceof Static3D)
105
      {
106
      mStaticCenter = (Static3D)center;
107
      }
108
    else if( center instanceof Dynamic3D )
109
      {
110
      mDynamicCenter = (Dynamic3D)center;
111
      }
112
113
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
114
    }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
119
    {
120
    boolean ret = false;
121
122
    if( mDynamicCenter!=null )
123
      {
124
      mDynamicCenter.interpolateMain(uniforms,index+5,currentDuration,step);
125
      }
126
    else
127
      {
128
      uniforms[index+5] = mStaticCenter.getX();
129
      uniforms[index+6] = mStaticCenter.getY();
130
      uniforms[index+7] = mStaticCenter.getZ();
131
      }
132
133
    if( mDynamicRegion!=null )
134
      {
135
      mDynamicRegion.interpolateMain(uniforms,index+8,currentDuration,step);
136
      }
137
    else
138
      {
139
      uniforms[index+ 8] = mStaticRegion.getX();
140
      uniforms[index+ 9] = mStaticRegion.getY();
141
      uniforms[index+10] = mStaticRegion.getZ();
142
      uniforms[index+11] = mStaticRegion.getW();
143
      }
144
145
    if( mDynamic0!=null )
146
      {
147
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
148
      }
149
    else
150
      {
151
      uniforms[index  ] = ((Static1D)mStatic0).getX();
152
      }
153
154
    return ret;
155 125cee3d Leszek Koltunski
    }
156
  }