Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectDeform.java @ 7625e47e

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 VertexEffectDeform extends VertexEffect
32
  {
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
/**
35
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
36
 * a (possibly changing in time) point on the Object.
37
 *
38
 * @param vector Vector of force that deforms the shape of the whole Object.
39
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
40
 * @param region Region that masks the Effect.
41
 */
42
  public VertexEffectDeform(Data3D vector, Data3D center, Data4D region)
43
    {
44
    super(EffectName.DEFORM);
45

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

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

    
64
    if( region == null )
65
      {
66
      mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
67
      }
68
    else
69
      {
70
      if (region instanceof Static4D)
71
        {
72
        mStaticRegion = (Static4D) region;
73
        }
74
      else if (region instanceof Dynamic4D)
75
        {
76
        mDynamicRegion = (Dynamic4D) region;
77
        }
78
      }
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
/**
83
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
84
 * a (possibly changing in time) point on the Object.
85
 *
86
 * @param vector Vector of force that deforms the shape of the whole Object.
87
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
88
 */
89
  public VertexEffectDeform(Data3D vector, Data3D center)
90
    {
91
    super(EffectName.DEFORM);
92

    
93
    if( vector instanceof Dynamic3D )
94
      {
95
      mDynamic0 = (Dynamic3D)vector;
96
      }
97
    else if ( vector instanceof Static3D )
98
      {
99
      mStatic0 = (Static3D)vector;
100
      }
101

    
102
    if( center instanceof Static3D)
103
      {
104
      mStaticCenter = (Static3D)center;
105
      }
106
    else if( center instanceof Dynamic3D )
107
      {
108
      mDynamicCenter = (Dynamic3D)center;
109
      }
110

    
111
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
117
    {
118
    boolean ret = false;
119

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

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

    
143
    if( mDynamic0!=null )
144
      {
145
      ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
146
      }
147
    else
148
      {
149
      uniforms[index  ] = ((Static3D)mStatic0).getX();
150
      uniforms[index+1] = ((Static3D)mStatic0).getY();
151
      uniforms[index+2] = ((Static3D)mStatic0).getZ();
152
      }
153

    
154
    return ret;
155
    }
156
  }
(20-20/25)