1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube 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
|
// Magic Cube 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 Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.control;
|
21
|
|
22
|
import android.graphics.Bitmap;
|
23
|
import android.graphics.BitmapFactory;
|
24
|
|
25
|
import org.distorted.library.effect.MatrixEffectMove;
|
26
|
import org.distorted.library.effect.MatrixEffectScale;
|
27
|
import org.distorted.library.main.DistortedEffects;
|
28
|
import org.distorted.library.main.DistortedNode;
|
29
|
import org.distorted.library.main.DistortedTexture;
|
30
|
import org.distorted.library.mesh.MeshQuad;
|
31
|
import org.distorted.library.type.Dynamic;
|
32
|
import org.distorted.library.type.Dynamic3D;
|
33
|
import org.distorted.library.type.Static3D;
|
34
|
import org.distorted.main.R;
|
35
|
import org.distorted.main.RubikActivity;
|
36
|
|
37
|
import java.io.IOException;
|
38
|
import java.io.InputStream;
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
class RubikControlWhole
|
43
|
{
|
44
|
private static final int NUM_NODE = 2;
|
45
|
private static final int NUM_EFFE = 2;
|
46
|
|
47
|
private final RubikControl mControl;
|
48
|
private DistortedEffects[] mEffects;
|
49
|
private DistortedNode[] mNodes;
|
50
|
private long mEffectID;
|
51
|
|
52
|
private Dynamic3D mDynamic;
|
53
|
private MatrixEffectMove mMove;
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
private Bitmap openBitmap(RubikActivity act, int resource)
|
58
|
{
|
59
|
try(InputStream is = act.getResources().openRawResource(resource) )
|
60
|
{
|
61
|
return BitmapFactory.decodeStream(is);
|
62
|
}
|
63
|
catch(IOException e)
|
64
|
{
|
65
|
// ignore
|
66
|
}
|
67
|
|
68
|
return null;
|
69
|
}
|
70
|
|
71
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72
|
|
73
|
private void createEffects()
|
74
|
{
|
75
|
if( mEffects==null )
|
76
|
{
|
77
|
mEffects = new DistortedEffects[NUM_EFFE];
|
78
|
mEffects[0]= new DistortedEffects();
|
79
|
mEffects[1]= new DistortedEffects();
|
80
|
|
81
|
float x1 = 200;
|
82
|
float y1 = 300;
|
83
|
float z = 0;
|
84
|
|
85
|
Static3D point0 = new Static3D(-x1,-y1,z);
|
86
|
Static3D point1 = new Static3D(+x1,-y1,z);
|
87
|
Static3D point2 = new Static3D(+x1,+y1,z);
|
88
|
|
89
|
mDynamic = new Dynamic3D(10000,0.5f);
|
90
|
mDynamic.add(point0);
|
91
|
mDynamic.add(point1);
|
92
|
mDynamic.add(point2);
|
93
|
mDynamic.setMode(Dynamic.MODE_PATH);
|
94
|
|
95
|
mMove = new MatrixEffectMove(mDynamic);
|
96
|
mMove.notifyWhenFinished(mControl);
|
97
|
mEffectID = mMove.getID();
|
98
|
|
99
|
mEffects[0].apply( new MatrixEffectScale(150));
|
100
|
mEffects[0].apply(mMove);
|
101
|
mEffects[1].apply( new MatrixEffectScale(300));
|
102
|
mEffects[1].apply(mMove);
|
103
|
}
|
104
|
else
|
105
|
{
|
106
|
mDynamic.resetToBeginning();
|
107
|
mMove.notifyWhenFinished(mControl);
|
108
|
}
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
private void createNodes()
|
114
|
{
|
115
|
if( mNodes==null )
|
116
|
{
|
117
|
mNodes = new DistortedNode[NUM_NODE];
|
118
|
RubikActivity act = mControl.getActivity();
|
119
|
|
120
|
if( act!=null )
|
121
|
{
|
122
|
MeshQuad mesh = new MeshQuad();
|
123
|
|
124
|
Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
|
125
|
DistortedTexture textureCirc = new DistortedTexture();
|
126
|
textureCirc.setTexture(bmpCirc);
|
127
|
mNodes[0]= new DistortedNode(textureCirc,mEffects[0],mesh);
|
128
|
|
129
|
Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
|
130
|
DistortedTexture textureHand = new DistortedTexture();
|
131
|
textureHand.setTexture(bmpHand);
|
132
|
mNodes[1]= new DistortedNode(textureHand,mEffects[1],mesh);
|
133
|
}
|
134
|
else
|
135
|
{
|
136
|
android.util.Log.e("D", "Activity NULL!!");
|
137
|
}
|
138
|
}
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
long getEffectID()
|
144
|
{
|
145
|
return mEffectID;
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
DistortedNode[] getNodes()
|
151
|
{
|
152
|
createEffects();
|
153
|
createNodes();
|
154
|
|
155
|
return mNodes;
|
156
|
}
|
157
|
|
158
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
159
|
|
160
|
DistortedNode[] returnNodes()
|
161
|
{
|
162
|
return mNodes;
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
RubikControlWhole(RubikControl control)
|
168
|
{
|
169
|
mControl = control;
|
170
|
}
|
171
|
}
|