Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectPinch.java @ a1d92a36

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.Data2D;
23
import org.distorted.library.type.Data3D;
24
import org.distorted.library.type.Data4D;
25
import org.distorted.library.type.Dynamic2D;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Dynamic4D;
28
import org.distorted.library.type.Static2D;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public class VertexEffectPinch extends VertexEffect
35
  {
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
/**
38
 * Pull all points around the center of the Effect towards a line passing through the center
39
 * (that's if degree>=1) or push them away from the line (degree<=1)
40
 *
41
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
42
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
43
 * @param region Region that masks the Effect.
44
 */
45
  public VertexEffectPinch(Data2D pinch, Data3D center, Data4D region)
46
    {
47
    super(EffectName.PINCH);
48

    
49
    if( pinch instanceof Dynamic2D)
50
      {
51
      mDynamic0 = (Dynamic2D)pinch;
52
      }
53
    else if ( pinch instanceof Static2D )
54
      {
55
      mStatic0  = (Static2D)pinch;
56
      }
57

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

    
67
    if( region == null )
68
      {
69
      mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
70
      }
71
    else
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
      }
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Pull all points around the center of the Effect towards a line passing through the center
87
 * (that's if degree>=1) or push them away from the line (degree<=1)
88
 *
89
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
90
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
91
 */
92
  public VertexEffectPinch(Data2D pinch, Data3D center)
93
    {
94
    super(EffectName.PINCH);
95

    
96
    if( pinch instanceof Dynamic2D)
97
      {
98
      mDynamic0 = (Dynamic2D)pinch;
99
      }
100
    else if ( pinch instanceof Static2D )
101
      {
102
      mStatic0  = (Static2D)pinch;
103
      }
104

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

    
114
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

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

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

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

    
146
    if( mDynamic0!=null )
147
      {
148
      ret = mDynamic0.get(uniforms,index,currentDuration,step);
149
      }
150
    else
151
      {
152
      uniforms[index  ] = ((Static2D)mStatic0).getX();
153
      uniforms[index+1] = ((Static2D)mStatic0).getY();
154
      }
155

    
156
    uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180);
157
    uniforms[index+9] =-uniforms[index+9];
158

    
159
    return ret;
160
    }
161
  }
(22-22/25)