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.monalisa;
|
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 |
|
|
import org.distorted.library.Distorted;
|
30 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
31 |
|
|
import org.distorted.library.DistortedEffectQueues;
|
32 |
10b7e588
|
Leszek Koltunski
|
import org.distorted.library.GridFlat;
|
33 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
34 |
7bf107f7
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
35 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
36 |
|
|
import org.distorted.library.type.Static4D;
|
37 |
427ab7bf
|
Leszek Koltunski
|
|
38 |
|
|
import android.graphics.Bitmap;
|
39 |
|
|
import android.graphics.BitmapFactory;
|
40 |
|
|
import android.opengl.GLES20;
|
41 |
|
|
import android.opengl.GLSurfaceView;
|
42 |
|
|
|
43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
|
|
class MonaLisaRenderer implements GLSurfaceView.Renderer
|
46 |
|
|
{
|
47 |
|
|
private GLSurfaceView mView;
|
48 |
f6d884d5
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
49 |
|
|
private DistortedEffectQueues mQueues;
|
50 |
10b7e588
|
Leszek Koltunski
|
private GridFlat mGrid;
|
51 |
8ff32d4d
|
Leszek Koltunski
|
private int bmpHeight, bmpWidth;
|
52 |
7bf107f7
|
Leszek Koltunski
|
|
53 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
f6d884d5
|
Leszek Koltunski
|
MonaLisaRenderer(GLSurfaceView v)
|
56 |
427ab7bf
|
Leszek Koltunski
|
{
|
57 |
|
|
mView = v;
|
58 |
8ff32d4d
|
Leszek Koltunski
|
|
59 |
f6d884d5
|
Leszek Koltunski
|
Static3D pLeft = new Static3D( 90, 258, 0);
|
60 |
|
|
Static3D pRight= new Static3D(176, 255, 0);
|
61 |
8ff32d4d
|
Leszek Koltunski
|
|
62 |
f6d884d5
|
Leszek Koltunski
|
Static4D rLeft = new Static4D(-10,-10,25,25);
|
63 |
|
|
Static4D rRight= new Static4D( 10, -5,25,25);
|
64 |
|
|
Dynamic3D dLeft = new Dynamic3D(1000,0.0f);
|
65 |
|
|
Dynamic3D dRight= new Dynamic3D(1000,0.0f);
|
66 |
8ff32d4d
|
Leszek Koltunski
|
dLeft.add ( new Static3D( 0, 0,0) );
|
67 |
|
|
dLeft.add ( new Static3D(-20,-20,0) );
|
68 |
|
|
dRight.add( new Static3D( 0, 0,0) );
|
69 |
|
|
dRight.add( new Static3D( 20,-10,0) );
|
70 |
f6d884d5
|
Leszek Koltunski
|
|
71 |
|
|
mQueues = new DistortedEffectQueues();
|
72 |
|
|
mQueues.distort( dLeft, pLeft , rLeft );
|
73 |
|
|
mQueues.distort(dRight, pRight, rRight);
|
74 |
427ab7bf
|
Leszek Koltunski
|
}
|
75 |
|
|
|
76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
|
|
public void onDrawFrame(GL10 glUnused)
|
79 |
|
|
{
|
80 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
81 |
f6d884d5
|
Leszek Koltunski
|
mQueues.draw(System.currentTimeMillis(),mTexture,mGrid);
|
82 |
427ab7bf
|
Leszek Koltunski
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
87 |
|
|
{
|
88 |
f6d884d5
|
Leszek Koltunski
|
mQueues.abortEffects(EffectTypes.MATRIX);
|
89 |
8ff32d4d
|
Leszek Koltunski
|
|
90 |
5055b5d4
|
Leszek Koltunski
|
if( (float)bmpHeight/bmpWidth > (float)height/width )
|
91 |
8ff32d4d
|
Leszek Koltunski
|
{
|
92 |
|
|
int w = (height*bmpWidth)/bmpHeight;
|
93 |
|
|
float factor = (float)height/bmpHeight;
|
94 |
f6d884d5
|
Leszek Koltunski
|
mQueues.move( new Static3D((width-w)/2,0,0) );
|
95 |
|
|
mQueues.scale(factor);
|
96 |
8ff32d4d
|
Leszek Koltunski
|
}
|
97 |
|
|
else
|
98 |
|
|
{
|
99 |
|
|
int h = (width*bmpHeight)/bmpWidth;
|
100 |
|
|
float factor = (float)width/bmpWidth;
|
101 |
f6d884d5
|
Leszek Koltunski
|
mQueues.move( new Static3D(0,(height-h)/2,0) );
|
102 |
|
|
mQueues.scale(factor);
|
103 |
8ff32d4d
|
Leszek Koltunski
|
}
|
104 |
7589635e
|
Leszek Koltunski
|
|
105 |
427ab7bf
|
Leszek Koltunski
|
Distorted.onSurfaceChanged(width, height);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
111 |
|
|
{
|
112 |
e7a4ef16
|
Leszek Koltunski
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
113 |
|
|
|
114 |
427ab7bf
|
Leszek Koltunski
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.monalisa);
|
115 |
|
|
Bitmap bitmap;
|
116 |
|
|
|
117 |
|
|
try
|
118 |
|
|
{
|
119 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
120 |
|
|
}
|
121 |
|
|
finally
|
122 |
|
|
{
|
123 |
|
|
try
|
124 |
|
|
{
|
125 |
|
|
is.close();
|
126 |
|
|
}
|
127 |
|
|
catch(IOException e) { }
|
128 |
|
|
}
|
129 |
3c28857f
|
Leszek Koltunski
|
|
130 |
8ff32d4d
|
Leszek Koltunski
|
bmpHeight = bitmap.getHeight();
|
131 |
|
|
bmpWidth = bitmap.getWidth();
|
132 |
|
|
|
133 |
10b7e588
|
Leszek Koltunski
|
mGrid = new GridFlat(9,9*bmpHeight/bmpWidth);
|
134 |
f6d884d5
|
Leszek Koltunski
|
mTexture = new DistortedTexture(bmpWidth,bmpHeight,0);
|
135 |
|
|
mTexture.setTexture(bitmap);
|
136 |
7bf107f7
|
Leszek Koltunski
|
|
137 |
427ab7bf
|
Leszek Koltunski
|
try
|
138 |
|
|
{
|
139 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
140 |
427ab7bf
|
Leszek Koltunski
|
}
|
141 |
|
|
catch(Exception ex)
|
142 |
|
|
{
|
143 |
|
|
android.util.Log.e("MonaLisa", ex.getMessage() );
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
}
|