Revision 75c7def3
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java | ||
---|---|---|
44 | 44 |
import org.distorted.library.EffectTypes; |
45 | 45 |
import org.distorted.library.type.Dynamic1D; |
46 | 46 |
import org.distorted.library.type.Dynamic3D; |
47 |
import org.distorted.library.type.Dynamic4D; |
|
47 | 48 |
|
48 | 49 |
import java.util.ArrayList; |
49 | 50 |
|
50 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 52 |
|
52 | 53 |
public class Fragment3DActivity extends Activity |
53 |
implements OnSeekBarChangeListener, |
|
54 |
View.OnClickListener, |
|
54 |
implements View.OnClickListener, |
|
55 | 55 |
AdapterView.OnItemSelectedListener |
56 | 56 |
{ |
57 | 57 |
private static final int COLOR_OFF = 0xffffe81f; |
... | ... | |
70 | 70 |
private int mObjectType; |
71 | 71 |
private int mBitmap; |
72 | 72 |
|
73 |
// fields needed for the second 'apply fragment effects' screen |
|
74 |
// |
|
75 |
private TextView textCenter; |
|
76 |
private int centerX, centerY; |
|
77 |
private float fcenterX, fcenterY; |
|
78 | 73 |
private ArrayList<Fragment3DEffect> mEffects; |
79 | 74 |
|
80 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
282 | 277 |
final View view = getLayoutInflater().inflate(R.layout.fragment3dlayout, null); |
283 | 278 |
|
284 | 279 |
setContentView(view); |
285 |
|
|
286 |
centerX = 50; |
|
287 |
centerY = 50; |
|
288 |
|
|
289 |
textCenter = (TextView)view.findViewById(R.id.fragment3dcenterText); |
|
290 |
computeCenter(); |
|
291 |
setCenterText(); |
|
292 |
|
|
293 |
SeekBar bar; |
|
294 |
|
|
295 |
bar = (SeekBar)view.findViewById(R.id.fragment3dcenterX); |
|
296 |
bar.setOnSeekBarChangeListener(this); |
|
297 |
bar.setProgress(centerX); |
|
298 |
|
|
299 |
bar = (SeekBar)view.findViewById(R.id.fragment3dcenterY); |
|
300 |
bar.setOnSeekBarChangeListener(this); |
|
301 |
bar.setProgress(centerY); |
|
302 | 280 |
} |
303 | 281 |
|
304 | 282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
308 | 286 |
Fragment3DEffect chroma = new Fragment3DEffect(EffectNames.CHROMA); |
309 | 287 |
mEffects.add(chroma); |
310 | 288 |
|
311 |
View view = chroma.createView(this); |
|
312 | 289 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
290 |
View view = chroma.createView(this); |
|
313 | 291 |
layout.addView(view); |
292 |
View region = chroma.createRegion(this); |
|
293 |
layout.addView(region); |
|
314 | 294 |
|
315 | 295 |
Dynamic1D dyn1 = chroma.getDyn1(); |
316 | 296 |
Dynamic3D dyn3 = chroma.getDyn3(); |
297 |
Dynamic4D regi = chroma.getRegion(); |
|
317 | 298 |
|
318 |
mObject.chroma(dyn1,dyn3);
|
|
299 |
mObject.chroma(dyn1, dyn3, regi, false);
|
|
319 | 300 |
} |
320 | 301 |
|
321 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
325 | 306 |
Fragment3DEffect alpha = new Fragment3DEffect(EffectNames.ALPHA); |
326 | 307 |
mEffects.add(alpha); |
327 | 308 |
|
328 |
View view = alpha.createView(this); |
|
329 | 309 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
310 |
View view = alpha.createView(this); |
|
330 | 311 |
layout.addView(view); |
312 |
View region = alpha.createRegion(this); |
|
313 |
layout.addView(region); |
|
331 | 314 |
|
332 | 315 |
Dynamic1D dyn1 = alpha.getDyn1(); |
316 |
Dynamic4D regi = alpha.getRegion(); |
|
333 | 317 |
|
334 |
mObject.alpha(dyn1); |
|
318 |
mObject.alpha(dyn1, regi, false);
|
|
335 | 319 |
} |
336 | 320 |
|
337 | 321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
341 | 325 |
Fragment3DEffect brightness = new Fragment3DEffect(EffectNames.BRIGHTNESS); |
342 | 326 |
mEffects.add(brightness); |
343 | 327 |
|
344 |
View view = brightness.createView(this); |
|
345 | 328 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
329 |
View view = brightness.createView(this); |
|
346 | 330 |
layout.addView(view); |
331 |
View region = brightness.createRegion(this); |
|
332 |
layout.addView(region); |
|
347 | 333 |
|
348 | 334 |
Dynamic1D dyn1 = brightness.getDyn1(); |
335 |
Dynamic4D regi = brightness.getRegion(); |
|
349 | 336 |
|
350 |
mObject.brightness(dyn1); |
|
337 |
mObject.brightness(dyn1, regi, false);
|
|
351 | 338 |
} |
352 | 339 |
|
353 | 340 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
357 | 344 |
Fragment3DEffect saturation = new Fragment3DEffect(EffectNames.SATURATION); |
358 | 345 |
mEffects.add(saturation); |
359 | 346 |
|
360 |
View view = saturation.createView(this); |
|
361 | 347 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
348 |
View view = saturation.createView(this); |
|
362 | 349 |
layout.addView(view); |
350 |
View region = saturation.createRegion(this); |
|
351 |
layout.addView(region); |
|
363 | 352 |
|
364 | 353 |
Dynamic1D dyn1 = saturation.getDyn1(); |
354 |
Dynamic4D regi = saturation.getRegion(); |
|
365 | 355 |
|
366 |
mObject.saturation(dyn1); |
|
356 |
mObject.saturation(dyn1, regi, false);
|
|
367 | 357 |
} |
368 | 358 |
|
369 | 359 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
376 | 366 |
mObject.abortEffects(EffectTypes.FRAGMENT); |
377 | 367 |
} |
378 | 368 |
|
379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
380 |
|
|
381 |
private void computeCenter() |
|
382 |
{ |
|
383 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
384 |
|
|
385 |
fcenterX = centerX; |
|
386 |
fcenterY = centerY; |
|
387 |
|
|
388 |
view.getRenderer().setCenter( fcenterX, fcenterY ); |
|
389 |
} |
|
390 |
|
|
391 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
392 |
|
|
393 |
private void setCenterText() |
|
394 |
{ |
|
395 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
396 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
397 |
|
|
398 |
textCenter.setText("center("+fcenterX+","+fcenterY+")"); |
|
399 |
} |
|
400 |
|
|
401 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
402 |
|
|
403 |
public float getCenterX() |
|
404 |
{ |
|
405 |
return fcenterX; |
|
406 |
} |
|
407 |
|
|
408 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
409 |
|
|
410 |
public float getCenterY() |
|
411 |
{ |
|
412 |
return fcenterY; |
|
413 |
} |
|
414 |
|
|
415 | 369 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
416 | 370 |
// Overrides |
417 | 371 |
|
... | ... | |
455 | 409 |
Distorted.onDestroy(); |
456 | 410 |
super.onDestroy(); |
457 | 411 |
} |
458 |
|
|
459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 |
|
|
461 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
462 |
{ |
|
463 |
switch (bar.getId()) |
|
464 |
{ |
|
465 |
case R.id.fragment3dcenterX: centerX = progress; computeCenter() ; setCenterText() ; break; |
|
466 |
case R.id.fragment3dcenterY: centerY = progress; computeCenter() ; setCenterText() ; break; |
|
467 |
} |
|
468 |
} |
|
469 |
|
|
470 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
471 |
|
|
472 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
473 |
|
|
474 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
475 | 412 |
|
476 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
477 | 413 |
} |
src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.EffectNames; |
30 | 30 |
import org.distorted.library.type.Dynamic1D; |
31 | 31 |
import org.distorted.library.type.Dynamic3D; |
32 |
import org.distorted.library.type.Dynamic4D; |
|
32 | 33 |
import org.distorted.library.type.Static1D; |
33 | 34 |
import org.distorted.library.type.Static3D; |
35 |
import org.distorted.library.type.Static4D; |
|
34 | 36 |
|
35 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 38 |
|
... | ... | |
38 | 40 |
{ |
39 | 41 |
private EffectNames mName; |
40 | 42 |
private int[] mInter; |
41 |
private SeekBar[] mSeek; |
|
43 |
private int[] mInterRegion; |
|
44 |
private int[] mSeekID; |
|
45 |
private int[] mSeekRegionID; |
|
42 | 46 |
private int mDimension; |
43 | 47 |
private TextView mText; |
48 |
private TextView mTextRegion; |
|
44 | 49 |
|
45 | 50 |
private Dynamic1D mDyn1; |
46 | 51 |
private Dynamic3D mDyn3; |
47 | 52 |
private Static1D mSta1; |
48 | 53 |
private Static3D mSta3; |
54 |
private Dynamic4D mRegionDyn; |
|
55 |
private Static4D mRegionSta; |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
private void fillRegionStatics() |
|
60 |
{ |
|
61 |
float factorX = 2.0f; |
|
62 |
float factorY = 2.0f; |
|
63 |
|
|
64 |
float x = (mInterRegion[0]-50)*factorX; |
|
65 |
float y = (mInterRegion[1]-50)*factorY; |
|
66 |
float rx = (mInterRegion[2] )*factorX; |
|
67 |
float ry = (mInterRegion[3] )*factorY; |
|
68 |
|
|
69 |
mRegionSta.set(x,y,rx,ry); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
private void setDefaultRegionInter() |
|
75 |
{ |
|
76 |
mInterRegion[0] = 50; |
|
77 |
mInterRegion[1] = 50; |
|
78 |
mInterRegion[2] = 50; |
|
79 |
mInterRegion[3] = 50; |
|
80 |
} |
|
81 |
|
|
82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 |
|
|
84 |
private void setRegionText() |
|
85 |
{ |
|
86 |
mTextRegion.setText("region ("+mRegionSta.getX()+","+mRegionSta.getY()+","+mRegionSta.getZ()+","+mRegionSta.getW()+")"); |
|
87 |
} |
|
49 | 88 |
|
50 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 90 |
|
... | ... | |
131 | 170 |
} |
132 | 171 |
|
133 | 172 |
mInter = new int[mDimension]; |
134 |
mSeek = new SeekBar[mDimension];
|
|
173 |
mSeekID= new int[mDimension];
|
|
135 | 174 |
|
136 | 175 |
mDyn1 = new Dynamic1D(); |
137 | 176 |
mSta1 = new Static1D(0); |
138 | 177 |
mDyn1.add(mSta1); |
178 |
|
|
179 |
mInterRegion = new int[4]; |
|
180 |
mSeekRegionID= new int[4]; |
|
181 |
mRegionDyn = new Dynamic4D(); |
|
182 |
mRegionSta = new Static4D(0,0,0,0); |
|
183 |
mRegionDyn.add(mRegionSta); |
|
139 | 184 |
} |
140 | 185 |
|
141 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
152 | 197 |
return mDyn3; |
153 | 198 |
} |
154 | 199 |
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public Dynamic4D getRegion() |
|
203 |
{ |
|
204 |
return mRegionDyn; |
|
205 |
} |
|
206 |
|
|
155 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 208 |
|
157 | 209 |
public View createView(Activity act) |
158 | 210 |
{ |
159 | 211 |
View effect; |
212 |
SeekBar[] seek = new SeekBar[mDimension]; |
|
160 | 213 |
|
161 | 214 |
switch(mDimension) |
162 | 215 |
{ |
163 |
case 1 : effect = act.getLayoutInflater().inflate(R.layout.effect1d, null); |
|
164 |
mText = (TextView)effect.findViewById(R.id.effect1dText); |
|
165 |
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1); |
|
216 |
case 1 : effect = act.getLayoutInflater().inflate(R.layout.effect1d, null); |
|
217 |
mText = (TextView)effect.findViewById(R.id.effect1dText); |
|
218 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1); |
|
219 |
mSeekID[0] = seek[0].getId(); |
|
166 | 220 |
break; |
167 |
case 2 : effect = act.getLayoutInflater().inflate(R.layout.effect2d, null); |
|
168 |
mText = (TextView)effect.findViewById(R.id.effect2dText); |
|
169 |
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1); |
|
170 |
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2); |
|
221 |
case 2 : effect = act.getLayoutInflater().inflate(R.layout.effect2d, null); |
|
222 |
mText = (TextView)effect.findViewById(R.id.effect2dText); |
|
223 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1); |
|
224 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2); |
|
225 |
mSeekID[0] = seek[0].getId(); |
|
226 |
mSeekID[1] = seek[1].getId(); |
|
171 | 227 |
break; |
172 |
case 3 : effect = act.getLayoutInflater().inflate(R.layout.effect3d, null); |
|
173 |
mText = (TextView)effect.findViewById(R.id.effect3dText); |
|
174 |
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1); |
|
175 |
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2); |
|
176 |
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3); |
|
228 |
case 3 : effect = act.getLayoutInflater().inflate(R.layout.effect3d, null); |
|
229 |
mText = (TextView)effect.findViewById(R.id.effect3dText); |
|
230 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1); |
|
231 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2); |
|
232 |
seek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3); |
|
233 |
mSeekID[0] = seek[0].getId(); |
|
234 |
mSeekID[1] = seek[1].getId(); |
|
235 |
mSeekID[2] = seek[2].getId(); |
|
177 | 236 |
break; |
178 |
case 4 : effect = act.getLayoutInflater().inflate(R.layout.effect4d, null); |
|
179 |
mText = (TextView)effect.findViewById(R.id.effect4dText); |
|
180 |
mSeek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1); |
|
181 |
mSeek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2); |
|
182 |
mSeek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3); |
|
183 |
mSeek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar3); |
|
237 |
case 4 : effect = act.getLayoutInflater().inflate(R.layout.effect4d, null); |
|
238 |
mText = (TextView)effect.findViewById(R.id.effect4dText); |
|
239 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1); |
|
240 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2); |
|
241 |
seek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3); |
|
242 |
seek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar4); |
|
243 |
mSeekID[0] = seek[0].getId(); |
|
244 |
mSeekID[1] = seek[1].getId(); |
|
245 |
mSeekID[2] = seek[2].getId(); |
|
246 |
mSeekID[3] = seek[3].getId(); |
|
184 | 247 |
break; |
185 | 248 |
default: android.util.Log.e("Fragment3DEffect", "dimension "+mDimension+" not supported!"); |
186 | 249 |
return null; |
... | ... | |
192 | 255 |
|
193 | 256 |
for(int i=0; i<mDimension; i++) |
194 | 257 |
{ |
195 |
mSeek[i].setOnSeekBarChangeListener(this);
|
|
196 |
mSeek[i].setProgress( mInter[i] );
|
|
258 |
seek[i].setOnSeekBarChangeListener(this);
|
|
259 |
seek[i].setProgress( mInter[i] );
|
|
197 | 260 |
} |
198 | 261 |
|
199 | 262 |
return effect; |
200 | 263 |
} |
201 | 264 |
|
265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
266 |
|
|
267 |
public View createRegion(Activity act) |
|
268 |
{ |
|
269 |
View region = act.getLayoutInflater().inflate(R.layout.effectregion, null); |
|
270 |
|
|
271 |
SeekBar[] seek = new SeekBar[4]; |
|
272 |
|
|
273 |
seek[0] = (SeekBar)region.findViewById(R.id.effectRegionBarX ); |
|
274 |
seek[1] = (SeekBar)region.findViewById(R.id.effectRegionBarY ); |
|
275 |
seek[2] = (SeekBar)region.findViewById(R.id.effectRegionBarRX); |
|
276 |
seek[3] = (SeekBar)region.findViewById(R.id.effectRegionBarRY); |
|
277 |
|
|
278 |
mSeekRegionID[0] = seek[0].getId(); |
|
279 |
mSeekRegionID[1] = seek[1].getId(); |
|
280 |
mSeekRegionID[2] = seek[2].getId(); |
|
281 |
mSeekRegionID[3] = seek[3].getId(); |
|
282 |
|
|
283 |
mTextRegion = (TextView)region.findViewById(R.id.effectRegionText); |
|
284 |
|
|
285 |
setDefaultRegionInter(); |
|
286 |
fillRegionStatics(); |
|
287 |
setRegionText(); |
|
288 |
|
|
289 |
for(int i=0; i<4; i++) |
|
290 |
{ |
|
291 |
seek[i].setOnSeekBarChangeListener(this); |
|
292 |
seek[i].setProgress( mInterRegion[i] ); |
|
293 |
} |
|
294 |
|
|
295 |
return region; |
|
296 |
} |
|
297 |
|
|
202 | 298 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
203 | 299 |
|
204 | 300 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
205 | 301 |
{ |
206 |
if ( mDimension>=1 && bar.getId()==mSeek[0].getId() ) mInter[0] = progress; |
|
207 |
if ( mDimension>=2 && bar.getId()==mSeek[1].getId() ) mInter[1] = progress; |
|
208 |
if ( mDimension>=3 && bar.getId()==mSeek[2].getId() ) mInter[2] = progress; |
|
209 |
if ( mDimension>=4 && bar.getId()==mSeek[3].getId() ) mInter[3] = progress; |
|
302 |
if ( mDimension>=1 && bar.getId()==mSeekID[0] ) |
|
303 |
{ |
|
304 |
mInter[0] = progress; |
|
305 |
fillStatics(); |
|
306 |
setText(); |
|
307 |
} |
|
308 |
if ( mDimension>=2 && bar.getId()==mSeekID[1] ) |
|
309 |
{ |
|
310 |
mInter[1] = progress; |
|
311 |
fillStatics(); |
|
312 |
setText(); |
|
313 |
} |
|
314 |
if ( mDimension>=3 && bar.getId()==mSeekID[2] ) |
|
315 |
{ |
|
316 |
mInter[2] = progress; |
|
317 |
fillStatics(); |
|
318 |
setText(); |
|
319 |
} |
|
320 |
if ( mDimension>=4 && bar.getId()==mSeekID[3] ) |
|
321 |
{ |
|
322 |
mInter[3] = progress; |
|
323 |
fillStatics(); |
|
324 |
setText(); |
|
325 |
} |
|
326 |
|
|
327 |
if( bar.getId() == mSeekRegionID[0] ) |
|
328 |
{ |
|
329 |
mInterRegion[0] = progress; |
|
330 |
fillRegionStatics(); |
|
331 |
setRegionText(); |
|
332 |
} |
|
333 |
if( bar.getId() == mSeekRegionID[1] ) |
|
334 |
{ |
|
335 |
mInterRegion[1] = progress; |
|
336 |
fillRegionStatics(); |
|
337 |
setRegionText(); |
|
338 |
} |
|
339 |
if( bar.getId() == mSeekRegionID[2] ) |
|
340 |
{ |
|
341 |
mInterRegion[2] = progress; |
|
342 |
fillRegionStatics(); |
|
343 |
setRegionText(); |
|
344 |
} |
|
345 |
if( bar.getId() == mSeekRegionID[3] ) |
|
346 |
{ |
|
347 |
mInterRegion[3] = progress; |
|
348 |
fillRegionStatics(); |
|
349 |
setRegionText(); |
|
350 |
} |
|
210 | 351 |
|
211 |
fillStatics(); |
|
212 |
setText(); |
|
213 | 352 |
} |
214 | 353 |
|
215 | 354 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/examples/fragment3d/Fragment3DRenderer.java | ||
---|---|---|
54 | 54 |
|
55 | 55 |
private GLSurfaceView mView; |
56 | 56 |
private DistortedObject mObject; |
57 |
private DistortedBitmap mCenter; |
|
58 | 57 |
private DistortedBitmap mBackground; |
59 |
private float mFactorCen, mFactorObj;
|
|
58 |
private float mFactorObj; |
|
60 | 59 |
|
61 | 60 |
private int mObjWidth, mObjHeight; |
62 | 61 |
|
63 | 62 |
private DynamicQuat mQuatInt1, mQuatInt2; |
64 | 63 |
|
65 |
private Dynamic3D mMoveInter; |
|
66 |
private Static3D mMovePoint; |
|
67 |
|
|
68 | 64 |
Static4D mQuat1, mQuat2; |
69 | 65 |
int mScreenMin; |
70 | 66 |
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
public void setCenter(float x, float y) |
|
74 |
{ |
|
75 |
x = (0.012f*x-0.1f)*mObjWidth; |
|
76 |
y = (0.012f*y-0.1f)*mObjHeight; |
|
77 |
|
|
78 |
mMovePoint.set(mFactorObj*x,mFactorObj*y,0); |
|
79 |
} |
|
80 |
|
|
81 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 68 |
|
83 | 69 |
public Fragment3DRenderer(GLSurfaceView v) |
... | ... | |
85 | 71 |
mView = v; |
86 | 72 |
|
87 | 73 |
mObject = ((Fragment3DActivity)v.getContext()).getObject(); |
88 |
mCenter = new DistortedBitmap(SIZE, SIZE, 1); |
|
89 | 74 |
mBackground = new DistortedBitmap(SIZE, SIZE, 1); |
90 | 75 |
|
91 | 76 |
mObjWidth = mObject.getWidth(); |
92 | 77 |
mObjHeight= mObject.getHeight(); |
93 | 78 |
|
94 |
mMovePoint= new Static3D(0,0,0); |
|
95 |
mMoveInter= new Dynamic3D(); |
|
96 |
mMoveInter.add(mMovePoint); |
|
97 |
|
|
98 | 79 |
mQuat1 = new Static4D(0,0,0,1); // unity |
99 | 80 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
100 | 81 |
|
... | ... | |
116 | 97 |
|
117 | 98 |
mBackground.draw(time); |
118 | 99 |
mObject.draw(time); |
119 |
mCenter.draw(time); |
|
120 | 100 |
} |
121 | 101 |
|
122 | 102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
126 | 106 |
mScreenMin = width<height ? width:height; |
127 | 107 |
|
128 | 108 |
mObject.abortEffects(EffectTypes.MATRIX); |
129 |
mCenter.abortEffects(EffectTypes.MATRIX); |
|
130 | 109 |
mBackground.abortEffects(EffectTypes.MATRIX); |
131 | 110 |
|
132 |
int centerSize = mCenter.getWidth(); |
|
133 |
|
|
134 | 111 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
135 | 112 |
{ |
136 | 113 |
mFactorObj = (0.70f*height)/mObjHeight; |
137 |
mFactorCen = (0.15f*height)/centerSize; |
|
138 | 114 |
} |
139 | 115 |
else |
140 | 116 |
{ |
141 | 117 |
mFactorObj = (0.70f*width)/mObjWidth; |
142 |
mFactorCen = (0.15f*width)/centerSize; |
|
143 | 118 |
} |
144 | 119 |
|
145 |
Fragment3DActivity act = (Fragment3DActivity)mView.getContext(); |
|
146 |
float cX = act.getCenterX(); |
|
147 |
float cY = act.getCenterY(); |
|
148 |
|
|
149 |
cX = (0.012f*cX-0.1f)*mObjWidth; |
|
150 |
cY = (0.012f*cY-0.1f)*mObjHeight; |
|
151 |
|
|
152 |
mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0); |
|
153 |
|
|
154 | 120 |
Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
155 | 121 |
|
156 | 122 |
mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) ); |
... | ... | |
158 | 124 |
mObject.quaternion(mQuatInt1, rotateObj); |
159 | 125 |
mObject.quaternion(mQuatInt2, rotateObj); |
160 | 126 |
|
161 |
Static3D rotateCen = new Static3D(width/2,height/2, 0); |
|
162 |
|
|
163 |
mCenter.quaternion(mQuatInt1, rotateCen); |
|
164 |
mCenter.quaternion(mQuatInt2, rotateCen); |
|
165 |
mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 , |
|
166 |
(height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) ); |
|
167 |
mCenter.move(mMoveInter); |
|
168 |
mCenter.scale(mFactorCen); |
|
169 |
|
|
170 | 127 |
int backgroundSize = mBackground.getWidth(); |
171 | 128 |
float factorBackX = ((float)width)/backgroundSize; |
172 | 129 |
float factorBackY = ((float)height)/backgroundSize; |
... | ... | |
184 | 141 |
Fragment3DActivity act = (Fragment3DActivity)mView.getContext(); |
185 | 142 |
|
186 | 143 |
InputStream is1 = act.getResources().openRawResource(act.getBitmap()); |
187 |
InputStream is2 = act.getResources().openRawResource(R.raw.center); |
|
188 |
InputStream is3 = act.getResources().openRawResource(R.raw.water); |
|
144 |
InputStream is2 = act.getResources().openRawResource(R.raw.water); |
|
189 | 145 |
|
190 |
Bitmap bitmap1,bitmap2,bitmap3;
|
|
146 |
Bitmap bitmap1,bitmap2; |
|
191 | 147 |
|
192 | 148 |
try |
193 | 149 |
{ |
194 | 150 |
bitmap1 = BitmapFactory.decodeStream(is1); |
195 | 151 |
bitmap2 = BitmapFactory.decodeStream(is2); |
196 |
bitmap3 = BitmapFactory.decodeStream(is3); |
|
197 | 152 |
} |
198 | 153 |
finally |
199 | 154 |
{ |
... | ... | |
201 | 156 |
{ |
202 | 157 |
is1.close(); |
203 | 158 |
is2.close(); |
204 |
is3.close(); |
|
205 | 159 |
} |
206 | 160 |
catch(IOException e) { } |
207 | 161 |
} |
208 | 162 |
|
209 | 163 |
mObject.setBitmap(bitmap1); |
210 |
mCenter.setBitmap(bitmap2); |
|
211 |
mBackground.setBitmap(bitmap3) |
|
164 |
mBackground.setBitmap(bitmap2) |
|
212 | 165 |
; |
213 | 166 |
try |
214 | 167 |
{ |
src/main/res/layout/effect1d.xml | ||
---|---|---|
24 | 24 |
|
25 | 25 |
|
26 | 26 |
<View |
27 |
android:layout_height="3dip"
|
|
27 |
android:layout_height="1dip"
|
|
28 | 28 |
android:background="#777777" |
29 | 29 |
android:layout_width="match_parent" |
30 | 30 |
/> |
src/main/res/layout/effect2d.xml | ||
---|---|---|
31 | 31 |
android:layout_marginRight="5dp" /> |
32 | 32 |
|
33 | 33 |
<View |
34 |
android:layout_height="3dip"
|
|
34 |
android:layout_height="1dip"
|
|
35 | 35 |
android:background="#777777" |
36 | 36 |
android:layout_width="match_parent" |
37 | 37 |
/> |
src/main/res/layout/effect3d.xml | ||
---|---|---|
38 | 38 |
android:layout_marginRight="5dp" /> |
39 | 39 |
|
40 | 40 |
<View |
41 |
android:layout_height="3dip"
|
|
41 |
android:layout_height="1dip"
|
|
42 | 42 |
android:background="#777777" |
43 | 43 |
android:layout_width="match_parent" |
44 | 44 |
/> |
src/main/res/layout/effect4d.xml | ||
---|---|---|
46 | 46 |
android:layout_marginRight="5dp" /> |
47 | 47 |
|
48 | 48 |
<View |
49 |
android:layout_height="3dip"
|
|
49 |
android:layout_height="1dip"
|
|
50 | 50 |
android:background="#777777" |
51 | 51 |
android:layout_width="match_parent" |
52 | 52 |
/> |
src/main/res/layout/effectregion.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:id="@+id/effectRegionLayout" |
|
4 |
android:layout_width="match_parent" |
|
5 |
android:layout_height="wrap_content" |
|
6 |
android:orientation="vertical"> |
|
7 |
|
|
8 |
<TextView |
|
9 |
android:id="@+id/effectRegionText" |
|
10 |
android:layout_width="wrap_content" |
|
11 |
android:layout_height="wrap_content" |
|
12 |
android:layout_marginEnd="5dp" |
|
13 |
android:layout_marginStart="5dp" |
|
14 |
android:layout_marginTop="3dp" |
|
15 |
/> |
|
16 |
|
|
17 |
<LinearLayout |
|
18 |
android:orientation="horizontal" |
|
19 |
android:layout_width="match_parent" |
|
20 |
android:layout_height="match_parent"> |
|
21 |
|
|
22 |
<SeekBar |
|
23 |
android:id="@+id/effectRegionBarX" |
|
24 |
android:layout_width="wrap_content" |
|
25 |
android:layout_height="wrap_content" |
|
26 |
android:layout_marginEnd="5dp" |
|
27 |
android:layout_marginLeft="5dp" |
|
28 |
android:layout_marginRight="5dp" |
|
29 |
android:layout_weight="0.5"/> |
|
30 |
|
|
31 |
<SeekBar |
|
32 |
android:id="@+id/effectRegionBarY" |
|
33 |
android:layout_width="wrap_content" |
|
34 |
android:layout_height="wrap_content" |
|
35 |
android:layout_marginEnd="5dp" |
|
36 |
android:layout_marginLeft="5dp" |
|
37 |
android:layout_marginRight="5dp" |
|
38 |
android:layout_weight="0.5"/> |
|
39 |
|
|
40 |
</LinearLayout> |
|
41 |
|
|
42 |
<LinearLayout |
|
43 |
android:orientation="horizontal" |
|
44 |
android:layout_width="match_parent" |
|
45 |
android:layout_height="match_parent"> |
|
46 |
|
|
47 |
<SeekBar |
|
48 |
android:id="@+id/effectRegionBarRX" |
|
49 |
android:layout_width="wrap_content" |
|
50 |
android:layout_height="wrap_content" |
|
51 |
android:layout_marginEnd="5dp" |
|
52 |
android:layout_marginLeft="5dp" |
|
53 |
android:layout_marginRight="5dp" |
|
54 |
android:layout_weight="0.5"/> |
|
55 |
|
|
56 |
<SeekBar |
|
57 |
android:id="@+id/effectRegionBarRY" |
|
58 |
android:layout_width="wrap_content" |
|
59 |
android:layout_height="wrap_content" |
|
60 |
android:layout_marginEnd="5dp" |
|
61 |
android:layout_marginLeft="5dp" |
|
62 |
android:layout_marginRight="5dp" |
|
63 |
android:layout_weight="0.5"/> |
|
64 |
|
|
65 |
</LinearLayout> |
|
66 |
|
|
67 |
|
|
68 |
<View |
|
69 |
android:layout_height="3dip" |
|
70 |
android:background="#777777" |
|
71 |
android:layout_width="match_parent" |
|
72 |
/> |
|
73 |
|
|
74 |
</LinearLayout> |
src/main/res/layout/fragment3dlayout.xml | ||
---|---|---|
53 | 53 |
android:onClick="newSaturation"/> |
54 | 54 |
</LinearLayout> |
55 | 55 |
|
56 |
<LinearLayout |
|
57 |
android:orientation="vertical" |
|
58 |
android:layout_width="fill_parent" |
|
59 |
android:layout_height="50dp" |
|
60 |
> |
|
61 |
|
|
62 |
<TextView |
|
63 |
android:id="@+id/fragment3dcenterText" |
|
64 |
android:layout_width="wrap_content" |
|
65 |
android:layout_height="wrap_content" |
|
66 |
android:layout_marginEnd="5dp" |
|
67 |
android:layout_marginStart="5dp" |
|
68 |
android:layout_marginTop="3dp" |
|
69 |
/> |
|
70 |
|
|
71 |
<LinearLayout |
|
72 |
android:orientation="horizontal" |
|
73 |
android:layout_width="match_parent" |
|
74 |
android:layout_height="match_parent" |
|
75 |
> |
|
76 |
|
|
77 |
<SeekBar |
|
78 |
android:layout_width="fill_parent" |
|
79 |
android:layout_height="wrap_content" |
|
80 |
android:id="@+id/fragment3dcenterX" |
|
81 |
android:layout_weight="0.5" |
|
82 |
android:paddingLeft="5dp" |
|
83 |
android:paddingRight="3dp"/> |
|
84 |
|
|
85 |
<SeekBar |
|
86 |
android:layout_width="fill_parent" |
|
87 |
android:layout_height="wrap_content" |
|
88 |
android:id="@+id/fragment3dcenterY" |
|
89 |
android:layout_weight="0.5" |
|
90 |
android:paddingLeft="3dp" |
|
91 |
android:paddingRight="5dp"/> |
|
92 |
</LinearLayout> |
|
93 |
|
|
94 |
</LinearLayout> |
|
95 |
|
|
96 | 56 |
<View |
97 | 57 |
android:layout_height="4dip" |
98 | 58 |
android:background="#777777" |
Also available in: Unified diff
Fragment3D close to done now!