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
|
private static final String NAME = "DEFORM";
|
34
|
private static final float[] UNITIES = new float[] {0.0f,0.0f,0.0f};
|
35
|
private static final int DIMENSION = 3;
|
36
|
private static final boolean SUPPORTS_CENTER = true;
|
37
|
private static final boolean SUPPORTS_REGION = true;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
/**
|
41
|
* Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
|
42
|
* a (possibly changing in time) point on the Object.
|
43
|
*
|
44
|
* @param vector Vector of force that deforms the shape of the whole Object.
|
45
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
46
|
* @param region Region that masks the Effect.
|
47
|
*/
|
48
|
public VertexEffectDeform(Data3D vector, Data3D center, Data4D region)
|
49
|
{
|
50
|
super(DEFORM,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
51
|
|
52
|
if( vector instanceof Dynamic3D )
|
53
|
{
|
54
|
mDynamic0 = (Dynamic3D)vector;
|
55
|
}
|
56
|
else if ( vector instanceof Static3D )
|
57
|
{
|
58
|
mStatic0 = (Static3D)vector;
|
59
|
}
|
60
|
|
61
|
if( center instanceof Static3D)
|
62
|
{
|
63
|
mStaticCenter = (Static3D)center;
|
64
|
}
|
65
|
else if( center instanceof Dynamic3D )
|
66
|
{
|
67
|
mDynamicCenter = (Dynamic3D)center;
|
68
|
}
|
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
|
* Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
|
83
|
* a (possibly changing in time) point on the Object.
|
84
|
*
|
85
|
* @param vector Vector of force that deforms the shape of the whole Object.
|
86
|
* @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
|
87
|
*/
|
88
|
public VertexEffectDeform(Data3D vector, Data3D center)
|
89
|
{
|
90
|
super(DEFORM,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,NAME);
|
91
|
|
92
|
if( vector instanceof Dynamic3D )
|
93
|
{
|
94
|
mDynamic0 = (Dynamic3D)vector;
|
95
|
}
|
96
|
else if ( vector instanceof Static3D )
|
97
|
{
|
98
|
mStatic0 = (Static3D)vector;
|
99
|
}
|
100
|
|
101
|
if( center instanceof Static3D)
|
102
|
{
|
103
|
mStaticCenter = (Static3D)center;
|
104
|
}
|
105
|
else if( center instanceof Dynamic3D )
|
106
|
{
|
107
|
mDynamicCenter = (Dynamic3D)center;
|
108
|
}
|
109
|
|
110
|
mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
116
|
{
|
117
|
boolean ret = false;
|
118
|
|
119
|
if( mDynamicCenter!=null )
|
120
|
{
|
121
|
mDynamicCenter.interpolateMain(uniforms,index+5,currentDuration,step);
|
122
|
}
|
123
|
else
|
124
|
{
|
125
|
uniforms[index+5] = mStaticCenter.getX();
|
126
|
uniforms[index+6] = mStaticCenter.getY();
|
127
|
uniforms[index+7] = mStaticCenter.getZ();
|
128
|
}
|
129
|
|
130
|
if( mDynamicRegion!=null )
|
131
|
{
|
132
|
mDynamicRegion.interpolateMain(uniforms,index+8,currentDuration,step);
|
133
|
}
|
134
|
else
|
135
|
{
|
136
|
uniforms[index+ 8] = mStaticRegion.getX();
|
137
|
uniforms[index+ 9] = mStaticRegion.getY();
|
138
|
uniforms[index+10] = mStaticRegion.getZ();
|
139
|
uniforms[index+11] = mStaticRegion.getW();
|
140
|
}
|
141
|
|
142
|
if( mDynamic0!=null )
|
143
|
{
|
144
|
ret = mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
145
|
}
|
146
|
else
|
147
|
{
|
148
|
uniforms[index ] = ((Static3D)mStatic0).getX();
|
149
|
uniforms[index+1] = ((Static3D)mStatic0).getY();
|
150
|
uniforms[index+2] = ((Static3D)mStatic0).getZ();
|
151
|
}
|
152
|
|
153
|
return ret;
|
154
|
}
|
155
|
}
|