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.Data1D;
|
23
|
import org.distorted.library.type.Data3D;
|
24
|
import org.distorted.library.type.Data4D;
|
25
|
import org.distorted.library.type.Dynamic1D;
|
26
|
import org.distorted.library.type.Dynamic3D;
|
27
|
import org.distorted.library.type.Dynamic4D;
|
28
|
import org.distorted.library.type.Static1D;
|
29
|
import org.distorted.library.type.Static3D;
|
30
|
import org.distorted.library.type.Static4D;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class MatrixEffectRotate extends MatrixEffect
|
35
|
{
|
36
|
private static final float[] UNITIES = new float[]{0.0f};
|
37
|
private static final int DIMENSION = 4;
|
38
|
private static final boolean SUPPORTS_CENTER = true;
|
39
|
private static final boolean SUPPORTS_REGION = false;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public MatrixEffectRotate(Data1D angle, Static3D axis, Data3D center)
|
44
|
{
|
45
|
super(ROTATE,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
|
46
|
|
47
|
if( angle instanceof Static1D )
|
48
|
{
|
49
|
mStatic0 = (Static1D)angle;
|
50
|
}
|
51
|
else if( angle instanceof Dynamic1D )
|
52
|
{
|
53
|
mDynamic0 = (Dynamic1D)angle;
|
54
|
}
|
55
|
|
56
|
mStatic1 = axis;
|
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
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
public MatrixEffectRotate(Data4D angleaxis, Data3D center)
|
71
|
{
|
72
|
super(ROTATE,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
|
73
|
|
74
|
if( angleaxis instanceof Static4D)
|
75
|
{
|
76
|
mStatic0 = (Static4D)angleaxis;
|
77
|
}
|
78
|
else if( angleaxis instanceof Dynamic4D)
|
79
|
{
|
80
|
mDynamic0 = (Dynamic4D)angleaxis;
|
81
|
}
|
82
|
|
83
|
if( center instanceof Static3D)
|
84
|
{
|
85
|
mStaticCenter = (Static3D)center;
|
86
|
}
|
87
|
else if( center instanceof Dynamic3D )
|
88
|
{
|
89
|
mDynamicCenter = (Dynamic3D)center;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
|
95
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
96
|
{
|
97
|
if( mDynamicCenter!=null )
|
98
|
{
|
99
|
mDynamicCenter.interpolateMain(uniforms,index+4,currentDuration,step);
|
100
|
}
|
101
|
else
|
102
|
{
|
103
|
uniforms[index+4] = mStaticCenter.getX();
|
104
|
uniforms[index+5] = mStaticCenter.getY();
|
105
|
uniforms[index+6] = mStaticCenter.getZ();
|
106
|
}
|
107
|
|
108
|
if( mDynamic0!=null )
|
109
|
{
|
110
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
111
|
}
|
112
|
else
|
113
|
{
|
114
|
if( mStatic1 != null )
|
115
|
{
|
116
|
uniforms[index ] = ((Static1D)mStatic0).getX();
|
117
|
uniforms[index+1] = ((Static3D)mStatic1).getX();
|
118
|
uniforms[index+2] = ((Static3D)mStatic1).getY();
|
119
|
uniforms[index+3] = ((Static3D)mStatic1).getZ();
|
120
|
}
|
121
|
else
|
122
|
{
|
123
|
uniforms[index ] = ((Static4D)mStatic0).getX();
|
124
|
uniforms[index+1] = ((Static4D)mStatic0).getY();
|
125
|
uniforms[index+2] = ((Static4D)mStatic0).getZ();
|
126
|
uniforms[index+3] = ((Static4D)mStatic0).getW();
|
127
|
}
|
128
|
|
129
|
return false;
|
130
|
}
|
131
|
}
|
132
|
}
|