Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / VertexEffectDeform.java @ 227b03bd

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.Static4D;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

    
28
public class VertexEffectDeform extends VertexEffect
29
  {
30
  private Data3D mVector, mCenter;
31
  private Data4D mRegion;
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
    mVector = vector;
46
    mCenter = center;
47
    mRegion = (region==null ? new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE) : region);
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
/**
52
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
53
 * a (possibly changing in time) point on the Object.
54
 *
55
 * @param vector Vector of force that deforms the shape of the whole Object.
56
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
57
 */
58
  public VertexEffectDeform(Data3D vector, Data3D center)
59
    {
60
    super(EffectName.DEFORM);
61
    mVector = vector;
62
    mCenter = center;
63
    mRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
69
    {
70
    mCenter.get(uniforms,index+5,currentDuration,step);
71
    mRegion.get(uniforms,index+8,currentDuration,step);
72
    boolean ret = mVector.get(uniforms,index,currentDuration,step);
73

    
74
    uniforms[index+9] =-uniforms[index+9];
75

    
76
    return ret;
77
    }
78
  }
(20-20/25)