Revision beb325a0
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.main.DistortedTexture; |
30 | 30 |
import org.distorted.library.mesh.MeshFlat; |
31 | 31 |
import org.distorted.library.message.EffectListener; |
32 |
import org.distorted.object.RubikCube; |
|
33 |
import org.distorted.object.RubikCubeMovement; |
|
32 | 34 |
|
33 | 35 |
import javax.microedition.khronos.egl.EGLConfig; |
34 | 36 |
import javax.microedition.khronos.opengles.GL10; |
... | ... | |
37 | 39 |
|
38 | 40 |
public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener |
39 | 41 |
{ |
40 |
private static final float CUBE_SCREEN_RATIO = 0.5f; |
|
41 | 42 |
private static final float CAMERA_DISTANCE = 0.6f; // 0.6 of the length of max(scrHeight,scrWidth) |
42 | 43 |
public static final int TEXTURE_SIZE = 600; |
43 | 44 |
|
44 | 45 |
private RubikSurfaceView mView; |
45 | 46 |
private DistortedScreen mScreen; |
46 |
private float mCubeSizeInScreenSpace; |
|
47 | 47 |
private int mNextCubeSize, mScrambleCubeNum; |
48 | 48 |
private long mRotationFinishedID; |
49 | 49 |
private long[] mEffectID; |
... | ... | |
60 | 60 |
RubikRenderer(RubikSurfaceView v) |
61 | 61 |
{ |
62 | 62 |
mView = v; |
63 |
|
|
64 | 63 |
mScreen = new DistortedScreen(); |
65 | 64 |
|
66 | 65 |
mOldCube = null; |
... | ... | |
84 | 83 |
mEffectID = new long[BaseEffect.Type.LENGTH]; |
85 | 84 |
|
86 | 85 |
mMesh= new MeshFlat(20,20); |
87 |
mNextCubeSize = RubikSize.getSize(RubikActivity.getRedButton()).getCubeSize();
|
|
86 |
mNextCubeSize = RubikSize.getSize(mView.getRedButton()).getCubeSize();
|
|
88 | 87 |
} |
89 | 88 |
|
90 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
95 | 94 |
return (float)(2*halfFOVInRadians*(180/Math.PI)); |
96 | 95 |
} |
97 | 96 |
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
private void recomputeScaleFactor(int screenWidth, int screenHeight) |
|
101 |
{ |
|
102 |
mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(screenWidth>screenHeight ? screenHeight:screenWidth); |
|
103 |
|
|
104 |
if( mNewCube!=null ) |
|
105 |
{ |
|
106 |
mNewCube.recomputeScaleFactor(screenWidth, screenHeight, mCubeSizeInScreenSpace); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 98 |
|
112 | 99 |
private void createCubeNow(int newSize) |
... | ... | |
122 | 109 |
|
123 | 110 |
if( mScreenWidth!=0 ) |
124 | 111 |
{ |
125 |
recomputeScaleFactor(mScreenWidth,mScreenHeight);
|
|
112 |
mNewCube.recomputeScaleFactor(mScreenWidth, mScreenHeight);
|
|
126 | 113 |
} |
127 | 114 |
|
115 |
RubikCubeMovement movement = new RubikCubeMovement(mNewCube); |
|
116 |
mView.setMovement(movement); |
|
117 |
|
|
128 | 118 |
mIsSolved = true; |
129 | 119 |
} |
130 | 120 |
|
... | ... | |
135 | 125 |
{ |
136 | 126 |
int index = type.ordinal(); |
137 | 127 |
|
138 |
mEffectID[index] = type.startEffect(this); |
|
139 |
|
|
140 |
if( mEffectID[index] < 0 ) |
|
128 |
try |
|
129 |
{ |
|
130 |
mEffectID[index] = type.startEffect(this); |
|
131 |
} |
|
132 |
catch( Exception ex ) |
|
141 | 133 |
{ |
134 |
android.util.Log.e("renderer", "exception starting effect: "+ex.getMessage()); |
|
135 |
|
|
142 | 136 |
mCanUI = true; |
143 | 137 |
mCanRotate = true; |
144 | 138 |
mCanDrag = true; |
... | ... | |
188 | 182 |
} |
189 | 183 |
} |
190 | 184 |
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
|
|
193 |
float returnCubeSizeInScreenSpace() |
|
194 |
{ |
|
195 |
return mCubeSizeInScreenSpace; |
|
196 |
} |
|
197 |
|
|
198 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
199 | 186 |
|
200 | 187 |
boolean canRotate() |
... | ... | |
267 | 254 |
mCanRotate = false; |
268 | 255 |
mCanUI = false; |
269 | 256 |
doEffectNow( BaseEffect.Type.WIN ); |
257 |
mView.leaveScrambleModeNonUI(); |
|
270 | 258 |
} |
271 | 259 |
else |
272 | 260 |
{ |
... | ... | |
316 | 304 |
float cameraDistance = CAMERA_DISTANCE*(width>height ? width:height); |
317 | 305 |
float fovInDegrees = computeFOV(cameraDistance,height); |
318 | 306 |
|
319 |
mScreen.setProjection( fovInDegrees, 0.1f); |
|
320 | 307 |
mView.setScreenSize(width,height); |
321 | 308 |
mView.setCameraDist(cameraDistance); |
309 |
|
|
310 |
mScreen.setProjection( fovInDegrees, 0.1f); |
|
322 | 311 |
mScreen.resize(width, height); |
323 | 312 |
|
324 |
recomputeScaleFactor(width,height); |
|
313 |
if( mNewCube!=null ) |
|
314 |
{ |
|
315 |
mNewCube.recomputeScaleFactor(width, height); |
|
316 |
} |
|
325 | 317 |
|
326 | 318 |
mScreenHeight = height; |
327 | 319 |
mScreenWidth = width; |
Also available in: Unified diff
Major restructuring - separate the Manipulated Objects (i.e. at the time being - Cubes of various sizes) and the class holding knowledge how those Objects move ( RubikCubeMovement ) into a separate package; remove all knowledge of Objects and the way they move from the main package.