1 |
2014665f
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
6d62a900
|
Leszek Koltunski
|
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 |
15aa7d94
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
27 |
6d62a900
|
Leszek Koltunski
|
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 |
2014665f
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
public class MatrixEffectRotate extends MatrixEffect
|
35 |
|
|
{
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
6bb59aad
|
Leszek Koltunski
|
/**
|
38 |
|
|
* Rotates the Object by 'angle' degrees around the center.
|
39 |
|
|
* Static axis of rotation is given by the last parameter.
|
40 |
|
|
*
|
41 |
|
|
* @param angle Angle that we want to rotate the Object to. Unit: degrees
|
42 |
|
|
* @param axis Axis of rotation
|
43 |
|
|
* @param center Coordinates of the Point we are rotating around.
|
44 |
|
|
*/
|
45 |
6d62a900
|
Leszek Koltunski
|
public MatrixEffectRotate(Data1D angle, Static3D axis, Data3D center)
|
46 |
2014665f
|
leszek
|
{
|
47 |
9d0d8530
|
leszek
|
super(EffectName.ROTATE);
|
48 |
6d62a900
|
Leszek Koltunski
|
|
49 |
|
|
if( angle instanceof Static1D )
|
50 |
|
|
{
|
51 |
|
|
mStatic0 = (Static1D)angle;
|
52 |
|
|
}
|
53 |
|
|
else if( angle instanceof Dynamic1D )
|
54 |
|
|
{
|
55 |
|
|
mDynamic0 = (Dynamic1D)angle;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
mStatic1 = axis;
|
59 |
15aa7d94
|
Leszek Koltunski
|
|
60 |
|
|
if( center instanceof Static3D)
|
61 |
|
|
{
|
62 |
|
|
mStaticCenter = (Static3D)center;
|
63 |
|
|
}
|
64 |
|
|
else if( center instanceof Dynamic3D )
|
65 |
|
|
{
|
66 |
|
|
mDynamicCenter = (Dynamic3D)center;
|
67 |
|
|
}
|
68 |
2014665f
|
leszek
|
}
|
69 |
6d62a900
|
Leszek Koltunski
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
6bb59aad
|
Leszek Koltunski
|
/**
|
72 |
|
|
* Rotates the Object by 'angle' degrees around the center.
|
73 |
|
|
* Here both angle and axis can dynamically change.
|
74 |
|
|
*
|
75 |
|
|
* @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
|
76 |
|
|
* @param center Coordinates of the Point we are rotating around.
|
77 |
|
|
*/
|
78 |
6d62a900
|
Leszek Koltunski
|
public MatrixEffectRotate(Data4D angleaxis, Data3D center)
|
79 |
|
|
{
|
80 |
9d0d8530
|
leszek
|
super(EffectName.ROTATE);
|
81 |
6d62a900
|
Leszek Koltunski
|
|
82 |
|
|
if( angleaxis instanceof Static4D)
|
83 |
|
|
{
|
84 |
|
|
mStatic0 = (Static4D)angleaxis;
|
85 |
|
|
}
|
86 |
|
|
else if( angleaxis instanceof Dynamic4D)
|
87 |
|
|
{
|
88 |
|
|
mDynamic0 = (Dynamic4D)angleaxis;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
15aa7d94
|
Leszek Koltunski
|
if( center instanceof Static3D)
|
92 |
|
|
{
|
93 |
|
|
mStaticCenter = (Static3D)center;
|
94 |
|
|
}
|
95 |
|
|
else if( center instanceof Dynamic3D )
|
96 |
|
|
{
|
97 |
|
|
mDynamicCenter = (Dynamic3D)center;
|
98 |
|
|
}
|
99 |
6d62a900
|
Leszek Koltunski
|
}
|
100 |
|
|
|
101 |
15aa7d94
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
104 |
|
|
{
|
105 |
|
|
if( mDynamicCenter!=null )
|
106 |
|
|
{
|
107 |
|
|
mDynamicCenter.interpolateMain(uniforms,index+4,currentDuration,step);
|
108 |
|
|
}
|
109 |
|
|
else
|
110 |
|
|
{
|
111 |
|
|
uniforms[index+4] = mStaticCenter.getX();
|
112 |
|
|
uniforms[index+5] = mStaticCenter.getY();
|
113 |
|
|
uniforms[index+6] = mStaticCenter.getZ();
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
if( mDynamic0!=null )
|
117 |
|
|
{
|
118 |
|
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
119 |
|
|
}
|
120 |
|
|
else
|
121 |
|
|
{
|
122 |
|
|
if( mStatic1 != null )
|
123 |
|
|
{
|
124 |
|
|
uniforms[index ] = ((Static1D)mStatic0).getX();
|
125 |
|
|
uniforms[index+1] = ((Static3D)mStatic1).getX();
|
126 |
|
|
uniforms[index+2] = ((Static3D)mStatic1).getY();
|
127 |
|
|
uniforms[index+3] = ((Static3D)mStatic1).getZ();
|
128 |
|
|
}
|
129 |
|
|
else
|
130 |
|
|
{
|
131 |
|
|
uniforms[index ] = ((Static4D)mStatic0).getX();
|
132 |
|
|
uniforms[index+1] = ((Static4D)mStatic0).getY();
|
133 |
|
|
uniforms[index+2] = ((Static4D)mStatic0).getZ();
|
134 |
|
|
uniforms[index+3] = ((Static4D)mStatic0).getW();
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
return false;
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
2014665f
|
leszek
|
}
|