1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
427ab7bf
|
Leszek Koltunski
|
|
20 |
5068fa06
|
Leszek Koltunski
|
package org.distorted.examples.bean;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import java.io.IOException;
|
23 |
|
|
import java.io.InputStream;
|
24 |
|
|
|
25 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
26 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
27 |
|
|
|
28 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
29 |
427ab7bf
|
Leszek Koltunski
|
|
30 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
31 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic2D;
|
32 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
33 |
|
|
import org.distorted.library.DistortedBitmap;
|
34 |
b5cc7760
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
35 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static2D;
|
36 |
|
|
import org.distorted.library.type.Static3D;
|
37 |
|
|
import org.distorted.library.type.Static4D;
|
38 |
427ab7bf
|
Leszek Koltunski
|
|
39 |
|
|
import android.graphics.Bitmap;
|
40 |
|
|
import android.graphics.BitmapFactory;
|
41 |
|
|
import android.opengl.GLES20;
|
42 |
|
|
import android.opengl.GLSurfaceView;
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
class BeanRenderer implements GLSurfaceView.Renderer
|
47 |
|
|
{
|
48 |
|
|
private GLSurfaceView mView;
|
49 |
|
|
private DistortedBitmap mBean;
|
50 |
7589635e
|
Leszek Koltunski
|
private Static2D pLeft, pRight;
|
51 |
b5cc7760
|
Leszek Koltunski
|
private Dynamic3D dLeft, dRight;
|
52 |
7589635e
|
Leszek Koltunski
|
private Static4D rLeft, rRight;
|
53 |
427ab7bf
|
Leszek Koltunski
|
private int bmpHeight, bmpWidth;
|
54 |
|
|
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
public BeanRenderer(GLSurfaceView v)
|
58 |
|
|
{
|
59 |
|
|
mView = v;
|
60 |
|
|
|
61 |
7589635e
|
Leszek Koltunski
|
pLeft = new Static2D(100, 199);
|
62 |
|
|
pRight= new Static2D(230, 150);
|
63 |
427ab7bf
|
Leszek Koltunski
|
|
64 |
7589635e
|
Leszek Koltunski
|
rLeft = new Static4D(-9,-31,35,35);
|
65 |
|
|
rRight= new Static4D(-9,-31,35,35);
|
66 |
427ab7bf
|
Leszek Koltunski
|
|
67 |
b5cc7760
|
Leszek Koltunski
|
dLeft = new Dynamic3D();
|
68 |
|
|
dRight= new Dynamic3D();
|
69 |
427ab7bf
|
Leszek Koltunski
|
|
70 |
b5cc7760
|
Leszek Koltunski
|
dLeft.setCount(0.0f);
|
71 |
|
|
dRight.setCount(0.0f);
|
72 |
|
|
dLeft.setDuration(1500);
|
73 |
|
|
dRight.setDuration(1500);
|
74 |
427ab7bf
|
Leszek Koltunski
|
|
75 |
b5cc7760
|
Leszek Koltunski
|
Static3D p1 = new Static3D( 0, 0, 0);
|
76 |
|
|
Static3D p2 = new Static3D(-10,-34, 0);
|
77 |
427ab7bf
|
Leszek Koltunski
|
|
78 |
b5cc7760
|
Leszek Koltunski
|
dLeft.add(p1);
|
79 |
|
|
dLeft.add(p1);
|
80 |
|
|
dLeft.add(p1);
|
81 |
|
|
dLeft.add(p1);
|
82 |
|
|
dLeft.add(p2);
|
83 |
|
|
dLeft.add(p2);
|
84 |
427ab7bf
|
Leszek Koltunski
|
|
85 |
b5cc7760
|
Leszek Koltunski
|
dRight.add(p1);
|
86 |
|
|
dRight.add(p2);
|
87 |
|
|
dRight.add(p2);
|
88 |
|
|
dRight.add(p1);
|
89 |
|
|
dRight.add(p1);
|
90 |
|
|
dRight.add(p1);
|
91 |
427ab7bf
|
Leszek Koltunski
|
}
|
92 |
|
|
|
93 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
|
95 |
|
|
public void onDrawFrame(GL10 glUnused)
|
96 |
|
|
{
|
97 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
98 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
99 |
|
|
|
100 |
|
|
mBean.draw(System.currentTimeMillis());
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
106 |
|
|
{
|
107 |
a8c3ada7
|
Leszek Koltunski
|
mBean.abortEffects(EffectTypes.MATRIX);
|
108 |
427ab7bf
|
Leszek Koltunski
|
|
109 |
|
|
if( bmpHeight/bmpWidth > height/width )
|
110 |
|
|
{
|
111 |
|
|
int w = (height*bmpWidth)/bmpHeight;
|
112 |
7589635e
|
Leszek Koltunski
|
float factor = (float)height/bmpHeight;
|
113 |
|
|
|
114 |
|
|
mBean.move( new Static3D((width-w)/2,0,0) );
|
115 |
|
|
mBean.scale( new Static3D(factor,factor,factor) );
|
116 |
427ab7bf
|
Leszek Koltunski
|
}
|
117 |
|
|
else
|
118 |
|
|
{
|
119 |
|
|
int h = (width*bmpHeight)/bmpWidth;
|
120 |
7589635e
|
Leszek Koltunski
|
float factor = (float)width/bmpWidth;
|
121 |
|
|
|
122 |
|
|
mBean.move( new Static3D(0,(height-h)/2,0) );
|
123 |
|
|
mBean.scale( new Static3D(factor,factor,factor) );
|
124 |
427ab7bf
|
Leszek Koltunski
|
}
|
125 |
|
|
|
126 |
|
|
Distorted.onSurfaceChanged(width, height);
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
|
|
|
131 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
132 |
|
|
{
|
133 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
|
134 |
|
|
Bitmap bitmap;
|
135 |
|
|
|
136 |
|
|
try
|
137 |
|
|
{
|
138 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
139 |
|
|
}
|
140 |
|
|
finally
|
141 |
|
|
{
|
142 |
|
|
try
|
143 |
|
|
{
|
144 |
|
|
is.close();
|
145 |
|
|
}
|
146 |
|
|
catch(IOException e) { }
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
bmpHeight = bitmap.getHeight();
|
150 |
|
|
bmpWidth = bitmap.getWidth();
|
151 |
|
|
|
152 |
|
|
mBean = new DistortedBitmap(bitmap, 10);
|
153 |
b5cc7760
|
Leszek Koltunski
|
mBean.distort(dLeft , pLeft , rLeft );
|
154 |
|
|
mBean.distort(dRight, pRight, rRight);
|
155 |
427ab7bf
|
Leszek Koltunski
|
|
156 |
|
|
try
|
157 |
|
|
{
|
158 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
159 |
427ab7bf
|
Leszek Koltunski
|
}
|
160 |
|
|
catch(Exception ex)
|
161 |
|
|
{
|
162 |
|
|
android.util.Log.e("Bean", ex.getMessage() );
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|