1 |
175f355d
|
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 |
|
|
|
20 |
|
|
package org.distorted.examples.flag;
|
21 |
|
|
|
22 |
|
|
import android.graphics.Bitmap;
|
23 |
|
|
import android.graphics.BitmapFactory;
|
24 |
|
|
import android.opengl.GLSurfaceView;
|
25 |
|
|
|
26 |
|
|
import org.distorted.examples.R;
|
27 |
2890c5df
|
Leszek Koltunski
|
import org.distorted.library.effect.EffectName;
|
28 |
|
|
import org.distorted.library.effect.MatrixEffectMove;
|
29 |
|
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
30 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
31 |
|
|
import org.distorted.library.effect.VertexEffectWave;
|
32 |
01782e85
|
Leszek Koltunski
|
import org.distorted.library.main.Distorted;
|
33 |
|
|
import org.distorted.library.main.DistortedEffects;
|
34 |
|
|
import org.distorted.library.main.DistortedScreen;
|
35 |
|
|
import org.distorted.library.main.MeshCubes;
|
36 |
|
|
import org.distorted.library.main.DistortedTexture;
|
37 |
76939f96
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic;
|
38 |
|
|
import org.distorted.library.type.Dynamic5D;
|
39 |
175f355d
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
40 |
|
|
import org.distorted.library.type.Static4D;
|
41 |
76939f96
|
Leszek Koltunski
|
import org.distorted.library.type.Static5D;
|
42 |
175f355d
|
Leszek Koltunski
|
|
43 |
|
|
import java.io.IOException;
|
44 |
|
|
import java.io.InputStream;
|
45 |
|
|
|
46 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
47 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
class FlagRenderer implements GLSurfaceView.Renderer
|
52 |
|
|
{
|
53 |
|
|
private GLSurfaceView mView;
|
54 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
55 |
40eef4b9
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
56 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
57 |
41d39cea
|
Leszek Koltunski
|
private Dynamic5D mWaveDyn;
|
58 |
|
|
private Static5D mWaveSta1, mWaveSta2;
|
59 |
392e16fd
|
Leszek Koltunski
|
private int mObjWidth, mObjHeight;
|
60 |
2890c5df
|
Leszek Koltunski
|
private Static3D mMove, mScale, mCenter;
|
61 |
175f355d
|
Leszek Koltunski
|
|
62 |
|
|
Static4D mQuat1, mQuat2;
|
63 |
|
|
int mScreenMin;
|
64 |
|
|
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
|
|
FlagRenderer(GLSurfaceView v)
|
68 |
|
|
{
|
69 |
|
|
mView = v;
|
70 |
|
|
|
71 |
d04a4886
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
72 |
7451c98a
|
Leszek Koltunski
|
mTexture = new DistortedTexture(500,300);
|
73 |
175f355d
|
Leszek Koltunski
|
|
74 |
40eef4b9
|
Leszek Koltunski
|
mObjWidth = mTexture.getWidth();
|
75 |
|
|
mObjHeight= mTexture.getHeight();
|
76 |
175f355d
|
Leszek Koltunski
|
|
77 |
41d39cea
|
Leszek Koltunski
|
mWaveDyn = new Dynamic5D(1000,0.0f);
|
78 |
|
|
mWaveSta1= new Static5D(0,0,-180,0,0); // all other values besides the
|
79 |
|
|
mWaveSta2= new Static5D(0,0,+180,0,0); // fourth will be set from the UI
|
80 |
76939f96
|
Leszek Koltunski
|
|
81 |
|
|
mWaveDyn.add(mWaveSta1);
|
82 |
|
|
mWaveDyn.add(mWaveSta2);
|
83 |
|
|
mWaveDyn.setMode(Dynamic.MODE_JUMP);
|
84 |
|
|
|
85 |
dba16c99
|
Leszek Koltunski
|
mQuat1 = new Static4D( 0, 0, 0, 1); // unity quaternion
|
86 |
|
|
mQuat2 = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); // something semi-random that looks good
|
87 |
175f355d
|
Leszek Koltunski
|
|
88 |
334c13fa
|
Leszek Koltunski
|
Static3D waveCenter = new Static3D(mObjWidth, mObjHeight/2, 0); // middle of the right edge
|
89 |
41d39cea
|
Leszek Koltunski
|
Static4D waveRegion = new Static4D(0,0,mObjWidth,mObjWidth);
|
90 |
|
|
|
91 |
2890c5df
|
Leszek Koltunski
|
mEffects.apply( new VertexEffectWave(mWaveDyn, waveCenter, waveRegion) );
|
92 |
|
|
|
93 |
|
|
mMove = new Static3D(0,0,0);
|
94 |
|
|
mScale = new Static3D(1,1,1);
|
95 |
|
|
mCenter= new Static3D(0,0,0);
|
96 |
|
|
|
97 |
|
|
mEffects.apply( new MatrixEffectMove(mMove));
|
98 |
|
|
mEffects.apply( new MatrixEffectScale(mScale));
|
99 |
|
|
mEffects.apply( new MatrixEffectQuaternion(mQuat1, mCenter) );
|
100 |
|
|
mEffects.apply( new MatrixEffectQuaternion(mQuat2, mCenter) );
|
101 |
392e16fd
|
Leszek Koltunski
|
|
102 |
e4330c89
|
Leszek Koltunski
|
mScreen = new DistortedScreen();
|
103 |
58e9e190
|
leszek
|
mScreen.attach(mTexture,mEffects, new MeshCubes(50,30,1) );
|
104 |
175f355d
|
Leszek Koltunski
|
}
|
105 |
|
|
|
106 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
100e2da7
|
Leszek Koltunski
|
|
108 |
41d39cea
|
Leszek Koltunski
|
void setAmplitude(int a)
|
109 |
100e2da7
|
Leszek Koltunski
|
{
|
110 |
41d39cea
|
Leszek Koltunski
|
mWaveSta1.set1(a);
|
111 |
|
|
mWaveSta2.set1(a);
|
112 |
100e2da7
|
Leszek Koltunski
|
}
|
113 |
|
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
41d39cea
|
Leszek Koltunski
|
void setLength(int l)
|
117 |
100e2da7
|
Leszek Koltunski
|
{
|
118 |
41d39cea
|
Leszek Koltunski
|
mWaveSta1.set2(l);
|
119 |
|
|
mWaveSta2.set2(l);
|
120 |
100e2da7
|
Leszek Koltunski
|
}
|
121 |
|
|
|
122 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
|
124 |
41d39cea
|
Leszek Koltunski
|
void setAngleA(int a)
|
125 |
100e2da7
|
Leszek Koltunski
|
{
|
126 |
41d39cea
|
Leszek Koltunski
|
mWaveSta1.set4(a);
|
127 |
|
|
mWaveSta2.set4(a);
|
128 |
100e2da7
|
Leszek Koltunski
|
}
|
129 |
|
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
|
132 |
41d39cea
|
Leszek Koltunski
|
void setAngleB(int b)
|
133 |
100e2da7
|
Leszek Koltunski
|
{
|
134 |
41d39cea
|
Leszek Koltunski
|
mWaveSta1.set5(b);
|
135 |
|
|
mWaveSta2.set5(b);
|
136 |
100e2da7
|
Leszek Koltunski
|
}
|
137 |
|
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
|
|
|
140 |
41d39cea
|
Leszek Koltunski
|
void setNoise(Static5D noise)
|
141 |
100e2da7
|
Leszek Koltunski
|
{
|
142 |
41d39cea
|
Leszek Koltunski
|
mWaveDyn.setNoise(noise);
|
143 |
100e2da7
|
Leszek Koltunski
|
}
|
144 |
|
|
|
145 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
|
147 |
175f355d
|
Leszek Koltunski
|
public void onDrawFrame(GL10 glUnused)
|
148 |
|
|
{
|
149 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
150 |
175f355d
|
Leszek Koltunski
|
}
|
151 |
|
|
|
152 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153 |
|
|
|
154 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
155 |
|
|
{
|
156 |
|
|
mScreenMin = width<height ? width:height;
|
157 |
2890c5df
|
Leszek Koltunski
|
float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.8f*height)/mObjHeight : (0.8f*width)/mObjWidth;
|
158 |
|
|
mMove.set((width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
|
159 |
|
|
mScale.set(factor,factor,factor);
|
160 |
|
|
mCenter.set(mObjWidth/2,mObjHeight/2, 0);
|
161 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
162 |
175f355d
|
Leszek Koltunski
|
}
|
163 |
|
|
|
164 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
167 |
|
|
{
|
168 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.iceland);
|
169 |
|
|
Bitmap bitmap;
|
170 |
|
|
|
171 |
|
|
try
|
172 |
|
|
{
|
173 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
174 |
|
|
}
|
175 |
|
|
finally
|
176 |
|
|
{
|
177 |
|
|
try
|
178 |
|
|
{
|
179 |
|
|
is.close();
|
180 |
|
|
}
|
181 |
|
|
catch(IOException e) { }
|
182 |
|
|
}
|
183 |
|
|
|
184 |
40eef4b9
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
185 |
6637d0f2
|
Leszek Koltunski
|
|
186 |
2890c5df
|
Leszek Koltunski
|
DistortedEffects.enableEffect(EffectName.WAVE);
|
187 |
6637d0f2
|
Leszek Koltunski
|
|
188 |
175f355d
|
Leszek Koltunski
|
try
|
189 |
|
|
{
|
190 |
76f9798b
|
Leszek Koltunski
|
Distorted.onCreate(mView.getContext());
|
191 |
175f355d
|
Leszek Koltunski
|
}
|
192 |
|
|
catch(Exception ex)
|
193 |
|
|
{
|
194 |
dba16c99
|
Leszek Koltunski
|
android.util.Log.e("Flag", ex.getMessage() );
|
195 |
175f355d
|
Leszek Koltunski
|
}
|
196 |
|
|
}
|
197 |
|
|
}
|