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 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffects;
|
31 |
392e16fd
|
Leszek Koltunski
|
import org.distorted.library.DistortedFramebuffer;
|
32 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
33 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
34 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
35 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
36 |
b5cc7760
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
37 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
38 |
|
|
import org.distorted.library.type.Static4D;
|
39 |
427ab7bf
|
Leszek Koltunski
|
|
40 |
|
|
import android.graphics.Bitmap;
|
41 |
|
|
import android.graphics.BitmapFactory;
|
42 |
|
|
import android.opengl.GLES20;
|
43 |
|
|
import android.opengl.GLSurfaceView;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
|
|
class BeanRenderer implements GLSurfaceView.Renderer
|
48 |
|
|
{
|
49 |
|
|
private GLSurfaceView mView;
|
50 |
f6d884d5
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
51 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
52 |
392e16fd
|
Leszek Koltunski
|
private DistortedFramebuffer mScreen;
|
53 |
10b7e588
|
Leszek Koltunski
|
private GridFlat mGrid;
|
54 |
427ab7bf
|
Leszek Koltunski
|
private int bmpHeight, bmpWidth;
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
b56faf50
|
Leszek Koltunski
|
BeanRenderer(GLSurfaceView v)
|
59 |
427ab7bf
|
Leszek Koltunski
|
{
|
60 |
|
|
mView = v;
|
61 |
|
|
|
62 |
f6d884d5
|
Leszek Koltunski
|
Static3D pLeft = new Static3D( 98, 183, 0);
|
63 |
|
|
Static3D pRight= new Static3D(233, 140, 0);
|
64 |
427ab7bf
|
Leszek Koltunski
|
|
65 |
f6d884d5
|
Leszek Koltunski
|
Static4D rLeft = new Static4D( -3,-33,47,47);
|
66 |
|
|
Static4D rRight= new Static4D(-14,-33,47,47);
|
67 |
427ab7bf
|
Leszek Koltunski
|
|
68 |
f6d884d5
|
Leszek Koltunski
|
Dynamic3D dLeft = new Dynamic3D(2000,0.0f);
|
69 |
|
|
Dynamic3D dRight= new Dynamic3D(2000,0.0f);
|
70 |
f988589e
|
Leszek Koltunski
|
|
71 |
b5cc7760
|
Leszek Koltunski
|
Static3D p1 = new Static3D( 0, 0, 0);
|
72 |
cdc515b9
|
Leszek Koltunski
|
Static3D p2 = new Static3D(-15,-30, 0);
|
73 |
427ab7bf
|
Leszek Koltunski
|
|
74 |
b5cc7760
|
Leszek Koltunski
|
dLeft.add(p1);
|
75 |
|
|
dLeft.add(p1);
|
76 |
|
|
dLeft.add(p1);
|
77 |
|
|
dLeft.add(p1);
|
78 |
|
|
dLeft.add(p2);
|
79 |
|
|
dLeft.add(p2);
|
80 |
427ab7bf
|
Leszek Koltunski
|
|
81 |
b5cc7760
|
Leszek Koltunski
|
dRight.add(p1);
|
82 |
|
|
dRight.add(p2);
|
83 |
|
|
dRight.add(p2);
|
84 |
|
|
dRight.add(p1);
|
85 |
|
|
dRight.add(p1);
|
86 |
|
|
dRight.add(p1);
|
87 |
f6d884d5
|
Leszek Koltunski
|
|
88 |
d04a4886
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
89 |
392e16fd
|
Leszek Koltunski
|
mEffects.distort(dLeft , pLeft , rLeft );
|
90 |
|
|
mEffects.distort(dRight, pRight, rRight);
|
91 |
|
|
|
92 |
|
|
mScreen = new DistortedFramebuffer(0);
|
93 |
427ab7bf
|
Leszek Koltunski
|
}
|
94 |
|
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
|
|
public void onDrawFrame(GL10 glUnused)
|
98 |
|
|
{
|
99 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
100 |
bc29e409
|
Leszek Koltunski
|
mScreen.renderTo(mTexture, mGrid, mEffects, System.currentTimeMillis() );
|
101 |
427ab7bf
|
Leszek Koltunski
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
106 |
|
|
{
|
107 |
392e16fd
|
Leszek Koltunski
|
mEffects.abortEffects(EffectTypes.MATRIX);
|
108 |
427ab7bf
|
Leszek Koltunski
|
|
109 |
5055b5d4
|
Leszek Koltunski
|
if( (float)bmpHeight/bmpWidth > (float)height/width )
|
110 |
427ab7bf
|
Leszek Koltunski
|
{
|
111 |
|
|
int w = (height*bmpWidth)/bmpHeight;
|
112 |
7589635e
|
Leszek Koltunski
|
float factor = (float)height/bmpHeight;
|
113 |
|
|
|
114 |
392e16fd
|
Leszek Koltunski
|
mEffects.move( new Static3D((width-w)/2,0,0) );
|
115 |
|
|
mEffects.scale(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 |
392e16fd
|
Leszek Koltunski
|
mEffects.move( new Static3D(0,(height-h)/2,0) );
|
123 |
|
|
mEffects.scale(factor);
|
124 |
427ab7bf
|
Leszek Koltunski
|
}
|
125 |
|
|
|
126 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
127 |
427ab7bf
|
Leszek Koltunski
|
}
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
|
|
|
131 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
132 |
|
|
{
|
133 |
e7a4ef16
|
Leszek Koltunski
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
134 |
|
|
|
135 |
427ab7bf
|
Leszek Koltunski
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
|
136 |
|
|
Bitmap bitmap;
|
137 |
|
|
|
138 |
|
|
try
|
139 |
|
|
{
|
140 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
141 |
|
|
}
|
142 |
|
|
finally
|
143 |
|
|
{
|
144 |
|
|
try
|
145 |
|
|
{
|
146 |
|
|
is.close();
|
147 |
|
|
}
|
148 |
|
|
catch(IOException e) { }
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
bmpHeight = bitmap.getHeight();
|
152 |
|
|
bmpWidth = bitmap.getWidth();
|
153 |
|
|
|
154 |
7451c98a
|
Leszek Koltunski
|
mTexture = new DistortedTexture(bmpWidth,bmpHeight);
|
155 |
f6d884d5
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
156 |
10b7e588
|
Leszek Koltunski
|
mGrid = new GridFlat(25,25*bmpHeight/bmpWidth);
|
157 |
e8b6aa95
|
Leszek Koltunski
|
|
158 |
427ab7bf
|
Leszek Koltunski
|
try
|
159 |
|
|
{
|
160 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
161 |
427ab7bf
|
Leszek Koltunski
|
}
|
162 |
|
|
catch(Exception ex)
|
163 |
|
|
{
|
164 |
|
|
android.util.Log.e("Bean", ex.getMessage() );
|
165 |
|
|
}
|
166 |
|
|
}
|
167 |
|
|
}
|