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