54 |
54 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated;
|
55 |
55 |
private boolean mCanRotate, mCanDrag;
|
56 |
56 |
private RubikCube mOldCube, mNewCube;
|
57 |
|
|
58 |
57 |
private int mScreenWidth, mScreenHeight;
|
59 |
|
|
60 |
58 |
private MeshQuad mMesh;
|
|
59 |
private AppearEffect.Type mAppearType;
|
|
60 |
private DisappearEffect.Type mDisappearType;
|
|
61 |
private int mAppearDuration, mDisappearDuration;
|
61 |
62 |
|
62 |
63 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
64 |
|
... | ... | |
85 |
86 |
mCanRotate = true;
|
86 |
87 |
mCanDrag = true;
|
87 |
88 |
|
|
89 |
mAppearType = AppearEffect.Type.SCALE;
|
|
90 |
mDisappearType = DisappearEffect.Type.SCALE;
|
|
91 |
|
|
92 |
mAppearDuration = 1000;
|
|
93 |
mDisappearDuration = 1000;
|
|
94 |
|
88 |
95 |
mMesh= new MeshQuad();
|
89 |
96 |
mNextCubeSize =RubikActivity.getSize();
|
90 |
97 |
}
|
... | ... | |
93 |
100 |
// various things are done here delayed, 'after the next render' as not to be done mid-render and
|
94 |
101 |
// cause artifacts.
|
95 |
102 |
|
|
103 |
@Override
|
96 |
104 |
public void onDrawFrame(GL10 glUnused)
|
97 |
105 |
{
|
98 |
106 |
mScreen.render( System.currentTimeMillis() );
|
... | ... | |
137 |
145 |
}
|
138 |
146 |
|
139 |
147 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
// EffectListener. The library sends a message to us when it's time to call 'removeRotation'
|
|
148 |
|
|
149 |
@Override
|
|
150 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
151 |
{
|
|
152 |
if( mNewCube!=null ) mNewCube.createTexture();
|
|
153 |
|
|
154 |
float cameraDistance = CAMERA_DISTANCE*(width>height ? width:height);
|
|
155 |
float fovInDegrees = computeFOV(cameraDistance,height);
|
|
156 |
|
|
157 |
mScreen.setProjection( fovInDegrees, 0.1f);
|
|
158 |
mView.setScreenSize(width,height);
|
|
159 |
mView.setCameraDist(cameraDistance);
|
|
160 |
mScreen.resize(width, height);
|
|
161 |
|
|
162 |
recomputeScaleFactor(width,height);
|
|
163 |
|
|
164 |
mScreenHeight = height;
|
|
165 |
mScreenWidth = width;
|
|
166 |
}
|
|
167 |
|
|
168 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
169 |
|
|
170 |
@Override
|
|
171 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
172 |
{
|
|
173 |
VertexEffectSink.enable();
|
|
174 |
AppearEffect.enableEffects();
|
|
175 |
DisappearEffect.enableEffects();
|
|
176 |
|
|
177 |
try
|
|
178 |
{
|
|
179 |
DistortedLibrary.onCreate(mView.getContext());
|
|
180 |
}
|
|
181 |
catch(Exception ex)
|
|
182 |
{
|
|
183 |
android.util.Log.e("Rubik", ex.getMessage() );
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
188 |
|
142 |
189 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
|
143 |
190 |
{
|
... | ... | |
162 |
209 |
{
|
163 |
210 |
try
|
164 |
211 |
{
|
165 |
|
DisappearEffect effect = DisappearEffect.create(DisappearEffect.Type.ROUND);
|
166 |
|
mDisappearEffectID = effect.start(mScreen,mOldCube,this);
|
|
212 |
DisappearEffect effect = DisappearEffect.create(mDisappearType);
|
|
213 |
mDisappearEffectID = effect.start(mDisappearDuration,mScreen,mOldCube,this);
|
167 |
214 |
}
|
168 |
215 |
catch(Exception ex)
|
169 |
216 |
{
|
... | ... | |
177 |
224 |
{
|
178 |
225 |
try
|
179 |
226 |
{
|
180 |
|
AppearEffect effect = AppearEffect.create(AppearEffect.Type.ROUND);
|
181 |
|
mAppearEffectID = effect.start(mScreen,mNewCube,this);
|
|
227 |
AppearEffect effect = AppearEffect.create(mAppearType);
|
|
228 |
mAppearEffectID = effect.start(mAppearDuration,mScreen,mNewCube,this);
|
182 |
229 |
}
|
183 |
230 |
catch(Exception ex)
|
184 |
231 |
{
|
... | ... | |
192 |
239 |
|
193 |
240 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194 |
241 |
|
195 |
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
196 |
|
{
|
197 |
|
if( mNewCube!=null ) mNewCube.createTexture();
|
|
242 |
private float computeFOV(float cameraDistance, int screenHeight)
|
|
243 |
{
|
|
244 |
double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) );
|
|
245 |
return (float)(2*halfFOVInRadians*(180/Math.PI));
|
|
246 |
}
|
198 |
247 |
|
199 |
|
float cameraDistance = CAMERA_DISTANCE*(width>height ? width:height);
|
200 |
|
float fovInDegrees = computeFOV(cameraDistance,height);
|
|
248 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
249 |
// no this will not race with onDrawFrame
|
201 |
250 |
|
202 |
|
mScreen.setProjection( fovInDegrees, 0.1f);
|
203 |
|
mView.setScreenSize(width,height);
|
204 |
|
mView.setCameraDist(cameraDistance);
|
205 |
|
mScreen.resize(width, height);
|
|
251 |
void finishRotation()
|
|
252 |
{
|
|
253 |
mFinishRotation = true;
|
|
254 |
}
|
206 |
255 |
|
207 |
|
recomputeScaleFactor(width,height);
|
|
256 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208 |
257 |
|
209 |
|
mScreenHeight = height;
|
210 |
|
mScreenWidth = width;
|
211 |
|
}
|
|
258 |
void setAppearDuration(int duration)
|
|
259 |
{
|
|
260 |
mAppearDuration = duration;
|
|
261 |
}
|
212 |
262 |
|
213 |
263 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214 |
|
|
215 |
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
216 |
|
{
|
217 |
|
VertexEffectSink.enable();
|
218 |
|
AppearEffect.enableEffects();
|
219 |
|
DisappearEffect.enableEffects();
|
220 |
264 |
|
221 |
|
try
|
222 |
|
{
|
223 |
|
DistortedLibrary.onCreate(mView.getContext());
|
224 |
|
}
|
225 |
|
catch(Exception ex)
|
226 |
|
{
|
227 |
|
android.util.Log.e("Rubik", ex.getMessage() );
|
228 |
|
}
|
229 |
|
}
|
|
265 |
void setDisappearDuration(int duration)
|
|
266 |
{
|
|
267 |
mDisappearDuration = duration;
|
|
268 |
}
|
230 |
269 |
|
231 |
270 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232 |
271 |
|
233 |
|
private float computeFOV(float cameraDistance, int screenHeight)
|
|
272 |
void setAppearType(AppearEffect.Type type)
|
234 |
273 |
{
|
235 |
|
double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) );
|
236 |
|
return (float)(2*halfFOVInRadians*(180/Math.PI));
|
|
274 |
mAppearType = type;
|
237 |
275 |
}
|
238 |
276 |
|
239 |
277 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240 |
|
// no this will not race with onDrawFrame
|
241 |
278 |
|
242 |
|
void finishRotation()
|
|
279 |
void setDisappearType(DisappearEffect.Type type)
|
243 |
280 |
{
|
244 |
|
mFinishRotation = true;
|
|
281 |
mDisappearType = type;
|
245 |
282 |
}
|
246 |
283 |
|
247 |
284 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Progress.