1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.fov;
|
21
|
|
22
|
import javax.microedition.khronos.egl.EGLConfig;
|
23
|
import javax.microedition.khronos.opengles.GL10;
|
24
|
|
25
|
import org.distorted.library.Distorted;
|
26
|
import org.distorted.library.DistortedBitmap;
|
27
|
import org.distorted.library.type.Static2D;
|
28
|
import org.distorted.library.type.Static3D;
|
29
|
import org.distorted.library.type.Static4D;
|
30
|
|
31
|
import android.graphics.Bitmap;
|
32
|
import android.graphics.Canvas;
|
33
|
import android.graphics.Paint;
|
34
|
import android.graphics.Paint.Style;
|
35
|
import android.opengl.GLES20;
|
36
|
import android.opengl.GLSurfaceView;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
class FOVRenderer implements GLSurfaceView.Renderer
|
41
|
{
|
42
|
private static final int NUMLINES = 10;
|
43
|
|
44
|
private GLSurfaceView mView;
|
45
|
private DistortedBitmap fov;
|
46
|
private Paint mPaint;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public FOVRenderer(GLSurfaceView view)
|
51
|
{
|
52
|
mView = view;
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
public static void setFOV(int fov)
|
58
|
{
|
59
|
Distorted.setFov(fov);
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
public void onDrawFrame(GL10 glUnused)
|
65
|
{
|
66
|
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
67
|
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
|
68
|
|
69
|
fov.draw(System.currentTimeMillis());
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
75
|
{
|
76
|
Distorted.onSurfaceChanged(width, height);
|
77
|
setupBitmap(width,height);
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
83
|
{
|
84
|
try
|
85
|
{
|
86
|
Distorted.onSurfaceCreated(mView.getContext());
|
87
|
}
|
88
|
catch(Exception ex)
|
89
|
{
|
90
|
android.util.Log.e("FOV", ex.getMessage() );
|
91
|
}
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
private void setupBitmap(int w, int h)
|
97
|
{
|
98
|
mPaint = new Paint();
|
99
|
fov = new DistortedBitmap(w,h, 50);
|
100
|
Bitmap fovBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
|
101
|
Canvas fovCanvas = new Canvas(fovBitmap);
|
102
|
|
103
|
mPaint.setColor(0xff008800);
|
104
|
mPaint.setStyle(Style.FILL);
|
105
|
fovCanvas.drawRect(0, 0, w, h, mPaint);
|
106
|
mPaint.setColor(0xffffffff);
|
107
|
|
108
|
for(int i=0; i<=NUMLINES ; i++ )
|
109
|
{
|
110
|
fovCanvas.drawRect(w*i/NUMLINES - 1, 0, w*i/NUMLINES + 1, h , mPaint);
|
111
|
fovCanvas.drawRect( 0, h *i/NUMLINES -1, w , h*i/NUMLINES + 1, mPaint);
|
112
|
}
|
113
|
|
114
|
fov.setBitmap(fovBitmap);
|
115
|
|
116
|
int min = w<h ? w:h;
|
117
|
|
118
|
Static3D vector = new Static3D(0,0,min/5);
|
119
|
Static4D region = new Static4D(0,0,min/5,min/5);
|
120
|
|
121
|
fov.distort(vector, new Static2D( w/4, h/4), region);
|
122
|
fov.distort(vector, new Static2D(3*w/4, h/4), region);
|
123
|
fov.distort(vector, new Static2D( w/4, 3*h/4), region);
|
124
|
fov.distort(vector, new Static2D(3*w/4, 3*h/4), region);
|
125
|
}
|
126
|
|
127
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
|
129
|
}
|