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 |
10d53839
|
Leszek Koltunski
|
package org.distorted.examples.projection;
|
21 |
427ab7bf
|
Leszek Koltunski
|
|
22 |
|
|
import javax.microedition.khronos.egl.EGLConfig;
|
23 |
|
|
import javax.microedition.khronos.opengles.GL10;
|
24 |
|
|
|
25 |
5068fa06
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
26 |
d04a4886
|
Leszek Koltunski
|
import org.distorted.library.DistortedEffects;
|
27 |
d218d64e
|
leszek
|
import org.distorted.library.DistortedScreen;
|
28 |
b01acdaf
|
Leszek Koltunski
|
import org.distorted.library.MeshFlat;
|
29 |
f6d884d5
|
Leszek Koltunski
|
import org.distorted.library.DistortedTexture;
|
30 |
7589635e
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
31 |
|
|
import org.distorted.library.type.Static4D;
|
32 |
427ab7bf
|
Leszek Koltunski
|
|
33 |
|
|
import android.graphics.Bitmap;
|
34 |
|
|
import android.graphics.Canvas;
|
35 |
|
|
import android.graphics.Paint;
|
36 |
|
|
import android.graphics.Paint.Style;
|
37 |
41a81a14
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
38 |
427ab7bf
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
|
42 |
10d53839
|
Leszek Koltunski
|
class ProjectionRenderer implements GLSurfaceView.Renderer
|
43 |
427ab7bf
|
Leszek Koltunski
|
{
|
44 |
|
|
private GLSurfaceView mView;
|
45 |
d04a4886
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
46 |
d218d64e
|
leszek
|
private DistortedScreen mScreen;
|
47 |
10d53839
|
Leszek Koltunski
|
|
48 |
af662543
|
leszek
|
private float mF, mNear;
|
49 |
2f9752c5
|
Leszek Koltunski
|
|
50 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
10d53839
|
Leszek Koltunski
|
ProjectionRenderer(GLSurfaceView view)
|
53 |
427ab7bf
|
Leszek Koltunski
|
{
|
54 |
392e16fd
|
Leszek Koltunski
|
mView = view;
|
55 |
d04a4886
|
Leszek Koltunski
|
mEffects= new DistortedEffects();
|
56 |
d218d64e
|
leszek
|
mScreen = new DistortedScreen();
|
57 |
427ab7bf
|
Leszek Koltunski
|
}
|
58 |
|
|
|
59 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
af662543
|
leszek
|
float setFOV(int f)
|
62 |
427ab7bf
|
Leszek Koltunski
|
{
|
63 |
10d53839
|
Leszek Koltunski
|
mF = f;
|
64 |
af662543
|
leszek
|
mScreen.setProjection(mF,mNear);
|
65 |
|
|
return mF;
|
66 |
427ab7bf
|
Leszek Koltunski
|
}
|
67 |
10d53839
|
Leszek Koltunski
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
af662543
|
leszek
|
float setNear(int near)
|
71 |
10d53839
|
Leszek Koltunski
|
{
|
72 |
af662543
|
leszek
|
mNear = near/100.0f;
|
73 |
|
|
mScreen.setProjection(mF,mNear);
|
74 |
|
|
return mNear;
|
75 |
10d53839
|
Leszek Koltunski
|
}
|
76 |
|
|
|
77 |
427ab7bf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
|
|
public void onDrawFrame(GL10 glUnused)
|
80 |
|
|
{
|
81 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
82 |
fe59d375
|
Leszek Koltunski
|
mScreen.render( System.currentTimeMillis() );
|
83 |
427ab7bf
|
Leszek Koltunski
|
}
|
84 |
|
|
|
85 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
|
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
88 |
10d53839
|
Leszek Koltunski
|
{
|
89 |
af662543
|
leszek
|
mScreen.setProjection(mF,mNear);
|
90 |
392e16fd
|
Leszek Koltunski
|
mEffects.abortAllEffects();
|
91 |
95bc9f69
|
Leszek Koltunski
|
|
92 |
2f9752c5
|
Leszek Koltunski
|
Paint paint = new Paint();
|
93 |
fe59d375
|
Leszek Koltunski
|
DistortedTexture texture= new DistortedTexture(width,height);
|
94 |
|
|
MeshFlat mesh = new MeshFlat(50,50*height/width);
|
95 |
f6d884d5
|
Leszek Koltunski
|
Bitmap bmp = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);
|
96 |
10d53839
|
Leszek Koltunski
|
Canvas bmpCanvas = new Canvas(bmp);
|
97 |
427ab7bf
|
Leszek Koltunski
|
|
98 |
2f9752c5
|
Leszek Koltunski
|
paint.setColor(0xff008800);
|
99 |
|
|
paint.setStyle(Style.FILL);
|
100 |
f6d884d5
|
Leszek Koltunski
|
bmpCanvas.drawRect(0, 0, width, height, paint);
|
101 |
2f9752c5
|
Leszek Koltunski
|
paint.setColor(0xffffffff);
|
102 |
10d53839
|
Leszek Koltunski
|
|
103 |
|
|
final int NUMLINES = 10;
|
104 |
|
|
|
105 |
427ab7bf
|
Leszek Koltunski
|
for(int i=0; i<=NUMLINES ; i++ )
|
106 |
|
|
{
|
107 |
f6d884d5
|
Leszek Koltunski
|
bmpCanvas.drawRect(width*i/NUMLINES - 1, 0, width*i/NUMLINES + 1, height , paint);
|
108 |
|
|
bmpCanvas.drawRect( 0, height*i/NUMLINES -1, width , height*i/NUMLINES + 1, paint);
|
109 |
427ab7bf
|
Leszek Koltunski
|
}
|
110 |
f6d884d5
|
Leszek Koltunski
|
|
111 |
fe59d375
|
Leszek Koltunski
|
texture.setTexture(bmp);
|
112 |
f6d884d5
|
Leszek Koltunski
|
|
113 |
|
|
int min = width<height ? width:height;
|
114 |
|
|
|
115 |
7bf107f7
|
Leszek Koltunski
|
Static3D vector = new Static3D(0,0,min/5);
|
116 |
|
|
Static4D region = new Static4D(0,0,min/5,min/5);
|
117 |
|
|
|
118 |
392e16fd
|
Leszek Koltunski
|
mEffects.distort(vector, new Static3D( width/4, height/4, 0), region);
|
119 |
|
|
mEffects.distort(vector, new Static3D(3*width/4, height/4, 0), region);
|
120 |
|
|
mEffects.distort(vector, new Static3D( width/4, 3*height/4, 0), region);
|
121 |
|
|
mEffects.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region);
|
122 |
f6d884d5
|
Leszek Koltunski
|
|
123 |
fe59d375
|
Leszek Koltunski
|
mScreen.detachAll();
|
124 |
|
|
mScreen.attach(texture,mEffects,mesh);
|
125 |
392e16fd
|
Leszek Koltunski
|
mScreen.resize(width, height);
|
126 |
427ab7bf
|
Leszek Koltunski
|
}
|
127 |
|
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
|
130 |
f6d884d5
|
Leszek Koltunski
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
131 |
|
|
{
|
132 |
41a81a14
|
Leszek Koltunski
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
133 |
f6d884d5
|
Leszek Koltunski
|
|
134 |
|
|
try
|
135 |
|
|
{
|
136 |
76f9798b
|
Leszek Koltunski
|
Distorted.onCreate(mView.getContext());
|
137 |
f6d884d5
|
Leszek Koltunski
|
}
|
138 |
|
|
catch(Exception ex)
|
139 |
|
|
{
|
140 |
|
|
android.util.Log.e("Projection", ex.getMessage() );
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
427ab7bf
|
Leszek Koltunski
|
}
|