Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectPinch.java @ 9d0d8530

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 instanceof Static4D)
68
      {
69
      mStaticRegion = (Static4D)region;
70
      }
71
    else if( region instanceof Dynamic4D)
72
      {
73
      mDynamicRegion = (Dynamic4D)region;
74
      }
75
    }
76

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

    
89
    if( pinch instanceof Dynamic2D)
90
      {
91
      mDynamic0 = (Dynamic2D)pinch;
92
      }
93
    else if ( pinch instanceof Static2D )
94
      {
95
      mStatic0  = (Static2D)pinch;
96
      }
97

    
98
    if( center instanceof Static3D)
99
      {
100
      mStaticCenter = (Static3D)center;
101
      }
102
    else if( center instanceof Dynamic3D )
103
      {
104
      mDynamicCenter = (Dynamic3D)center;
105
      }
106

    
107
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
113
    {
114
    boolean ret= false;
115

    
116
    if( mDynamicCenter!=null )
117
      {
118
      mDynamicCenter.interpolateMain(uniforms,index+5,currentDuration,step);
119
      }
120
    else
121
      {
122
      uniforms[index+5] = mStaticCenter.getX();
123
      uniforms[index+6] = mStaticCenter.getY();
124
      uniforms[index+7] = mStaticCenter.getZ();
125
      }
126

    
127
    if( mDynamicRegion!=null )
128
      {
129
      mDynamicRegion.interpolateMain(uniforms,index+8,currentDuration,step);
130
      }
131
    else
132
      {
133
      uniforms[index+ 8] = mStaticRegion.getX();
134
      uniforms[index+ 9] = mStaticRegion.getY();
135
      uniforms[index+10] = mStaticRegion.getZ();
136
      uniforms[index+11] = mStaticRegion.getW();
137
      }
138

    
139
    if( mDynamic0!=null )
140
      {
141
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
142
      }
143
    else
144
      {
145
      uniforms[index  ] = ((Static2D)mStatic0).getX();
146
      uniforms[index+1] = ((Static2D)mStatic0).getY();
147
      }
148

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

    
151
    return ret;
152
    }
153
  }
(22-22/25)