Revision 3e673c74
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/examples/multiblur/MultiblurActivity.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.examples.multiblur; |
| 21 | 21 |
|
| 22 | 22 |
import android.app.Activity; |
| 23 |
import android.opengl.GLSurfaceView; |
|
| 23 | 24 |
import android.os.Bundle; |
| 25 |
import android.widget.SeekBar; |
|
| 26 |
|
|
| 27 |
import org.distorted.examples.R; |
|
| 24 | 28 |
import org.distorted.library.Distorted; |
| 25 | 29 |
|
| 26 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | 31 |
|
| 28 |
public class MultiblurActivity extends Activity |
|
| 32 |
public class MultiblurActivity extends Activity implements SeekBar.OnSeekBarChangeListener
|
|
| 29 | 33 |
{
|
| 30 |
private MultiblurSurfaceView mView; |
|
| 31 |
|
|
| 32 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 33 | 35 |
|
| 34 | 36 |
@Override |
| 35 | 37 |
protected void onCreate(Bundle savedState) |
| 36 | 38 |
{
|
| 37 | 39 |
super.onCreate(savedState); |
| 38 |
mView = new MultiblurSurfaceView(this); |
|
| 39 |
setContentView(mView); |
|
| 40 |
setContentView(R.layout.multiblurlayout); |
|
| 41 |
|
|
| 42 |
SeekBar bar = (SeekBar)findViewById(R.id.multiblurSeek); |
|
| 43 |
bar.setOnSeekBarChangeListener(this); |
|
| 44 |
bar.setProgress(50); |
|
| 40 | 45 |
} |
| 41 | 46 |
|
| 42 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 44 | 49 |
@Override |
| 45 | 50 |
protected void onPause() |
| 46 | 51 |
{
|
| 47 |
mView.onPause(); |
|
| 52 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.multiblurSurfaceView); |
|
| 53 |
view.onPause(); |
|
| 48 | 54 |
super.onPause(); |
| 49 | 55 |
} |
| 50 | 56 |
|
| ... | ... | |
| 54 | 60 |
protected void onResume() |
| 55 | 61 |
{
|
| 56 | 62 |
super.onResume(); |
| 57 |
mView.onResume(); |
|
| 63 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.multiblurSurfaceView); |
|
| 64 |
view.onResume(); |
|
| 58 | 65 |
} |
| 59 | 66 |
|
| 60 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 65 | 72 |
Distorted.onDestroy(); |
| 66 | 73 |
super.onDestroy(); |
| 67 | 74 |
} |
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
| 79 |
{
|
|
| 80 |
switch (bar.getId()) |
|
| 81 |
{
|
|
| 82 |
case R.id.multiblurSeek: MultiblurSurfaceView view = (MultiblurSurfaceView) this.findViewById(R.id.multiblurSurfaceView); |
|
| 83 |
view.getRenderer().setDistance(progress); |
|
| 84 |
break; |
|
| 85 |
} |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
|
|
| 90 |
public void onStartTrackingTouch(SeekBar bar) { }
|
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
public void onStopTrackingTouch(SeekBar bar) { }
|
|
| 95 |
|
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 | 97 |
} |
| src/main/java/org/distorted/examples/multiblur/MultiblurRenderer.java | ||
|---|---|---|
| 32 | 32 |
import org.distorted.library.EffectNames; |
| 33 | 33 |
import org.distorted.library.EffectTypes; |
| 34 | 34 |
import org.distorted.library.MeshCubes; |
| 35 |
import org.distorted.library.type.Dynamic3D; |
|
| 35 | 36 |
import org.distorted.library.type.DynamicQuat; |
| 36 | 37 |
import org.distorted.library.type.Static1D; |
| 37 | 38 |
import org.distorted.library.type.Static3D; |
| ... | ... | |
| 65 | 66 |
private GLSurfaceView mView; |
| 66 | 67 |
private DistortedTexture mTex1, mTex2; |
| 67 | 68 |
private DistortedEffects[] mEffects; |
| 68 |
private Static3D[] mMoveVector; |
|
| 69 |
private Static3D[] mMoveVector; |
|
| 70 |
private Dynamic3D[] mMoveDynamic; |
|
| 69 | 71 |
private DistortedScreen mScreen; |
| 70 | 72 |
private DynamicQuat mQuatInt1, mQuatInt2; |
| 73 |
private int mDistance; |
|
| 71 | 74 |
|
| 72 | 75 |
Static4D mQuat1, mQuat2; |
| 73 | 76 |
int mScreenMin; |
| ... | ... | |
| 77 | 80 |
MultiblurRenderer(GLSurfaceView v) |
| 78 | 81 |
{
|
| 79 | 82 |
mView = v; |
| 83 |
mDistance = -1; |
|
| 80 | 84 |
|
| 85 |
mMoveDynamic= new Dynamic3D[NUM_OBJECTS]; |
|
| 81 | 86 |
mMoveVector = new Static3D[NUM_OBJECTS]; |
| 82 |
for(int i=0; i<NUM_OBJECTS; i++) mMoveVector[i] = new Static3D(0,0,0);
|
|
| 87 |
mEffects = new DistortedEffects[NUM_OBJECTS];
|
|
| 83 | 88 |
|
| 84 |
mEffects = new DistortedEffects[NUM_OBJECTS]; |
|
| 85 |
for(int i=0; i<NUM_OBJECTS; i++) mEffects[i] = new DistortedEffects(); |
|
| 89 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 90 |
{
|
|
| 91 |
mMoveVector[i] = new Static3D(0,0,0); |
|
| 92 |
mEffects[i] = new DistortedEffects(); |
|
| 93 |
mMoveDynamic[i] = new Dynamic3D(); |
|
| 94 |
|
|
| 95 |
mMoveDynamic[i].add(mMoveVector[i]); |
|
| 96 |
} |
|
| 86 | 97 |
|
| 87 | 98 |
mEffects[0].blur(new Static1D(10)); |
| 88 | 99 |
|
| ... | ... | |
| 118 | 129 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
| 119 | 130 |
{
|
| 120 | 131 |
mScreenMin = width<height ? width:height; |
| 121 |
|
|
| 132 |
|
|
| 133 |
float factor = 0.15f*mScreenMin/OBJ_SIZE; |
|
| 122 | 134 |
Static3D center = new Static3D( (float)OBJ_SIZE/2, (float)OBJ_SIZE/2, 0.0f ); |
| 123 |
float factor = 0.15f*mScreenMin/OBJ_SIZE; |
|
| 124 |
float xMove =(width -factor*OBJ_SIZE)/2; |
|
| 125 |
float yMove =(height-factor*OBJ_SIZE)/2; |
|
| 126 |
float size = 1.3f*OBJ_SIZE; |
|
| 135 |
Static3D moveVec= new Static3D( (width -factor*OBJ_SIZE)/2 ,(height-factor*OBJ_SIZE)/2 ,0); |
|
| 127 | 136 |
|
| 128 | 137 |
for(int i=0; i<NUM_OBJECTS; i++) |
| 129 | 138 |
{
|
| 130 | 139 |
mEffects[i].abortEffects(EffectTypes.MATRIX); |
| 131 | 140 |
|
| 132 |
mMoveVector[i].set(xMove,yMove,0); |
|
| 133 |
mEffects[i].move(mMoveVector[i]); |
|
| 141 |
mEffects[i].move(moveVec); |
|
| 134 | 142 |
mEffects[i].scale(factor); |
| 135 | 143 |
mEffects[i].quaternion(mQuatInt1, center); |
| 136 | 144 |
mEffects[i].quaternion(mQuatInt2, center); |
| 137 |
mMoveVector[i].set(size*MOVE_VEC[3*i], size*MOVE_VEC[3*i+1], size*MOVE_VEC[3*i+2]); |
|
| 138 |
mEffects[i].move(mMoveVector[i]); |
|
| 145 |
mEffects[i].move(mMoveDynamic[i]); |
|
| 139 | 146 |
} |
| 140 | 147 |
|
| 148 |
computeMoveVectors(); |
|
| 149 |
|
|
| 141 | 150 |
mScreen.resize(width, height); |
| 142 | 151 |
} |
| 143 | 152 |
|
| ... | ... | |
| 178 | 187 |
android.util.Log.e("Multiblur", ex.getMessage() );
|
| 179 | 188 |
} |
| 180 | 189 |
} |
| 190 |
|
|
| 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 192 |
|
|
| 193 |
private void computeMoveVectors() |
|
| 194 |
{
|
|
| 195 |
float size= 1.3f*OBJ_SIZE*(mDistance/50.0f); |
|
| 196 |
|
|
| 197 |
for(int i=0; i<NUM_OBJECTS; i++) |
|
| 198 |
{
|
|
| 199 |
mMoveVector[i].set(size*MOVE_VEC[3*i], size*MOVE_VEC[3*i+1], size*MOVE_VEC[3*i+2]); |
|
| 200 |
} |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 204 |
|
|
| 205 |
void setDistance(int distance) |
|
| 206 |
{
|
|
| 207 |
mDistance = distance; |
|
| 208 |
computeMoveVectors(); |
|
| 209 |
android.util.Log.e("renderer", "distance: "+distance);
|
|
| 210 |
} |
|
| 181 | 211 |
} |
| src/main/java/org/distorted/examples/multiblur/MultiblurSurfaceView.java | ||
|---|---|---|
| 38 | 38 |
|
| 39 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 40 | 40 |
|
| 41 |
public MultiblurSurfaceView(Context context) |
|
| 41 |
public MultiblurSurfaceView(Context context, AttributeSet attrs)
|
|
| 42 | 42 |
{
|
| 43 |
super(context); |
|
| 43 |
super(context, attrs);
|
|
| 44 | 44 |
|
| 45 | 45 |
mX = -1; |
| 46 | 46 |
mY = -1; |
| ... | ... | |
| 55 | 55 |
Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show(); |
| 56 | 56 |
} |
| 57 | 57 |
} |
| 58 |
|
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
public MultiblurRenderer getRenderer() |
|
| 62 |
{
|
|
| 63 |
return mRenderer; |
|
| 64 |
} |
|
| 65 |
|
|
| 59 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | 67 |
|
| 61 | 68 |
@Override public boolean onTouchEvent(MotionEvent event) |
| src/main/res/layout/multiblurlayout.xml | ||
|---|---|---|
| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|
| 2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
| 3 |
android:layout_width="fill_parent" |
|
| 4 |
android:layout_height="fill_parent" |
|
| 5 |
android:orientation="vertical" > |
|
| 6 |
|
|
| 7 |
<org.distorted.examples.multiblur.MultiblurSurfaceView |
|
| 8 |
android:id="@+id/multiblurSurfaceView" |
|
| 9 |
android:layout_width="fill_parent" |
|
| 10 |
android:layout_height="0dp" |
|
| 11 |
android:layout_weight="1" /> |
|
| 12 |
|
|
| 13 |
<LinearLayout |
|
| 14 |
android:id="@+id/linearLayout1" |
|
| 15 |
android:layout_width="fill_parent" |
|
| 16 |
android:layout_height="wrap_content" |
|
| 17 |
android:gravity="center|fill_horizontal" |
|
| 18 |
android:orientation="horizontal" |
|
| 19 |
android:paddingBottom="10dp" |
|
| 20 |
android:paddingTop="10dp" > |
|
| 21 |
|
|
| 22 |
<SeekBar |
|
| 23 |
android:id="@+id/multiblurSeek" |
|
| 24 |
android:layout_weight="1" |
|
| 25 |
android:layout_width="wrap_content" |
|
| 26 |
android:layout_height="wrap_content" |
|
| 27 |
android:paddingLeft="15dp" |
|
| 28 |
android:paddingRight="10dp" /> |
|
| 29 |
|
|
| 30 |
</LinearLayout> |
|
| 31 |
|
|
| 32 |
</LinearLayout> |
|
Also available in: Unified diff
Enrich the Multiblur app.