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