Revision 13fde129
Added by Leszek Koltunski over 1 year ago
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(); |
Also available in: Unified diff
Change the Sink app. The point: test Sink effect at extreme strengths.