1 |
427ab7bf
|
Leszek Koltunski
|
|
2 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.bean;
|
3 |
427ab7bf
|
Leszek Koltunski
|
|
4 |
|
|
import java.io.IOException;
|
5 |
|
|
import java.io.InputStream;
|
6 |
|
|
|
7 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
8 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
9 |
|
|
|
10 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
11 |
427ab7bf
|
Leszek Koltunski
|
|
12 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
13 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Interpolator2D;
|
14 |
|
|
import org.distorted.library.Distorted;
|
15 |
|
|
import org.distorted.library.DistortedBitmap;
|
16 |
|
|
import org.distorted.library.Float2D;
|
17 |
|
|
import org.distorted.library.Float4D;
|
18 |
427ab7bf
|
Leszek Koltunski
|
|
19 |
|
|
import android.graphics.Bitmap;
|
20 |
|
|
import android.graphics.BitmapFactory;
|
21 |
|
|
import android.opengl.GLES20;
|
22 |
|
|
import android.opengl.GLSurfaceView;
|
23 |
|
|
|
24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25 |
|
|
|
26 |
|
|
class BeanRenderer implements GLSurfaceView.Renderer
|
27 |
|
|
{
|
28 |
|
|
private GLSurfaceView mView;
|
29 |
|
|
private DistortedBitmap mBean;
|
30 |
|
|
private Float2D pLeft, pRight;
|
31 |
|
|
private Interpolator2D iLeft, iRight;
|
32 |
|
|
private Float4D rLeft, rRight;
|
33 |
|
|
private int bmpHeight, bmpWidth;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public BeanRenderer(GLSurfaceView v)
|
38 |
|
|
{
|
39 |
|
|
mView = v;
|
40 |
|
|
|
41 |
|
|
pLeft = new Float2D(100, 199);
|
42 |
|
|
pRight= new Float2D(230, 150);
|
43 |
|
|
|
44 |
|
|
rLeft = new Float4D(-9,-31,35,35);
|
45 |
|
|
rRight= new Float4D(-9,-31,35,35);
|
46 |
|
|
|
47 |
|
|
iLeft = new Interpolator2D();
|
48 |
|
|
iRight= new Interpolator2D();
|
49 |
|
|
|
50 |
|
|
iLeft.setCount(0.0f);
|
51 |
|
|
iRight.setCount(0.0f);
|
52 |
|
|
iLeft.setDuration(1500);
|
53 |
|
|
iRight.setDuration(1500);
|
54 |
|
|
|
55 |
|
|
Float2D p1 = new Float2D(0,0);
|
56 |
|
|
Float2D p2 = new Float2D(-10,-34);
|
57 |
|
|
|
58 |
|
|
iLeft.add(p1);
|
59 |
|
|
iLeft.add(p1);
|
60 |
|
|
iLeft.add(p1);
|
61 |
|
|
iLeft.add(p1);
|
62 |
|
|
iLeft.add(p2);
|
63 |
|
|
iLeft.add(p2);
|
64 |
|
|
|
65 |
|
|
iRight.add(p1);
|
66 |
|
|
iRight.add(p2);
|
67 |
|
|
iRight.add(p2);
|
68 |
|
|
iRight.add(p1);
|
69 |
|
|
iRight.add(p1);
|
70 |
|
|
iRight.add(p1);
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
|
|
public void onDrawFrame(GL10 glUnused)
|
76 |
|
|
{
|
77 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
78 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
79 |
|
|
|
80 |
|
|
mBean.draw(System.currentTimeMillis());
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
86 |
|
|
{
|
87 |
a8c3ada7
|
Leszek Koltunski
|
mBean.abortEffects(EffectTypes.MATRIX);
|
88 |
427ab7bf
|
Leszek Koltunski
|
|
89 |
|
|
if( bmpHeight/bmpWidth > height/width )
|
90 |
|
|
{
|
91 |
|
|
int w = (height*bmpWidth)/bmpHeight;
|
92 |
|
|
mBean.move((width-w)/2 ,0, 0);
|
93 |
|
|
mBean.scale((float)height/bmpHeight);
|
94 |
|
|
}
|
95 |
|
|
else
|
96 |
|
|
{
|
97 |
|
|
int h = (width*bmpHeight)/bmpWidth;
|
98 |
|
|
mBean.move(0 ,(height-h)/2, 0);
|
99 |
|
|
mBean.scale((float)width/bmpWidth);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
Distorted.onSurfaceChanged(width, height);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
108 |
|
|
{
|
109 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
|
110 |
|
|
Bitmap bitmap;
|
111 |
|
|
|
112 |
|
|
try
|
113 |
|
|
{
|
114 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
115 |
|
|
}
|
116 |
|
|
finally
|
117 |
|
|
{
|
118 |
|
|
try
|
119 |
|
|
{
|
120 |
|
|
is.close();
|
121 |
|
|
}
|
122 |
|
|
catch(IOException e) { }
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
bmpHeight = bitmap.getHeight();
|
126 |
|
|
bmpWidth = bitmap.getWidth();
|
127 |
|
|
|
128 |
|
|
mBean = new DistortedBitmap(bitmap, 10);
|
129 |
|
|
mBean.distort(iLeft , rLeft , pLeft );
|
130 |
|
|
mBean.distort(iRight, rRight, pRight);
|
131 |
|
|
|
132 |
|
|
try
|
133 |
|
|
{
|
134 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
135 |
427ab7bf
|
Leszek Koltunski
|
}
|
136 |
|
|
catch(Exception ex)
|
137 |
|
|
{
|
138 |
|
|
android.util.Log.e("Bean", ex.getMessage() );
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
}
|