Revision 13fde129
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/examples/sink/SinkActivity.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.examples.sink; |
21 | 21 |
|
22 |
import org.distorted.examples.R; |
|
22 | 23 |
import org.distorted.library.main.DistortedLibrary; |
23 | 24 |
|
24 | 25 |
import android.app.Activity; |
25 | 26 |
import android.os.Bundle; |
27 |
import android.widget.SeekBar; |
|
28 |
import android.widget.TextView; |
|
26 | 29 |
|
27 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 31 |
|
29 |
public class SinkActivity extends Activity |
|
30 |
{
|
|
31 |
private SinkSurfaceView mView;
|
|
32 |
public class SinkActivity extends Activity implements SeekBar.OnSeekBarChangeListener
|
|
33 |
{ |
|
34 |
private TextView sinkText;
|
|
32 | 35 |
|
33 | 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 |
|
|
35 |
@Override |
|
36 |
protected void onCreate(Bundle icicle) |
|
37 |
{ |
|
38 |
super.onCreate(icicle); |
|
39 |
DistortedLibrary.onCreate(); |
|
40 |
mView = new SinkSurfaceView(this); |
|
41 |
setContentView(mView); |
|
42 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void onCreate(Bundle icicle) |
|
40 |
{ |
|
41 |
super.onCreate(icicle); |
|
42 |
DistortedLibrary.onCreate(); |
|
43 |
setContentView(R.layout.sinklayout); |
|
44 |
|
|
45 |
SeekBar bar = findViewById(R.id.sinkSeek); |
|
46 |
bar.setOnSeekBarChangeListener(this); |
|
47 |
|
|
48 |
sinkText = findViewById(R.id.sinkText); |
|
49 |
|
|
50 |
bar.setProgress(50); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void onPause() |
|
57 |
{ |
|
58 |
super.onPause(); |
|
59 |
SinkSurfaceView view = findViewById(R.id.sinkSurfaceView); |
|
60 |
view.onPause(); |
|
61 |
DistortedLibrary.onPause(); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
@Override |
|
67 |
protected void onResume() |
|
68 |
{ |
|
69 |
super.onResume(); |
|
70 |
SinkSurfaceView view = findViewById(R.id.sinkSurfaceView); |
|
71 |
view.onResume(); |
|
72 |
} |
|
43 | 73 |
|
44 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
45 |
|
|
46 |
@Override |
|
47 |
protected void onPause() |
|
48 |
{ |
|
49 |
super.onPause(); |
|
50 |
mView.onPause(); |
|
51 |
DistortedLibrary.onPause(); |
|
52 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
protected void onDestroy() |
|
78 |
{ |
|
79 |
DistortedLibrary.onDestroy(); |
|
80 |
super.onDestroy(); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
86 |
{ |
|
87 |
if (bar.getId() == R.id.sinkSeek) |
|
88 |
{ |
|
89 |
SinkSurfaceView view = findViewById(R.id.sinkSurfaceView); |
|
90 |
float value = view.getRenderer().setSink(progress); |
|
91 |
sinkText.setText(getString(R.string.sink_placeholder,value)); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
|
97 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
53 | 98 |
|
54 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 |
|
|
56 |
@Override |
|
57 |
protected void onResume() |
|
58 |
{ |
|
59 |
super.onResume(); |
|
60 |
mView.onResume(); |
|
61 |
} |
|
62 |
|
|
100 |
|
|
101 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
102 |
|
|
63 | 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 |
|
|
65 |
@Override |
|
66 |
protected void onDestroy() |
|
67 |
{ |
|
68 |
DistortedLibrary.onDestroy(); |
|
69 |
super.onDestroy(); |
|
70 |
} |
|
71 |
} |
|
104 |
|
|
105 |
} |
src/main/java/org/distorted/examples/sink/SinkRenderer.java | ||
---|---|---|
34 | 34 |
import org.distorted.library.main.DistortedScreen; |
35 | 35 |
import org.distorted.library.mesh.MeshSquare; |
36 | 36 |
import org.distorted.library.main.DistortedTexture; |
37 |
import org.distorted.library.type.Dynamic1D; |
|
38 | 37 |
import org.distorted.library.type.Static1D; |
39 | 38 |
import org.distorted.library.type.Static3D; |
40 | 39 |
import org.distorted.library.type.Static4D; |
... | ... | |
47 | 46 |
|
48 | 47 |
class SinkRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
49 | 48 |
{ |
50 |
private GLSurfaceView mView; |
|
51 |
private DistortedEffects mEffects; |
|
52 |
private DistortedScreen mScreen; |
|
53 |
private DistortedTexture mTexture; |
|
54 |
private MeshSquare mMesh; |
|
55 |
private Static3D mScale; |
|
49 |
private final GLSurfaceView mView; |
|
50 |
private final DistortedEffects mEffects; |
|
51 |
private final DistortedScreen mScreen; |
|
52 |
private final DistortedTexture mTexture; |
|
53 |
private final Static3D mScale; |
|
54 |
private final Static1D mSinkStrength; |
|
55 |
|
|
56 | 56 |
private float mBmpRatio; |
57 |
private MeshSquare mMesh; |
|
57 | 58 |
|
58 | 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 60 |
|
... | ... | |
63 | 64 |
mTexture = new DistortedTexture(); |
64 | 65 |
mEffects = new DistortedEffects(); |
65 | 66 |
mScreen = new DistortedScreen(); |
67 |
mSinkStrength = new Static1D(1.0f); |
|
66 | 68 |
|
67 |
Dynamic1D sinkStrength = new Dynamic1D(2000,0.0f); |
|
68 |
sinkStrength.add(new Static1D(2.0f)); |
|
69 |
sinkStrength.add(new Static1D(0.2f)); |
|
70 |
|
|
71 |
// strength [changing in time from 1.0 to 0.2 and back], |
|
72 |
// center [(0,0,0), i.e. center of the bitmap], |
|
73 |
// region [ (0,0,0) with radius 0.5 - apply to the center circle of the bitmap ] |
|
74 |
VertexEffectSink sinkEffect = new VertexEffectSink(sinkStrength, new Static3D(0,0,0), new Static4D(0,0,0,0.5f) ); |
|
69 |
VertexEffectSink sinkEffect = new VertexEffectSink(mSinkStrength, new Static3D(0,0,0), new Static4D(0,0,0,0.5f) ); |
|
75 | 70 |
mEffects.apply(sinkEffect); |
76 | 71 |
|
77 | 72 |
mScale = new Static3D(1,1,1); |
... | ... | |
79 | 74 |
} |
80 | 75 |
|
81 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 |
|
|
77 |
// logarithmic: 50 -> 1.0, 40-> A^(-1), 30->A^(-2), 70-> A^2 |
|
78 |
// where A = 5 maybe? |
|
79 |
// f(x) = A^((level-50)/10) = e^(logA*((level-50)/10)) |
|
80 |
|
|
81 |
float setSink(int level) |
|
82 |
{ |
|
83 |
final double logA = Math.log(5); |
|
84 |
final float exponent = (level-50)/10.0f; |
|
85 |
final float value = (float)Math.exp(logA*exponent); |
|
86 |
mSinkStrength.set(value); |
|
87 |
|
|
88 |
return value; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
83 | 93 |
public void onDrawFrame(GL10 glUnused) |
84 | 94 |
{ |
85 | 95 |
mScreen.render( System.currentTimeMillis() ); |
... | ... | |
99 | 109 |
|
100 | 110 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
101 | 111 |
{ |
102 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.cat);
|
|
112 |
InputStream is = mView.getContext().getResources().openRawResource(R.raw.gridlines);
|
|
103 | 113 |
Bitmap bitmap; |
104 | 114 |
|
105 | 115 |
try |
... | ... | |
112 | 122 |
{ |
113 | 123 |
is.close(); |
114 | 124 |
} |
115 |
catch(IOException e) { }
|
|
125 |
catch(IOException ignored) { }
|
|
116 | 126 |
} |
117 | 127 |
|
118 | 128 |
mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth(); |
src/main/java/org/distorted/examples/sink/SinkSurfaceView.java | ||
---|---|---|
23 | 23 |
import android.content.Context; |
24 | 24 |
import android.content.pm.ConfigurationInfo; |
25 | 25 |
import android.opengl.GLSurfaceView; |
26 |
import android.util.AttributeSet; |
|
26 | 27 |
|
27 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 29 |
|
29 |
class SinkSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
public SinkSurfaceView(Context context) |
|
32 |
{ |
|
33 |
super(context); |
|
34 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
35 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
36 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
37 |
setRenderer(new SinkRenderer(this)); |
|
38 |
} |
|
39 |
} |
|
30 |
class SinkSurfaceView extends GLSurfaceView |
|
31 |
{ |
|
32 |
private SinkRenderer mRenderer; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
public SinkSurfaceView(Context context, AttributeSet attrs) |
|
37 |
{ |
|
38 |
super(context, attrs); |
|
39 |
|
|
40 |
if(!isInEditMode()) |
|
41 |
{ |
|
42 |
mRenderer = new SinkRenderer(this); |
|
43 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
44 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
45 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
|
46 |
setRenderer(mRenderer); |
|
47 |
} |
|
48 |
} |
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public SinkRenderer getRenderer() |
|
52 |
{ |
|
53 |
return mRenderer; |
|
54 |
} |
|
55 |
} |
|
40 | 56 |
|
src/main/res/layout/sinklayout.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.sink.SinkSurfaceView |
|
8 |
android:id="@+id/sinkSurfaceView" |
|
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:paddingTop="10dp" |
|
20 |
android:paddingBottom="10dp"> |
|
21 |
|
|
22 |
<TextView |
|
23 |
android:id="@+id/sinkText" |
|
24 |
android:layout_width="0dp" |
|
25 |
android:layout_height="wrap_content" |
|
26 |
android:layout_weight="0.5" |
|
27 |
android:paddingLeft="10dp" |
|
28 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
29 |
|
|
30 |
<SeekBar |
|
31 |
android:id="@+id/sinkSeek" |
|
32 |
android:layout_width="wrap_content" |
|
33 |
android:layout_height="wrap_content" |
|
34 |
android:layout_weight="1" |
|
35 |
android:paddingLeft="10dp" |
|
36 |
android:paddingRight="10dp" /> |
|
37 |
|
|
38 |
</LinearLayout> |
|
39 |
|
|
40 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
119 | 119 |
<string name="fov_placeholder">FOV: %1$d</string> |
120 | 120 |
<string name="near_placeholder">Near: %1$.2f</string> |
121 | 121 |
<string name="wind_placeholder">Wind: %1$d</string> |
122 |
<string name="sink_placeholder">%1$.4f</string> |
|
122 | 123 |
<string name="blur_placeholder">Blur: %1$d</string> |
123 | 124 |
<string name="halo_placeholder">Halo: %1$d</string> |
124 | 125 |
<string name="move_placeholder">Move: %1$d</string> |
Also available in: Unified diff
Change the Sink app. The point: test Sink effect at extreme strengths.