Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectDistort.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.Data3D;
23
import org.distorted.library.type.Data4D;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Dynamic4D;
26
import org.distorted.library.type.Static3D;
27
import org.distorted.library.type.Static4D;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class VertexEffectDistort extends VertexEffect
32
  {
33
  private static final float[] UNITIES = new float[] {0.0f,0.0f,0.0f};
34
  private static final int DIMENSION = 3;
35
  private static final boolean SUPPORTS_CENTER = true;
36
  private static final boolean SUPPORTS_REGION = true;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  public VertexEffectDistort(Data3D vector, Data3D center, Data4D region)
41
    {
42
    super(DISTORT,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
43

    
44
    if( vector instanceof Dynamic3D )
45
      {
46
      mDynamic0 = (Dynamic3D)vector;
47
      }
48
    else if ( vector instanceof Static3D )
49
      {
50
      mStatic0 = (Static3D)vector;
51
      }
52

    
53
    if( center instanceof Static3D)
54
      {
55
      mStaticCenter = (Static3D)center;
56
      }
57
    else if( center instanceof Dynamic3D )
58
      {
59
      mDynamicCenter = (Dynamic3D)center;
60
      }
61

    
62
    if( region instanceof Static4D)
63
      {
64
      mStaticRegion = (Static4D)region;
65
      }
66
    else if( region instanceof Dynamic4D)
67
      {
68
      mDynamicRegion = (Dynamic4D)region;
69
      }
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  public VertexEffectDistort(Data3D vector, Data3D center)
75
    {
76
    super(DISTORT,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
77

    
78
    if( vector instanceof Dynamic3D )
79
      {
80
      mDynamic0 = (Dynamic3D)vector;
81
      }
82
    else if ( vector instanceof Static3D )
83
      {
84
      mStatic0 = (Static3D)vector;
85
      }
86

    
87
    if( center instanceof Static3D)
88
      {
89
      mStaticCenter = (Static3D)center;
90
      }
91
    else if( center instanceof Dynamic3D )
92
      {
93
      mDynamicCenter = (Dynamic3D)center;
94
      }
95

    
96
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
102
    {
103
    boolean ret = false;
104

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

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

    
128
    if( mDynamic0!=null )
129
      {
130
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
131
      }
132
    else
133
      {
134
      uniforms[index  ] = ((Static3D)mStatic0).getX();
135
      uniforms[index+1] = ((Static3D)mStatic0).getY();
136
      uniforms[index+2] = ((Static3D)mStatic0).getZ();
137
      }
138

    
139
    uniforms[index+1] =-uniforms[index+1];
140

    
141
    return ret;
142
    }
143
  }
144

    
145

    
(19-19/23)