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