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