1 |
77a500b3
|
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.inflate;
|
21 |
|
|
|
22 |
|
|
import android.opengl.GLSurfaceView;
|
23 |
|
|
|
24 |
|
|
import org.distorted.library.effect.MatrixEffectMove;
|
25 |
|
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
26 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
27 |
|
|
import org.distorted.library.main.Distorted;
|
28 |
|
|
import org.distorted.library.main.DistortedEffects;
|
29 |
|
|
import org.distorted.library.main.DistortedScreen;
|
30 |
|
|
import org.distorted.library.main.DistortedTexture;
|
31 |
|
|
import org.distorted.library.mesh.MeshBase;
|
32 |
|
|
import org.distorted.library.type.DynamicQuat;
|
33 |
|
|
import org.distorted.library.type.Static3D;
|
34 |
|
|
import org.distorted.library.type.Static4D;
|
35 |
|
|
|
36 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
37 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
38 |
|
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
|
|
class InflateRenderer implements GLSurfaceView.Renderer
|
42 |
|
|
{
|
43 |
0579fe3a
|
Leszek Koltunski
|
private static final float FOV = 30.0f;
|
44 |
|
|
private static final float NEAR = 0.1f;
|
45 |
|
|
|
46 |
77a500b3
|
Leszek Koltunski
|
private GLSurfaceView mView;
|
47 |
|
|
private DistortedTexture mTexture;
|
48 |
|
|
private DistortedEffects mEffects;
|
49 |
|
|
private MeshBase mMesh;
|
50 |
|
|
private DistortedScreen mScreen;
|
51 |
|
|
private int mObjWidth, mObjHeight, mObjDepth;
|
52 |
|
|
private Static3D mMove, mScale, mCenter;
|
53 |
|
|
|
54 |
|
|
Static4D mQuat1, mQuat2;
|
55 |
|
|
int mScreenMin;
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
|
|
InflateRenderer(GLSurfaceView v)
|
60 |
|
|
{
|
61 |
|
|
mView = v;
|
62 |
|
|
|
63 |
|
|
mMove = new Static3D(0,0,0);
|
64 |
|
|
mScale= new Static3D(1,1,1);
|
65 |
|
|
mCenter=new Static3D(0,0,0);
|
66 |
|
|
|
67 |
|
|
InflateActivity2 act = (InflateActivity2)v.getContext();
|
68 |
|
|
|
69 |
|
|
mTexture = act.getTexture();
|
70 |
|
|
mMesh = act.getMesh();
|
71 |
|
|
|
72 |
|
|
mObjWidth = mTexture.getWidth();
|
73 |
|
|
mObjHeight= mTexture.getHeight();
|
74 |
|
|
mObjDepth = mTexture.getDepth(mMesh);
|
75 |
|
|
|
76 |
|
|
mQuat1 = new Static4D(0,0,0,1); // unity
|
77 |
|
|
mQuat2 = new Static4D(0,0,0,1); // quaternions
|
78 |
|
|
|
79 |
|
|
DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
|
80 |
|
|
DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
|
81 |
|
|
|
82 |
|
|
quatInt1.add(mQuat1);
|
83 |
|
|
quatInt2.add(mQuat2);
|
84 |
|
|
|
85 |
|
|
mEffects = new DistortedEffects();
|
86 |
|
|
mEffects.apply( new MatrixEffectMove(mMove) );
|
87 |
|
|
mEffects.apply( new MatrixEffectScale(mScale));
|
88 |
|
|
mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
|
89 |
|
|
mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
|
90 |
|
|
|
91 |
|
|
mScreen = new DistortedScreen();
|
92 |
|
|
mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
|
93 |
0579fe3a
|
Leszek Koltunski
|
mScreen.setProjection(FOV, NEAR);
|
94 |
77a500b3
|
Leszek Koltunski
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
|
98 |
|
|
public void onDrawFrame(GL10 glUnused)
|
99 |
|
|
{
|
100 |
|
|
mScreen.render( System.currentTimeMillis() );
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
106 |
|
|
{
|
107 |
24624a1a
|
Leszek Koltunski
|
final float SCALE = 0.75f;
|
108 |
|
|
|
109 |
77a500b3
|
Leszek Koltunski
|
mScreenMin = width<height ? width:height;
|
110 |
24624a1a
|
Leszek Koltunski
|
float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight : (SCALE*width)/mObjWidth;
|
111 |
77a500b3
|
Leszek Koltunski
|
mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
|
112 |
|
|
mScale.set(factor,factor,factor);
|
113 |
b424b062
|
Leszek Koltunski
|
mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, (float)mObjDepth/2 );
|
114 |
77a500b3
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
|
|
|
119 |
|
|
float setLevel(int level)
|
120 |
|
|
{
|
121 |
|
|
float inflateLevel = (level-50)/50.0f;
|
122 |
|
|
mMesh.setInflate(inflateLevel);
|
123 |
|
|
|
124 |
|
|
return inflateLevel;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128 |
|
|
|
129 |
|
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
130 |
|
|
{
|
131 |
|
|
InflateActivity2 act = (InflateActivity2)mView.getContext();
|
132 |
|
|
|
133 |
|
|
mTexture.setTexture( act.getBitmap() );
|
134 |
|
|
|
135 |
|
|
mScreen.detachAll();
|
136 |
|
|
mScreen.attach(mTexture,mEffects,mMesh);
|
137 |
|
|
|
138 |
|
|
try
|
139 |
|
|
{
|
140 |
|
|
Distorted.onCreate(mView.getContext());
|
141 |
|
|
}
|
142 |
|
|
catch(Exception ex)
|
143 |
|
|
{
|
144 |
|
|
android.util.Log.e("Inflate", ex.getMessage() );
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
|
|
}
|