Revision 794e6c4f
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java | ||
|---|---|---|
| 57 | 57 |
// fields needed for the second 'apply vertex effects' screen |
| 58 | 58 |
// |
| 59 | 59 |
private SeekBar bar; |
| 60 |
private TextView textDeform, textDistort, textSink, textSwirl; |
|
| 60 |
private TextView textDeform, textDistort, textSink, textSwirl, textCenter;
|
|
| 61 | 61 |
private int deformX, deformY, deformZ; |
| 62 | 62 |
private int distortX, distortY, distortZ; |
| 63 | 63 |
private int sinkA; |
| 64 | 64 |
private int swirlA; |
| 65 |
private int centerX, centerY; |
|
| 65 | 66 |
|
| 66 | 67 |
private float fdeformX, fdeformY, fdeformZ; |
| 67 | 68 |
private float fdistortX, fdistortY, fdistortZ; |
| 68 | 69 |
private float fsinkA; |
| 69 | 70 |
private float fswirlA; |
| 70 |
|
|
| 71 |
private float fcenterX, fcenterY; |
|
| 72 |
|
|
| 71 | 73 |
private EffectNames[] effects = new EffectNames[4]; |
| 72 | 74 |
|
| 73 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 219 | 221 |
sinkA = 50; |
| 220 | 222 |
swirlA = 50; |
| 221 | 223 |
|
| 224 |
centerX = 25; |
|
| 225 |
centerY = 25; |
|
| 226 |
|
|
| 227 |
textCenter = (TextView)findViewById(R.id.vertex3dcenterText); |
|
| 228 |
setCenterText(); |
|
| 229 |
|
|
| 230 |
setBar(R.id.vertex3dcenterX, centerX); |
|
| 231 |
setBar(R.id.vertex3dcenterY, centerY); |
|
| 232 |
|
|
| 222 | 233 |
addViews(); |
| 223 | 234 |
} |
| 224 | 235 |
|
| ... | ... | |
| 419 | 430 |
|
| 420 | 431 |
textSwirl.setText("swirl("+fswirlA+")");
|
| 421 | 432 |
} |
| 422 |
|
|
| 433 |
|
|
| 434 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 435 |
|
|
| 436 |
private void computeCenter() |
|
| 437 |
{
|
|
| 438 |
fcenterX = (centerX*0.02f - 0.5f)*Vertex3DRenderer.SIZE; |
|
| 439 |
fcenterY = (centerY*0.02f - 0.5f)*Vertex3DRenderer.SIZE; |
|
| 440 |
|
|
| 441 |
Vertex3DRenderer.setCenter( fcenterX, fcenterY ); |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 445 |
|
|
| 446 |
private void setCenterText() |
|
| 447 |
{
|
|
| 448 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
| 449 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
| 450 |
|
|
| 451 |
textCenter.setText("center("+fcenterX+","+fcenterY+")");
|
|
| 452 |
} |
|
| 453 |
|
|
| 423 | 454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 424 | 455 |
// Overrides |
| 425 | 456 |
|
| ... | ... | |
| 472 | 503 |
{
|
| 473 | 504 |
switch (bar.getId()) |
| 474 | 505 |
{
|
| 506 |
case R.id.vertex3dcenterX : centerX = progress; computeCenter() ; setCenterText() ; break; |
|
| 507 |
case R.id.vertex3dcenterY : centerY = progress; computeCenter() ; setCenterText() ; break; |
|
| 475 | 508 |
case R.id.vertex3ddeformBar1 : deformX = progress; computeDeform() ; setDeformText() ; break; |
| 476 | 509 |
case R.id.vertex3ddeformBar2 : deformY = progress; computeDeform() ; setDeformText() ; break; |
| 477 | 510 |
case R.id.vertex3ddeformBar3 : deformZ = progress; computeDeform() ; setDeformText() ; break; |
| src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
|---|---|---|
| 26 | 26 |
|
| 27 | 27 |
import org.distorted.examples.R; |
| 28 | 28 |
import org.distorted.library.Distorted; |
| 29 |
import org.distorted.library.DistortedBitmap; |
|
| 29 | 30 |
import org.distorted.library.DistortedCubes; |
| 30 | 31 |
import org.distorted.library.DistortedObject; |
| 31 | 32 |
import org.distorted.library.EffectNames; |
| 32 | 33 |
import org.distorted.library.EffectTypes; |
| 33 | 34 |
import org.distorted.library.type.Dynamic1D; |
| 35 |
import org.distorted.library.type.Dynamic2D; |
|
| 34 | 36 |
import org.distorted.library.type.Dynamic3D; |
| 35 | 37 |
import org.distorted.library.type.DynamicQuat; |
| 36 | 38 |
import org.distorted.library.type.Static1D; |
| ... | ... | |
| 48 | 50 |
|
| 49 | 51 |
class Vertex3DRenderer implements GLSurfaceView.Renderer |
| 50 | 52 |
{
|
| 53 |
public static final int SIZE = 100; |
|
| 54 |
|
|
| 51 | 55 |
private GLSurfaceView mView; |
| 52 | 56 |
private static DistortedObject mObject; |
| 53 | 57 |
|
| ... | ... | |
| 56 | 60 |
private DynamicQuat mQuatInt1, mQuatInt2; |
| 57 | 61 |
|
| 58 | 62 |
private static EffectNames[] order; |
| 59 |
|
|
| 63 |
|
|
| 64 |
private static Dynamic2D mCenterInter; |
|
| 60 | 65 |
private static Dynamic3D mDeformInter, mDistortInter; |
| 61 | 66 |
private static Dynamic1D mSinkInter, mSwirlInter; |
| 62 | 67 |
|
| ... | ... | |
| 95 | 100 |
mSwirlPoint.set(s); |
| 96 | 101 |
} |
| 97 | 102 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
public static void setCenter(float x, float y) |
|
| 106 |
{
|
|
| 107 |
mCenterPoint.set(x,y); |
|
| 108 |
} |
|
| 109 |
|
|
| 98 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 99 | 111 |
|
| 100 | 112 |
public static void setOrder(EffectNames[] effects) |
| ... | ... | |
| 108 | 120 |
public static void setVertexEffects() |
| 109 | 121 |
{
|
| 110 | 122 |
mObject.abortEffects(EffectTypes.VERTEX); |
| 111 |
|
|
| 123 |
|
|
| 112 | 124 |
for( int i=0; i<=order.length-1 ; i++ ) |
| 113 | 125 |
{
|
| 114 | 126 |
switch(order[i]) |
| 115 | 127 |
{
|
| 116 |
case DEFORM : mObject.deform( mDeformInter , mCenterPoint) ; break;
|
|
| 117 |
case DISTORT: mObject.distort(mDistortInter, mCenterPoint) ; break;
|
|
| 118 |
case SINK : mObject.sink( mSinkInter , mCenterPoint) ; break;
|
|
| 119 |
case SWIRL : mObject.swirl( mSwirlInter , mCenterPoint) ; break;
|
|
| 128 |
case DEFORM : mObject.deform( mDeformInter , mCenterInter) ; break;
|
|
| 129 |
case DISTORT: mObject.distort(mDistortInter, mCenterInter) ; break;
|
|
| 130 |
case SINK : mObject.sink( mSinkInter , mCenterInter) ; break;
|
|
| 131 |
case SWIRL : mObject.swirl( mSwirlInter , mCenterInter) ; break;
|
|
| 120 | 132 |
} |
| 121 | 133 |
} |
| 122 | 134 |
} |
| ... | ... | |
| 127 | 139 |
{
|
| 128 | 140 |
mView = v; |
| 129 | 141 |
|
| 130 |
mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), 100);
|
|
| 131 |
//mObject = new DistortedBitmap( 100, 100, 10);
|
|
| 142 |
mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), SIZE);
|
|
| 143 |
//mObject = new DistortedBitmap( SIZE, SIZE, 10);
|
|
| 132 | 144 |
|
| 133 | 145 |
mObjWidth = mObject.getWidth(); |
| 134 | 146 |
mObjHeight= mObject.getHeight(); |
| ... | ... | |
| 139 | 151 |
mSwirlPoint = new Static1D(0); |
| 140 | 152 |
mSinkPoint = new Static1D(1); |
| 141 | 153 |
|
| 154 |
mCenterInter = new Dynamic2D(); |
|
| 142 | 155 |
mDeformInter = new Dynamic3D(); |
| 143 | 156 |
mDistortInter = new Dynamic3D(); |
| 144 | 157 |
mSwirlInter = new Dynamic1D(); |
| 145 | 158 |
mSinkInter = new Dynamic1D(); |
| 146 | 159 |
|
| 160 |
mCenterInter.add(mCenterPoint); |
|
| 147 | 161 |
mDeformInter.add(mDeformPoint); |
| 148 | 162 |
mDistortInter.add(mDistortPoint); |
| 149 | 163 |
mSwirlInter.add(mSwirlPoint); |
| ... | ... | |
| 180 | 194 |
|
| 181 | 195 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
| 182 | 196 |
{
|
| 183 |
factor = (0.8f*height)/mObjHeight;
|
|
| 197 |
factor = (0.7f*height)/mObjHeight;
|
|
| 184 | 198 |
} |
| 185 | 199 |
else |
| 186 | 200 |
{
|
| 187 |
factor = (0.8f*width)/mObjWidth;
|
|
| 201 |
factor = (0.7f*width)/mObjWidth;
|
|
| 188 | 202 |
} |
| 189 | 203 |
|
| 190 | 204 |
mObject.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) ); |
| src/main/res/layout/vertex3dlayout.xml | ||
|---|---|---|
| 10 | 10 |
android:layout_height="0dp" |
| 11 | 11 |
android:layout_weight="1" /> |
| 12 | 12 |
|
| 13 |
<Button
|
|
| 14 |
android:id="@+id/button1"
|
|
| 15 |
android:layout_width="fill_parent"
|
|
| 13 |
<LinearLayout
|
|
| 14 |
android:orientation="horizontal"
|
|
| 15 |
android:layout_width="match_parent"
|
|
| 16 | 16 |
android:layout_height="wrap_content" |
| 17 |
android:onClick="Default" |
|
| 18 |
android:text="@string/Default" /> |
|
| 17 |
> |
|
| 18 |
|
|
| 19 |
<LinearLayout |
|
| 20 |
android:orientation="vertical" |
|
| 21 |
android:layout_width="0dp" |
|
| 22 |
android:layout_height="match_parent" |
|
| 23 |
android:layout_weight="0.8"> |
|
| 24 |
|
|
| 25 |
<TextView |
|
| 26 |
android:layout_width="wrap_content" |
|
| 27 |
android:layout_height="wrap_content" |
|
| 28 |
android:id="@+id/vertex3dcenterText"/> |
|
| 29 |
|
|
| 30 |
<LinearLayout |
|
| 31 |
android:orientation="horizontal" |
|
| 32 |
android:layout_width="match_parent" |
|
| 33 |
android:layout_height="match_parent"> |
|
| 34 |
|
|
| 35 |
<SeekBar |
|
| 36 |
android:layout_width="fill_parent" |
|
| 37 |
android:layout_height="wrap_content" |
|
| 38 |
android:id="@+id/vertex3dcenterX" |
|
| 39 |
android:layout_weight="0.5" |
|
| 40 |
android:paddingLeft="5dp" |
|
| 41 |
android:paddingRight="3dp"/> |
|
| 42 |
|
|
| 43 |
<SeekBar |
|
| 44 |
android:layout_width="fill_parent" |
|
| 45 |
android:layout_height="wrap_content" |
|
| 46 |
android:id="@+id/vertex3dcenterY" |
|
| 47 |
android:layout_weight="0.5" |
|
| 48 |
android:paddingLeft="3dp" |
|
| 49 |
android:paddingRight="5dp"/> |
|
| 50 |
</LinearLayout> |
|
| 51 |
|
|
| 52 |
</LinearLayout> |
|
| 53 |
|
|
| 54 |
<Button |
|
| 55 |
android:id="@+id/buttonDefault" |
|
| 56 |
android:layout_width="60dp" |
|
| 57 |
android:layout_height="wrap_content" |
|
| 58 |
android:onClick="Default" |
|
| 59 |
android:text="@string/reset" |
|
| 60 |
android:layout_gravity="right"/> |
|
| 61 |
</LinearLayout> |
|
| 19 | 62 |
|
| 20 | 63 |
<ScrollView |
| 21 | 64 |
android:id="@+id/vertex3dscrollView" |
Also available in: Unified diff
Vertex3D: add configurable center