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.DistortedScreen;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshQuad;
|
32
|
import org.distorted.library.type.Dynamic;
|
33
|
import org.distorted.library.type.Dynamic3D;
|
34
|
import org.distorted.library.type.Static3D;
|
35
|
import org.distorted.main.R;
|
36
|
import org.distorted.main.RubikActivity;
|
37
|
|
38
|
import java.io.IOException;
|
39
|
import java.io.InputStream;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
class RubikControlWhole
|
44
|
{
|
45
|
private static final int NUM_NODE = 4;
|
46
|
private static final int NUM_EFFE = 4;
|
47
|
|
48
|
private final RubikControl mControl;
|
49
|
private DistortedEffects[] mEffects;
|
50
|
private DistortedNode[] mNodes;
|
51
|
private long mEffectID;
|
52
|
|
53
|
private Dynamic3D mDynamicHand1;
|
54
|
private MatrixEffectMove mMoveHand1;
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
private Bitmap openBitmap(RubikActivity act, int resource)
|
59
|
{
|
60
|
try(InputStream is = act.getResources().openRawResource(resource) )
|
61
|
{
|
62
|
return BitmapFactory.decodeStream(is);
|
63
|
}
|
64
|
catch(IOException e)
|
65
|
{
|
66
|
// ignore
|
67
|
}
|
68
|
|
69
|
return null;
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
private void createEffects()
|
75
|
{
|
76
|
if( mEffects==null )
|
77
|
{
|
78
|
mEffects = new DistortedEffects[NUM_EFFE];
|
79
|
for(int i=0; i<NUM_EFFE; i++) mEffects[i]= new DistortedEffects();
|
80
|
|
81
|
DistortedScreen screen = mControl.getScreen();
|
82
|
int wid = screen.getWidth();
|
83
|
int hei = screen.getHeight();
|
84
|
|
85
|
float x1 = wid*0.35f;
|
86
|
float y1 = hei*0.28f;
|
87
|
float z = 0;
|
88
|
|
89
|
Static3D point0 = new Static3D(-x1,-y1,z);
|
90
|
Static3D point1 = new Static3D( 0,-y1,z);
|
91
|
Static3D point2 = new Static3D(+x1,-y1,z);
|
92
|
Static3D point3 = new Static3D(+x1, 0,z);
|
93
|
Static3D point4 = new Static3D(+x1,+y1,z);
|
94
|
Static3D point5 = new Static3D( 0, 0,z);
|
95
|
|
96
|
mDynamicHand1 = new Dynamic3D(15000,0.5f);
|
97
|
mDynamicHand1.add(point0);
|
98
|
mDynamicHand1.add(point0);
|
99
|
mDynamicHand1.add(point1);
|
100
|
mDynamicHand1.add(point2);
|
101
|
mDynamicHand1.add(point2);
|
102
|
mDynamicHand1.add(point3);
|
103
|
mDynamicHand1.add(point4);
|
104
|
mDynamicHand1.add(point4);
|
105
|
mDynamicHand1.add(point5);
|
106
|
mDynamicHand1.add(point0);
|
107
|
mDynamicHand1.add(point0);
|
108
|
mDynamicHand1.setMode(Dynamic.MODE_PATH);
|
109
|
mDynamicHand1.setConvexity(0.0f);
|
110
|
|
111
|
mMoveHand1 = new MatrixEffectMove(mDynamicHand1);
|
112
|
mMoveHand1.notifyWhenFinished(mControl);
|
113
|
mEffectID = mMoveHand1.getID();
|
114
|
|
115
|
mEffects[0].apply( new MatrixEffectScale(150));
|
116
|
mEffects[0].apply(mMoveHand1);
|
117
|
mEffects[2].apply( new MatrixEffectScale(300));
|
118
|
mEffects[2].apply(mMoveHand1);
|
119
|
}
|
120
|
else
|
121
|
{
|
122
|
mDynamicHand1.resetToBeginning();
|
123
|
mMoveHand1.notifyWhenFinished(mControl);
|
124
|
}
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
private void createNodes()
|
130
|
{
|
131
|
if( mNodes==null )
|
132
|
{
|
133
|
mNodes = new DistortedNode[NUM_NODE];
|
134
|
RubikActivity act = mControl.getActivity();
|
135
|
|
136
|
if( act!=null )
|
137
|
{
|
138
|
MeshQuad mesh = new MeshQuad();
|
139
|
|
140
|
Bitmap bmpCirc = openBitmap(act, R.drawable.ui_fading_circle);
|
141
|
DistortedTexture textureCirc = new DistortedTexture();
|
142
|
textureCirc.setTexture(bmpCirc);
|
143
|
mNodes[0]= new DistortedNode(textureCirc,mEffects[0],mesh);
|
144
|
mNodes[1]= new DistortedNode(textureCirc,mEffects[1],mesh);
|
145
|
|
146
|
Bitmap bmpHand = openBitmap(act, R.drawable.ui_hand_pointer);
|
147
|
DistortedTexture textureHand = new DistortedTexture();
|
148
|
textureHand.setTexture(bmpHand);
|
149
|
mNodes[2]= new DistortedNode(textureHand,mEffects[2],mesh);
|
150
|
mNodes[3]= new DistortedNode(textureHand,mEffects[3],mesh);
|
151
|
}
|
152
|
else
|
153
|
{
|
154
|
android.util.Log.e("D", "Activity NULL!!");
|
155
|
}
|
156
|
}
|
157
|
}
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
|
161
|
long getEffectID()
|
162
|
{
|
163
|
return mEffectID;
|
164
|
}
|
165
|
|
166
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167
|
|
168
|
DistortedNode[] getNodes()
|
169
|
{
|
170
|
createEffects();
|
171
|
createNodes();
|
172
|
|
173
|
return mNodes;
|
174
|
}
|
175
|
|
176
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
177
|
|
178
|
DistortedNode[] returnNodes()
|
179
|
{
|
180
|
return mNodes;
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
RubikControlWhole(RubikControl control)
|
186
|
{
|
187
|
mControl = control;
|
188
|
}
|
189
|
}
|