1 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
71c8884f
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
bc0a685b
|
Leszek Koltunski
|
// //
|
6 |
71c8884f
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
bc0a685b
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
bc0a685b
|
Leszek Koltunski
|
// 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 |
71c8884f
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
bc0a685b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
fa9b6494
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectScale;
|
31 |
|
|
import org.distorted.library.effect.VertexEffectDistort;
|
32 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
33 |
|
|
import org.distorted.library.main.DistortedScreen;
|
34 |
e3900503
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedLibrary;
|
35 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedTexture;
|
36 |
f3ca895f
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshRectangles;
|
37 |
b5cc7760
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
38 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
39 |
|
|
import org.distorted.library.type.Static4D;
|
40 |
427ab7bf
|
Leszek Koltunski
|
|
41 |
|
|
import android.graphics.Bitmap;
|
42 |
|
|
import android.graphics.BitmapFactory;
|
43 |
|
|
import android.opengl.GLSurfaceView;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
|
|
class BeanRenderer implements GLSurfaceView.Renderer
|
48 |
|
|
{
|
49 |
|
|
private GLSurfaceView mView;
|
50 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
51 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
52 |
b0ebdf5e
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
53 |
f3ca895f
|
Leszek Koltunski
|
private MeshRectangles mMesh;
|
54 |
849e0034
|
Leszek Koltunski
|
private Static3D mScale;
|
55 |
fa9b6494
|
Leszek Koltunski
|
|
56 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
b56faf50
|
Leszek Koltunski
|
BeanRenderer(GLSurfaceView v)
|
59 |
427ab7bf
|
Leszek Koltunski
|
{
|
60 |
|
|
mView = v;
|
61 |
|
|
|
62 |
849e0034
|
Leszek Koltunski
|
Static3D pointLeft = new Static3D(-85, 57, 0);
|
63 |
|
|
Static3D pointRight = new Static3D( 50, 100, 0);
|
64 |
a4d59c0b
|
Leszek Koltunski
|
Static4D regionLeft = new Static4D( -3, 33, 0, 47);
|
65 |
|
|
Static4D regionRight= new Static4D(-14, 33, 0, 47);
|
66 |
dfae5d27
|
Leszek Koltunski
|
Dynamic3D dynLeft = new Dynamic3D(2000,0.0f);
|
67 |
|
|
Dynamic3D dynRight = new Dynamic3D(2000,0.0f);
|
68 |
f988589e
|
Leszek Koltunski
|
|
69 |
a4d59c0b
|
Leszek Koltunski
|
Static3D vect1 = new Static3D( 0, 0, 0);
|
70 |
|
|
Static3D vect2 = new Static3D(-15, 30, 0);
|
71 |
dfae5d27
|
Leszek Koltunski
|
|
72 |
a4d59c0b
|
Leszek Koltunski
|
dynLeft.add(vect1);
|
73 |
|
|
dynLeft.add(vect1);
|
74 |
|
|
dynLeft.add(vect1);
|
75 |
|
|
dynLeft.add(vect1);
|
76 |
|
|
dynLeft.add(vect2);
|
77 |
|
|
dynLeft.add(vect2);
|
78 |
427ab7bf
|
Leszek Koltunski
|
|
79 |
a4d59c0b
|
Leszek Koltunski
|
dynRight.add(vect1);
|
80 |
|
|
dynRight.add(vect2);
|
81 |
|
|
dynRight.add(vect2);
|
82 |
|
|
dynRight.add(vect1);
|
83 |
|
|
dynRight.add(vect1);
|
84 |
|
|
dynRight.add(vect1);
|
85 |
f6d884d5
|
Leszek Koltunski
|
|
86 |
fa9b6494
|
Leszek Koltunski
|
mScale= new Static3D(1,1,1);
|
87 |
|
|
|
88 |
698ad0a8
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
89 |
849e0034
|
Leszek Koltunski
|
mEffects.apply( new VertexEffectDistort(dynLeft , pointLeft , regionLeft) );
|
90 |
|
|
mEffects.apply( new VertexEffectDistort(dynRight, pointRight, regionRight));
|
91 |
dfae5d27
|
Leszek Koltunski
|
mEffects.apply( new MatrixEffectScale(mScale) );
|
92 |
392e16fd
|
Leszek Koltunski
|
|
93 |
e4330c89
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
94 |
427ab7bf
|
Leszek Koltunski
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
|
98 |
fa9b6494
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
99 |
427ab7bf
|
Leszek Koltunski
|
{
|
100 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
101 |
427ab7bf
|
Leszek Koltunski
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
fa9b6494
|
Leszek Koltunski
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
106 |
|
|
{
|
107 |
d381aa80
|
Leszek Koltunski
|
float horiRatio = (float)width / mTexture.getWidth();
|
108 |
|
|
float vertRatio = (float)height/ mTexture.getHeight();
|
109 |
|
|
float factor = horiRatio > vertRatio ? vertRatio : horiRatio;
|
110 |
|
|
|
111 |
|
|
mScale.set( factor,factor,factor );
|
112 |
|
|
mScreen.resize(width, height);
|
113 |
fa9b6494
|
Leszek Koltunski
|
}
|
114 |
427ab7bf
|
Leszek Koltunski
|
|
115 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
|
117 |
fa9b6494
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
118 |
|
|
{
|
119 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
|
120 |
|
|
Bitmap bitmap;
|
121 |
427ab7bf
|
Leszek Koltunski
|
|
122 |
fa9b6494
|
Leszek Koltunski
|
try
|
123 |
|
|
{
|
124 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
125 |
|
|
}
|
126 |
|
|
finally
|
127 |
|
|
{
|
128 |
|
|
try
|
129 |
|
|
{
|
130 |
|
|
is.close();
|
131 |
|
|
}
|
132 |
|
|
catch(IOException e) { }
|
133 |
|
|
}
|
134 |
427ab7bf
|
Leszek Koltunski
|
|
135 |
d381aa80
|
Leszek Koltunski
|
int bmpHeight = bitmap.getHeight();
|
136 |
|
|
int bmpWidth = bitmap.getWidth();
|
137 |
687263cc
|
Leszek Koltunski
|
|
138 |
|
|
if( mTexture==null ) mTexture = new DistortedTexture();
|
139 |
fa9b6494
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
140 |
26c4e181
|
Leszek Koltunski
|
|
141 |
698ad0a8
|
Leszek Koltunski
|
if( mMesh==null )
|
142 |
|
|
{
|
143 |
386fd702
|
Leszek Koltunski
|
mMesh = new MeshRectangles(25,25*bmpHeight/bmpWidth);
|
144 |
|
|
mMesh.setStretch(bmpWidth,bmpHeight,0);
|
145 |
698ad0a8
|
Leszek Koltunski
|
}
|
146 |
a4d59c0b
|
Leszek Koltunski
|
|
147 |
fa9b6494
|
Leszek Koltunski
|
mScreen.detachAll();
|
148 |
|
|
mScreen.attach(mTexture,mEffects,mMesh);
|
149 |
|
|
|
150 |
885b9cca
|
leszek
|
VertexEffectDistort.enable();
|
151 |
fa9b6494
|
Leszek Koltunski
|
|
152 |
|
|
try
|
153 |
|
|
{
|
154 |
e3900503
|
Leszek Koltunski
|
DistortedLibrary.onCreate(mView.getContext());
|
155 |
fa9b6494
|
Leszek Koltunski
|
}
|
156 |
|
|
catch(Exception ex)
|
157 |
|
|
{
|
158 |
|
|
android.util.Log.e("Bean", ex.getMessage() );
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
427ab7bf
|
Leszek Koltunski
|
}
|