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 |
|
|
import android.opengl.GLES20;
|
25 |
|
|
import android.opengl.GLSurfaceView;
|
26 |
|
|
|
27 |
|
|
import org.distorted.examples.R;
|
28 |
|
|
import org.distorted.library.Distorted;
|
29 |
|
|
import org.distorted.library.DistortedCubes;
|
30 |
|
|
import org.distorted.library.DistortedObject;
|
31 |
|
|
import org.distorted.library.EffectTypes;
|
32 |
815687bb
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
33 |
14122c52
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
34 |
|
|
|
35 |
|
|
import java.io.IOException;
|
36 |
|
|
import java.io.InputStream;
|
37 |
|
|
|
38 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
39 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
|
|
class WindRenderer implements GLSurfaceView.Renderer
|
44 |
|
|
{
|
45 |
|
|
private GLSurfaceView mView;
|
46 |
|
|
private DistortedObject mObject;
|
47 |
815687bb
|
Leszek Koltunski
|
private WindEffectsManager mEffects;
|
48 |
14122c52
|
Leszek Koltunski
|
private int mObjWidth, mObjHeight;
|
49 |
|
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
WindRenderer(GLSurfaceView view)
|
53 |
|
|
{
|
54 |
|
|
mView = view;
|
55 |
|
|
|
56 |
|
|
mObject = new DistortedCubes(50,30,10,false);
|
57 |
815687bb
|
Leszek Koltunski
|
mEffects = new WindEffectsManager();
|
58 |
14122c52
|
Leszek Koltunski
|
|
59 |
|
|
mObjWidth = mObject.getWidth();
|
60 |
|
|
mObjHeight= mObject.getHeight();
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
|
65 |
|
|
void setWind(int wind)
|
66 |
|
|
{
|
67 |
815687bb
|
Leszek Koltunski
|
mEffects.apply(mObject,wind);
|
68 |
14122c52
|
Leszek Koltunski
|
}
|
69 |
|
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
public void onDrawFrame(GL10 glUnused)
|
73 |
|
|
{
|
74 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
75 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
76 |
|
|
|
77 |
|
|
mObject.draw(System.currentTimeMillis());
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
|
82 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
83 |
|
|
{
|
84 |
|
|
mObject.abortEffects(EffectTypes.MATRIX);
|
85 |
815687bb
|
Leszek Koltunski
|
float factor = 0.8f*(width<height? width:height)/mObjWidth;
|
86 |
14122c52
|
Leszek Koltunski
|
|
87 |
815687bb
|
Leszek Koltunski
|
mObject.move( new Static3D( (width-factor*mObjWidth)/2 + width/8 , (height-factor*mObjHeight)/2 -height/4 , 0) );
|
88 |
14122c52
|
Leszek Koltunski
|
mObject.scale(factor);
|
89 |
|
|
|
90 |
815687bb
|
Leszek Koltunski
|
Static1D angle = new Static1D(-45);
|
91 |
|
|
Static3D axis = new Static3D(0,0,1);
|
92 |
|
|
Static3D center= new Static3D(0,mObjHeight/2,0);
|
93 |
|
|
|
94 |
|
|
mObject.rotate(angle, axis, center);
|
95 |
14122c52
|
Leszek Koltunski
|
|
96 |
|
|
Distorted.onSurfaceChanged(width, height);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100 |
|
|
|
101 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
102 |
|
|
{
|
103 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.iceland);
|
104 |
|
|
Bitmap bitmap;
|
105 |
|
|
|
106 |
|
|
try
|
107 |
|
|
{
|
108 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
109 |
|
|
}
|
110 |
|
|
finally
|
111 |
|
|
{
|
112 |
|
|
try
|
113 |
|
|
{
|
114 |
|
|
is.close();
|
115 |
|
|
}
|
116 |
|
|
catch(IOException e) { }
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
mObject.setBitmap(bitmap);
|
120 |
|
|
|
121 |
|
|
try
|
122 |
|
|
{
|
123 |
|
|
Distorted.onSurfaceCreated(mView.getContext());
|
124 |
|
|
}
|
125 |
|
|
catch(Exception ex)
|
126 |
|
|
{
|
127 |
|
|
android.util.Log.e("Wind", ex.getMessage() );
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
}
|