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.effects3d;
|
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 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.DistortedCubes;
|
31 |
95593730
|
Leszek Koltunski
|
import org.distorted.library.EffectTypes;
|
32 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
33 |
|
|
import org.distorted.library.type.Dynamic3D;
|
34 |
|
|
import org.distorted.library.type.Static1D;
|
35 |
|
|
import org.distorted.library.type.Static3D;
|
36 |
|
|
import org.distorted.library.type.Static4D;
|
37 |
|
|
import org.distorted.library.type.Dynamic4D;
|
38 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
39 |
427ab7bf
|
Leszek Koltunski
|
|
40 |
|
|
import android.graphics.Bitmap;
|
41 |
|
|
import android.graphics.BitmapFactory;
|
42 |
|
|
import android.opengl.GLES20;
|
43 |
|
|
import android.opengl.GLSurfaceView;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
|
|
class Effects3DRenderer implements GLSurfaceView.Renderer
|
48 |
|
|
{
|
49 |
|
|
private static final int SIZE = 100;
|
50 |
|
|
|
51 |
|
|
private GLSurfaceView mView;
|
52 |
|
|
private static DistortedCubes mCube;
|
53 |
|
|
|
54 |
|
|
private static int[] order;
|
55 |
|
|
|
56 |
7589635e
|
Leszek Koltunski
|
private static Dynamic3D mMoveInter, mScaleInter, mShearInter;
|
57 |
|
|
private static Dynamic4D mDynamicRotate;
|
58 |
|
|
|
59 |
|
|
private static Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
|
60 |
|
|
private static Static4D mRotatePoint;
|
61 |
|
|
|
62 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63 |
|
|
|
64 |
|
|
public static void setMove(float x, float y, float z)
|
65 |
|
|
{
|
66 |
|
|
mMovePoint.set(x, y, z);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
public static void setScale(float x, float y, float z)
|
72 |
|
|
{
|
73 |
|
|
mScalePoint.set(x, y, z);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77 |
|
|
|
78 |
|
|
public static void setRotate(float a, float x, float y, float z)
|
79 |
|
|
{
|
80 |
7589635e
|
Leszek Koltunski
|
mRotatePoint.set(a,x,y,z);
|
81 |
427ab7bf
|
Leszek Koltunski
|
}
|
82 |
|
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
|
|
public static void setShear(float x, float y, float z)
|
86 |
|
|
{
|
87 |
|
|
mShearPoint.set(x, y, z);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
public static void setOrder(int[] effects)
|
93 |
|
|
{
|
94 |
|
|
order = effects;
|
95 |
|
|
setMatrixEffects();
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
99 |
|
|
|
100 |
|
|
public static void setMatrixEffects()
|
101 |
|
|
{
|
102 |
a8c3ada7
|
Leszek Koltunski
|
mCube.abortEffects(EffectTypes.MATRIX);
|
103 |
427ab7bf
|
Leszek Koltunski
|
|
104 |
|
|
for( int i=0; i<=order.length-1 ; i++ )
|
105 |
|
|
{
|
106 |
|
|
switch(order[i])
|
107 |
|
|
{
|
108 |
7589635e
|
Leszek Koltunski
|
case Effects3DActivity.MOVE : mCube.move(mMoveInter) ; break;
|
109 |
|
|
case Effects3DActivity.SCALE : mCube.scale(mScaleInter) ; break;
|
110 |
|
|
case Effects3DActivity.ROTATE: mCube.rotate(mZeroPoint,mDynamicRotate); break;
|
111 |
|
|
case Effects3DActivity.SHEAR : mCube.shear(mZeroPoint,mShearInter) ; break;
|
112 |
427ab7bf
|
Leszek Koltunski
|
}
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
public Effects3DRenderer(GLSurfaceView v)
|
119 |
|
|
{
|
120 |
|
|
mView = v;
|
121 |
|
|
mCube = new DistortedCubes( 1, "1", SIZE);
|
122 |
|
|
|
123 |
7589635e
|
Leszek Koltunski
|
mZeroPoint = new Static3D(0,0,0);
|
124 |
|
|
mMovePoint = new Static3D(0,0,0);
|
125 |
|
|
mScalePoint = new Static3D(1,1,1);
|
126 |
|
|
mShearPoint = new Static3D(0,0,0);
|
127 |
|
|
mRotatePoint = new Static4D(0,1,0,0);
|
128 |
|
|
|
129 |
|
|
mMoveInter = new Dynamic3D();
|
130 |
|
|
mScaleInter = new Dynamic3D();
|
131 |
|
|
mShearInter = new Dynamic3D();
|
132 |
|
|
mDynamicRotate= new Dynamic4D();
|
133 |
|
|
|
134 |
427ab7bf
|
Leszek Koltunski
|
mMoveInter.add(mMovePoint);
|
135 |
|
|
mScaleInter.add(mScalePoint);
|
136 |
|
|
mShearInter.add(mShearPoint);
|
137 |
7589635e
|
Leszek Koltunski
|
mDynamicRotate.add(mRotatePoint);
|
138 |
427ab7bf
|
Leszek Koltunski
|
}
|
139 |
|
|
|
140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141 |
|
|
|
142 |
|
|
public void onDrawFrame(GL10 glUnused)
|
143 |
|
|
{
|
144 |
|
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
145 |
|
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
146 |
|
|
|
147 |
|
|
mCube.draw(System.currentTimeMillis());
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
153 |
|
|
{
|
154 |
|
|
setMatrixEffects();
|
155 |
|
|
|
156 |
|
|
Distorted.onSurfaceChanged(width, height);
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160 |
|
|
|
161 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
162 |
|
|
{
|
163 |
|
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
|
164 |
|
|
Bitmap bitmap;
|
165 |
|
|
|
166 |
|
|
try
|
167 |
|
|
{
|
168 |
|
|
bitmap = BitmapFactory.decodeStream(is);
|
169 |
|
|
}
|
170 |
|
|
finally
|
171 |
|
|
{
|
172 |
|
|
try
|
173 |
|
|
{
|
174 |
|
|
is.close();
|
175 |
|
|
}
|
176 |
|
|
catch(IOException e) { }
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
mCube.setBitmap(bitmap);
|
180 |
|
|
|
181 |
|
|
try
|
182 |
|
|
{
|
183 |
ed1c0b33
|
Leszek Koltunski
|
Distorted.onSurfaceCreated(mView.getContext());
|
184 |
427ab7bf
|
Leszek Koltunski
|
}
|
185 |
|
|
catch(Exception ex)
|
186 |
|
|
{
|
187 |
|
|
android.util.Log.e("Quaternion", ex.getMessage() );
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
}
|