Revision 213c15de
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java | ||
---|---|---|
284 | 284 |
public void deleteObject(String name) |
285 | 285 |
{ |
286 | 286 |
RubikFiles files = RubikFiles.getInstance(); |
287 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
288 |
SharedPreferences.Editor editor = preferences.edit(); |
|
289 |
|
|
290 |
int meshState = TwistyObject.MESH_NICE; |
|
291 |
int iconMode = TwistyObject.MODE_NORM; |
|
292 | 287 |
InputStream jsonStream = files.openFile(this,name+"_object.json"); |
293 |
TwistyObject object = new TwistyJson( jsonStream, meshState, iconMode, null, null, 1.0f, null); |
|
294 |
object.removePreferences(editor); |
|
295 | 288 |
|
296 |
editor.apply(); |
|
289 |
if( jsonStream!=null ) |
|
290 |
{ |
|
291 |
int meshState= TwistyObject.MESH_NICE; |
|
292 |
int iconMode = TwistyObject.MODE_NORM; |
|
293 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
294 |
SharedPreferences.Editor editor = preferences.edit(); |
|
295 |
TwistyObject object = new TwistyJson( jsonStream, meshState, iconMode, null, null, 1.0f, null); |
|
296 |
object.removePreferences(editor); |
|
297 |
editor.apply(); |
|
298 |
} |
|
297 | 299 |
|
298 | 300 |
mScreen.deleteObject(this,name); |
299 | 301 |
files.deleteIcon(this,name); |
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
---|---|---|
60 | 60 |
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
61 | 61 |
{ |
62 | 62 |
public static final float BRIGHTNESS = 0.333f; |
63 |
private static final int DURATION = 1000; |
|
63 |
private static final int RESET_DURATION = 1000;
|
|
64 | 64 |
static final float SCREEN_RATIO = 0.5f; |
65 | 65 |
|
66 | 66 |
private final BandagedCreatorView mView; |
... | ... | |
153 | 153 |
c++; |
154 | 154 |
} |
155 | 155 |
|
156 |
mView.setCubits(mCubits); |
|
156 |
mView.setCubits(mCubits,mX,mY,mZ);
|
|
157 | 157 |
} |
158 | 158 |
|
159 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
292 | 292 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
293 | 293 |
{ |
294 | 294 |
DistortedLibrary.setMax(EffectType.VERTEX,25); |
295 |
MeshBase.setMaxEffComponents(50);
|
|
295 |
MeshBase.setMaxEffComponents(120);
|
|
296 | 296 |
|
297 | 297 |
VertexEffectDeform.enable(); |
298 | 298 |
FragmentEffectBrightness.enable(); |
... | ... | |
587 | 587 |
public boolean continueResetting(long time) |
588 | 588 |
{ |
589 | 589 |
long diff = time-mStartTime; |
590 |
float quotient = ((float)diff)/DURATION; |
|
590 |
float quotient = ((float)diff)/RESET_DURATION;
|
|
591 | 591 |
|
592 | 592 |
if( mInitialPhase && quotient>0.5f ) |
593 | 593 |
{ |
src/main/java/org/distorted/bandaged/BandagedCreatorTouchControl.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
public class BandagedCreatorTouchControl |
30 | 30 |
{ |
31 |
private static final float DIST3D = 0.5f; |
|
32 | 31 |
private static final float DIST2D = 0.5f; |
33 | 32 |
|
34 | 33 |
private final Static4D CAMERA_POINT; |
... | ... | |
36 | 35 |
private final float[] mPoint2D; |
37 | 36 |
private float mObjectRatio; |
38 | 37 |
private final Static3D[] mFaceAxis; |
38 |
private final float[] mDist3D; |
|
39 | 39 |
|
40 | 40 |
private BandagedCubit[] mCubits; |
41 | 41 |
private int mNumCubits; |
42 | 42 |
private int mLastTouchedFace; |
43 |
private float mX, mY, mZ, mMax; |
|
43 | 44 |
|
44 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 | 46 |
|
46 |
private boolean isInsideFace(float[] p) |
|
47 |
private boolean isInsideFace(int face, float[] p)
|
|
47 | 48 |
{ |
48 | 49 |
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D ); |
49 | 50 |
} |
... | ... | |
103 | 104 |
// |
104 | 105 |
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)] |
105 | 106 |
|
106 |
private void castTouchPointOntoFace(int index, float[] output)
|
|
107 |
private void castTouchPointOntoFace(int face, float[] output)
|
|
107 | 108 |
{ |
108 |
Static3D faceAxis = mFaceAxis[index];
|
|
109 |
Static3D faceAxis = mFaceAxis[face];
|
|
109 | 110 |
|
110 | 111 |
float d0 = mPoint[0]-mCamera[0]; |
111 | 112 |
float d1 = mPoint[1]-mCamera[1]; |
... | ... | |
119 | 120 |
if( denom != 0.0f ) |
120 | 121 |
{ |
121 | 122 |
float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2]; |
122 |
float alpha = (DIST3D-axisCam)/denom;
|
|
123 |
float alpha = (mDist3D[face]-axisCam)/denom;
|
|
123 | 124 |
|
124 | 125 |
output[0] = mCamera[0] + d0*alpha; |
125 | 126 |
output[1] = mCamera[1] + d1*alpha; |
... | ... | |
129 | 130 |
|
130 | 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
131 | 132 |
|
132 |
private boolean faceIsVisible(int index)
|
|
133 |
private void stretchPoint(int face, float[] output)
|
|
133 | 134 |
{ |
134 |
Static3D faceAxis = mFaceAxis[index]; |
|
135 |
switch(face/2) |
|
136 |
{ |
|
137 |
case 0: output[0] *= (mMax/mZ); output[1] *= (mMax/mY); break; |
|
138 |
case 1: output[0] *= (mMax/mX); output[1] *= (mMax/mZ); break; |
|
139 |
case 2: output[0] *= (mMax/mX); output[1] *= (mMax/mY); break; |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
144 |
|
|
145 |
private boolean faceIsVisible(int face) |
|
146 |
{ |
|
147 |
Static3D faceAxis = mFaceAxis[face]; |
|
135 | 148 |
float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2(); |
136 |
return castCameraOnAxis > DIST3D;
|
|
149 |
return castCameraOnAxis > mDist3D[face];
|
|
137 | 150 |
} |
138 | 151 |
|
139 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
159 | 172 |
float az = mFaceAxis[mLastTouchedFace].get2(); |
160 | 173 |
|
161 | 174 |
convertTo2Dcoords(mTouch, ax,ay,az, mPoint2D); |
162 |
if( isInsideFace(mPoint2D) ) return true; |
|
175 |
stretchPoint(mLastTouchedFace,mPoint2D); |
|
176 |
if( isInsideFace(mLastTouchedFace,mPoint2D) ) return true; |
|
163 | 177 |
} |
164 | 178 |
} |
165 | 179 |
|
... | ... | |
170 | 184 |
|
171 | 185 |
private void computePosition(int face, float pointX, float pointY) |
172 | 186 |
{ |
173 |
int x = (int)(3*pointX+1.5f) -1; |
|
174 |
int y = (int)(3*pointY+1.5f) -1; |
|
175 |
|
|
176 | 187 |
switch(face) |
177 | 188 |
{ |
178 |
case 0: mPos[0] = 1.0f; mPos[1] = y; mPos[2] = -x; break; |
|
179 |
case 1: mPos[0] =-1.0f; mPos[1] = y; mPos[2] = x; break; |
|
180 |
case 2: mPos[0] = x; mPos[1] = 1.0f; mPos[2] = -y; break; |
|
181 |
case 3: mPos[0] = x; mPos[1] =-1.0f; mPos[2] = y; break; |
|
182 |
case 4: mPos[0] = x; mPos[1] = y; mPos[2] = 1.0f; break; |
|
183 |
case 5: mPos[0] = -x; mPos[1] = y; mPos[2] =-1.0f; break; |
|
189 |
case 0: mPos[0] = (mX-1)/2; |
|
190 |
mPos[1] = (int)(+mY*pointY+mY/2)-(mY-1)/2; |
|
191 |
mPos[2] = (int)(-mZ*pointX-mZ/2)+(mZ-1)/2; |
|
192 |
break; |
|
193 |
case 1: mPos[0] =-(mX-1)/2; |
|
194 |
mPos[1] = (int)(+mY*pointY+mY/2)-(mY-1)/2; |
|
195 |
mPos[2] = (int)(+mZ*pointX+mZ/2)-(mZ-1)/2; |
|
196 |
break; |
|
197 |
case 2: mPos[0] = (int)(+mX*pointX+mX/2)-(mX-1)/2; |
|
198 |
mPos[1] = (mY-1)/2; |
|
199 |
mPos[2] = (int)(-mZ*pointY-mZ/2)+(mZ-1)/2; |
|
200 |
break; |
|
201 |
case 3: mPos[0] = (int)(+mX*pointX+mX/2)-(mX-1)/2; |
|
202 |
mPos[1] =-(mY-1)/2; |
|
203 |
mPos[2] = (int)(+mZ*pointY+mZ/2)-(mZ-1)/2; |
|
204 |
break; |
|
205 |
case 4: mPos[0] = (int)(+mX*pointX+mX/2)-(mX-1)/2; |
|
206 |
mPos[1] = (int)(+mY*pointY+mY/2)-(mY-1)/2; |
|
207 |
mPos[2] = (mZ-1)/2; |
|
208 |
break; |
|
209 |
case 5: mPos[0] = (int)(-mX*pointX-mX/2)+(mX-1)/2; |
|
210 |
mPos[1] = (int)(+mY*pointY+mY/2)-(mY-1)/2; |
|
211 |
mPos[2] =-(mZ-1)/2; |
|
212 |
break; |
|
184 | 213 |
} |
185 | 214 |
} |
186 | 215 |
|
... | ... | |
215 | 244 |
mTouch = new float[3]; |
216 | 245 |
mPos = new float[3]; |
217 | 246 |
mPoint2D = new float[2]; |
247 |
mDist3D = new float[6]; |
|
218 | 248 |
mFaceAxis = TouchControlHexahedron.FACE_AXIS; |
219 | 249 |
mObjectRatio = ratio; |
220 | 250 |
|
... | ... | |
227 | 257 |
|
228 | 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
229 | 259 |
|
230 |
public void setCubits(BandagedCubit[] cubits) |
|
260 |
public void setCubits(BandagedCubit[] cubits, int x, int y, int z)
|
|
231 | 261 |
{ |
232 | 262 |
mCubits = cubits; |
233 | 263 |
mNumCubits = cubits.length; |
264 |
|
|
265 |
mX = x; |
|
266 |
mY = y; |
|
267 |
mZ = z; |
|
268 |
mMax = mX>mY ? Math.max(mX,mZ) : Math.max(mY,mZ); |
|
269 |
|
|
270 |
mDist3D[0] = mDist3D[1] = 0.5f*(mX/mMax); |
|
271 |
mDist3D[2] = mDist3D[3] = 0.5f*(mY/mMax); |
|
272 |
mDist3D[4] = mDist3D[5] = 0.5f*(mZ/mMax); |
|
234 | 273 |
} |
235 | 274 |
|
236 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/bandaged/BandagedCreatorView.java | ||
---|---|---|
108 | 108 |
|
109 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
110 | 110 |
|
111 |
public void setCubits(BandagedCubit[] cubits) |
|
111 |
public void setCubits(BandagedCubit[] cubits, int x, int y, int z)
|
|
112 | 112 |
{ |
113 |
mTouchControl.setCubits(cubits); |
|
113 |
mTouchControl.setCubits(cubits,x,y,z);
|
|
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
146 | 146 |
|
147 | 147 |
switch(action) |
148 | 148 |
{ |
149 |
case MotionEvent.ACTION_DOWN: float x1 = (x - mScreenWidth*0.5f)/mScreenMin;
|
|
150 |
float y1 = (mScreenHeight*0.5f - y)/mScreenMin;
|
|
149 |
case MotionEvent.ACTION_DOWN: float x1 = (x -mScreenWidth*0.5f)/mScreenMin; |
|
150 |
float y1 = (mScreenHeight*0.5f-y)/mScreenMin;
|
|
151 | 151 |
|
152 | 152 |
int index = mTouchControl.cubitTouched(x1,y1,mRenderer.getQuatAccu() ); |
153 | 153 |
|
Also available in: Unified diff
Bandaged: progress with touch control.