Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectSink.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 VertexEffectSink extends VertexEffect
35
  {
36
  private static final float[] UNITIES         = new float[] {1.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
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
44
 * away from the center (degree<=1)
45
 *
46
 * @param sink   The current degree of the Effect.
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 VertexEffectSink(Data1D sink, Data3D center, Data4D region)
51
    {
52
    super(EffectName.SINK,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
53

    
54
    if( sink instanceof Dynamic1D)
55
      {
56
      mDynamic0 = (Dynamic1D)sink;
57
      }
58
    else if ( sink instanceof Static1D )
59
      {
60
      mStatic0  = (Static1D)sink;
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
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
85
 * away from the center (degree<=1)
86
 *
87
 * @param sink   The current degree of the Effect.
88
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
89
 */
90
  public VertexEffectSink(Data1D sink, Data3D center)
91
    {
92
    super(EffectName.SINK,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
93

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

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

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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

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

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

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

    
153
    return ret;
154
    }
155
  }
(23-23/25)