Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectSink.java @ 15aa7d94

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
  public VertexEffectSink(Data1D sink, Data3D center, Data4D region)
44
    {
45
    super(SINK,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
46

    
47
    if( sink instanceof Dynamic1D)
48
      {
49
      mDynamic0 = (Dynamic1D)sink;
50
      }
51
    else if ( sink instanceof Static1D )
52
      {
53
      mStatic0  = (Static1D)sink;
54
      }
55

    
56
    if( center instanceof Static3D)
57
      {
58
      mStaticCenter = (Static3D)center;
59
      }
60
    else if( center instanceof Dynamic3D)
61
      {
62
      mDynamicCenter = (Dynamic3D)center;
63
      }
64

    
65
    if( region instanceof Static4D)
66
      {
67
      mStaticRegion = (Static4D)region;
68
      }
69
    else if( region instanceof Dynamic4D)
70
      {
71
      mDynamicRegion = (Dynamic4D)region;
72
      }
73
    }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  public VertexEffectSink(Data1D sink, Data3D center)
78
    {
79
    super(SINK,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
80

    
81
    if( sink instanceof Dynamic1D)
82
      {
83
      mDynamic0 = (Dynamic1D)sink;
84
      }
85
    else if ( sink instanceof Static1D )
86
      {
87
      mStatic0  = (Static1D)sink;
88
      }
89

    
90
    if( center instanceof Static3D)
91
      {
92
      mStaticCenter = (Static3D)center;
93
      }
94
    else if( center instanceof Dynamic3D )
95
      {
96
      mDynamicCenter = (Dynamic3D)center;
97
      }
98

    
99
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
105
    {
106
    boolean ret = false;
107

    
108
    if( mDynamicCenter!=null )
109
      {
110
      mDynamicCenter.interpolateMain(uniforms,index+5,currentDuration,step);
111
      }
112
    else
113
      {
114
      uniforms[index+5] = mStaticCenter.getX();
115
      uniforms[index+6] = mStaticCenter.getY();
116
      uniforms[index+7] = mStaticCenter.getZ();
117
      }
118

    
119
    if( mDynamicRegion!=null )
120
      {
121
      mDynamicRegion.interpolateMain(uniforms,index+8,currentDuration,step);
122
      }
123
    else
124
      {
125
      uniforms[index+ 8] = mStaticRegion.getX();
126
      uniforms[index+ 9] = mStaticRegion.getY();
127
      uniforms[index+10] = mStaticRegion.getZ();
128
      uniforms[index+11] = mStaticRegion.getW();
129
      }
130

    
131
    if( mDynamic0!=null )
132
      {
133
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
134
      }
135
    else
136
      {
137
      uniforms[index  ] = ((Static1D)mStatic0).getX();
138
      }
139

    
140
    return ret;
141
    }
142
  }
(21-21/23)