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 MatrixEffectQuaternion extends MatrixEffect
|
32
|
{
|
33
|
private static final float[] UNITIES = new float[]{0.0f, 0.0f, 0.0f};
|
34
|
private static final int DIMENSION = 4;
|
35
|
private static final boolean SUPPORTS_CENTER = true;
|
36
|
private static final boolean SUPPORTS_REGION = false;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
/**
|
40
|
* Rotates the Object by quaternion.
|
41
|
*
|
42
|
* @param quaternion The quaternion describing the rotation.
|
43
|
* @param center Coordinates of the Point we are rotating around.
|
44
|
*/
|
45
|
public MatrixEffectQuaternion(Data4D quaternion, Data3D center )
|
46
|
{
|
47
|
super(EffectName.QUATERNION,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION,UNITIES);
|
48
|
|
49
|
if( quaternion instanceof Static4D)
|
50
|
{
|
51
|
mStatic0 = (Static4D)quaternion;
|
52
|
}
|
53
|
else if( quaternion instanceof Dynamic4D)
|
54
|
{
|
55
|
mDynamic0 = (Dynamic4D)quaternion;
|
56
|
}
|
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 boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
71
|
{
|
72
|
if( mDynamicCenter!=null )
|
73
|
{
|
74
|
mDynamicCenter.interpolateMain(uniforms,index+4,currentDuration,step);
|
75
|
}
|
76
|
else
|
77
|
{
|
78
|
uniforms[index+4] = mStaticCenter.getX();
|
79
|
uniforms[index+5] = mStaticCenter.getY();
|
80
|
uniforms[index+6] = mStaticCenter.getZ();
|
81
|
}
|
82
|
|
83
|
if( mDynamic0!=null )
|
84
|
{
|
85
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
86
|
}
|
87
|
else
|
88
|
{
|
89
|
uniforms[index ] = ((Static4D)mStatic0).getX();
|
90
|
uniforms[index+1] = ((Static4D)mStatic0).getY();
|
91
|
uniforms[index+2] = ((Static4D)mStatic0).getZ();
|
92
|
uniforms[index+3] = ((Static4D)mStatic0).getW();
|
93
|
|
94
|
return false;
|
95
|
}
|
96
|
}
|
97
|
}
|