1 |
14122c52
|
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.wind;
|
21 |
|
|
|
22 |
|
|
import android.graphics.Bitmap;
|
23 |
|
|
import android.graphics.BitmapFactory;
|
24 |
41a81a14
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
25 |
14122c52
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
26 |
|
|
|
27 |
|
|
import org.distorted.examples.R;
|
28 |
|
|
import org.distorted.library.Distorted;
|
29 |
392e16fd
|
Leszek Koltunski
|
import org.distorted.library.DistortedFramebuffer;
|
30 |
b01acdaf
|
Leszek Koltunski
|
import org.distorted.library.MeshCubes;
|
31 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffects;
|
32 |
40eef4b9
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
33 |
815687bb
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
34 |
14122c52
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
35 |
|
|
|
36 |
|
|
import java.io.IOException;
|
37 |
|
|
import java.io.InputStream;
|
38 |
|
|
|
39 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
40 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
41 |
|
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
class WindRenderer implements GLSurfaceView.Renderer
|
45 |
|
|
{
|
46 |
|
|
private GLSurfaceView mView;
|
47 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
48 |
40eef4b9
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
49 |
392e16fd
|
Leszek Koltunski
|
private DistortedFramebuffer mScreen;
|
50 |
b01acdaf
|
Leszek Koltunski
|
private MeshCubes mMesh;
|
51 |
392e16fd
|
Leszek Koltunski
|
private WindEffectsManager mManager;
|
52 |
14122c52
|
Leszek Koltunski
|
private int mObjWidth, mObjHeight;
|
53 |
21819119
|
Leszek Koltunski
|
private int mWind;
|
54 |
14122c52
|
Leszek Koltunski
|
|
55 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
WindRenderer(GLSurfaceView view)
|
58 |
|
|
{
|
59 |
|
|
mView = view;
|
60 |
|
|
|
61 |
b01acdaf
|
Leszek Koltunski
|
mMesh = new MeshCubes(50,30,false);
|
62 |
d04a4886
|
Leszek Koltunski
|
mEffects = new DistortedEffects();
|
63 |
7451c98a
|
Leszek Koltunski
|
mTexture = new DistortedTexture(50,30);
|
64 |
392e16fd
|
Leszek Koltunski
|
mManager = new WindEffectsManager(mTexture);
|
65 |
|
|
mScreen = new DistortedFramebuffer(0);
|
66 |
14122c52
|
Leszek Koltunski
|
|
67 |
40eef4b9
|
Leszek Koltunski
|
mObjWidth = mTexture.getWidth();
|
68 |
|
|
mObjHeight= mTexture.getHeight();
|
69 |
14122c52
|
Leszek Koltunski
|
}
|
70 |
|
|
|
71 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
|
|
73 |
|
|
void setWind(int wind)
|
74 |
|
|
{
|
75 |
21819119
|
Leszek Koltunski
|
mWind = wind;
|
76 |
392e16fd
|
Leszek Koltunski
|
mManager.setWind(mWind);
|
77 |
14122c52
|
Leszek Koltunski
|
}
|
78 |
|
|
|
79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
public void onDrawFrame(GL10 glUnused)
|
82 |
|
|
{
|
83 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
84 |
b01acdaf
|
Leszek Koltunski
|
mScreen.renderTo(mTexture, mMesh, mEffects, System.currentTimeMillis() );
|
85 |
14122c52
|
Leszek Koltunski
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
90 |
|
|
{
|
91 |
392e16fd
|
Leszek Koltunski
|
mEffects.abortAllEffects();
|
92 |
21819119
|
Leszek Koltunski
|
|
93 |
b041d424
|
Leszek Koltunski
|
float factor = ( (float)(width<height? width:height) )/(mObjHeight + 1.4f*mObjWidth);
|
94 |
14122c52
|
Leszek Koltunski
|
|
95 |
392e16fd
|
Leszek Koltunski
|
mEffects.move( new Static3D( factor*mObjHeight*0.58f , factor*mObjHeight*0.08f , 0) );
|
96 |
|
|
mEffects.scale(factor);
|
97 |
14122c52
|
Leszek Koltunski
|
|
98 |
815687bb
|
Leszek Koltunski
|
Static1D angle = new Static1D(-45);
|
99 |
|
|
Static3D axis = new Static3D(0,0,1);
|
100 |
|
|
Static3D center= new Static3D(0,mObjHeight/2,0);
|
101 |
|
|
|
102 |
392e16fd
|
Leszek Koltunski
|
mEffects.rotate(angle, axis, center);
|
103 |
|
|
mManager.apply(mEffects,mWind);
|
104 |
|
|
mScreen.resize(width, height);
|
105 |
14122c52
|
Leszek Koltunski
|
}
|
106 |
|
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
110 |
e7a4ef16
|
Leszek Koltunski
|
{
|
111 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
112 |
e7a4ef16
|
Leszek Koltunski
|
|
113 |
14122c52
|
Leszek Koltunski
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.iceland);
|
114 |
|
|
Bitmap bitmap;
|
115 |
|
|
|
116 |
|
|
try
|
117 |
|
|
{
|
118 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
119 |
|
|
}
|
120 |
|
|
finally
|
121 |
|
|
{
|
122 |
|
|
try
|
123 |
|
|
{
|
124 |
|
|
is.close();
|
125 |
|
|
}
|
126 |
|
|
catch(IOException e) { }
|
127 |
|
|
}
|
128 |
|
|
|
129 |
40eef4b9
|
Leszek Koltunski
|
mTexture.setTexture(bitmap);
|
130 |
14122c52
|
Leszek Koltunski
|
|
131 |
|
|
try
|
132 |
|
|
{
|
133 |
76f9798b
|
Leszek Koltunski
|
Distorted.onCreate(mView.getContext());
|
134 |
14122c52
|
Leszek Koltunski
|
}
|
135 |
|
|
catch(Exception ex)
|
136 |
|
|
{
|
137 |
|
|
android.util.Log.e("Wind", ex.getMessage() );
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
}
|