Project

General

Profile

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

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

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
  private static final String NAME = "PINCH";
37
  private static final float[] UNITIES = new float[] {1.0f};
38
  private static final int DIMENSION = 2;
39
  private static final boolean SUPPORTS_CENTER = true;
40
  private static final boolean SUPPORTS_REGION = true;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
/**
44
 * Pull all points around the center of the Effect towards a line passing through the center
45
 * (that's if degree>=1) or push them away from the line (degree<=1)
46
 *
47
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
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
  public VertexEffectPinch(Data2D pinch, Data3D center, Data4D region)
52
    {
53
    super(PINCH,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
54

    
55
    if( pinch instanceof Dynamic2D)
56
      {
57
      mDynamic0 = (Dynamic2D)pinch;
58
      }
59
    else if ( pinch instanceof Static2D )
60
      {
61
      mStatic0  = (Static2D)pinch;
62
      }
63

    
64
    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
    }
82

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

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

    
104
    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  ] = ((Static2D)mStatic0).getX();
152
      uniforms[index+1] = ((Static2D)mStatic0).getY();
153
      }
154

    
155
    uniforms[index+1] = (float)(Math.PI*uniforms[index+1]/180);
156

    
157
    return ret;
158
    }
159
  }
(20-20/23)