Revision 10d53839
Added by Leszek Koltunski almost 8 years ago
src/main/AndroidManifest.xml | ||
---|---|---|
19 | 19 |
<activity android:name=".monalisa.MonaLisaActivity" /> |
20 | 20 |
<activity android:name=".sink.SinkActivity" /> |
21 | 21 |
<activity android:name=".bean.BeanActivity" /> |
22 |
<activity android:name=".fov.FOVActivity" />
|
|
22 |
<activity android:name=".projection.ProjectionActivity" />
|
|
23 | 23 |
<activity android:name=".deform.DeformActivity" /> |
24 | 24 |
<activity android:name=".listener.ListenerActivity" /> |
25 | 25 |
<activity android:name=".dynamic.DynamicActivity" /> |
src/main/java/org/distorted/examples/TableOfContents.java | ||
---|---|---|
37 | 37 |
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity; |
38 | 38 |
import org.distorted.examples.monalisa.MonaLisaActivity; |
39 | 39 |
import org.distorted.examples.sink.SinkActivity; |
40 |
import org.distorted.examples.fov.FOVActivity;
|
|
40 |
import org.distorted.examples.projection.ProjectionActivity;
|
|
41 | 41 |
import org.distorted.examples.deform.DeformActivity; |
42 | 42 |
import org.distorted.examples.listener.ListenerActivity; |
43 | 43 |
import org.distorted.examples.dynamic.DynamicActivity; |
... | ... | |
60 | 60 |
import org.distorted.examples.save.SaveActivity; |
61 | 61 |
import org.distorted.examples.flag.FlagActivity; |
62 | 62 |
import org.distorted.examples.wind.WindActivity; |
63 |
import org.distorted.examples.aroundtheworld.AroundTheWorldActivity; |
|
64 | 63 |
|
65 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
66 | 65 |
|
... | ... | |
112 | 111 |
|
113 | 112 |
{ |
114 | 113 |
final Map<String, Object> item = new HashMap<>(); |
115 |
item.put(ITEM_IMAGE, R.drawable.icon_example_fov);
|
|
116 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fov));
|
|
117 |
item.put(ITEM_SUBTITLE, getText(R.string.example_fov_subtitle));
|
|
114 |
item.put(ITEM_IMAGE, R.drawable.icon_example_projection);
|
|
115 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_projection));
|
|
116 |
item.put(ITEM_SUBTITLE, getText(R.string.example_projection_subtitle));
|
|
118 | 117 |
data.add(item); |
119 |
activityMapping.put(i++, FOVActivity.class);
|
|
118 |
activityMapping.put(i++, ProjectionActivity.class);
|
|
120 | 119 |
} |
121 | 120 |
|
122 | 121 |
{ |
src/main/java/org/distorted/examples/fov/FOVActivity.java | ||
---|---|---|
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 org.distorted.library.Distorted; |
|
23 |
import org.distorted.examples.R; |
|
24 |
|
|
25 |
import android.app.Activity; |
|
26 |
import android.opengl.GLSurfaceView; |
|
27 |
import android.os.Bundle; |
|
28 |
import android.widget.SeekBar; |
|
29 |
import android.widget.TextView; |
|
30 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public class FOVActivity extends Activity implements OnSeekBarChangeListener |
|
35 |
{ |
|
36 |
private TextView textFOV; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
@Override |
|
41 |
protected void onCreate(Bundle icicle) |
|
42 |
{ |
|
43 |
super.onCreate(icicle); |
|
44 |
setContentView(R.layout.fovlayout); |
|
45 |
|
|
46 |
SeekBar barFOV = (SeekBar)findViewById(R.id.seekFOV); |
|
47 |
barFOV.setOnSeekBarChangeListener(this); |
|
48 |
|
|
49 |
textFOV = (TextView)findViewById(R.id.textFOV); |
|
50 |
|
|
51 |
barFOV.setProgress(50); |
|
52 |
|
|
53 |
textFOV.setText("FOV: 50"); |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void onPause() |
|
60 |
{ |
|
61 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.surfaceViewFOV); |
|
62 |
mView.onPause(); |
|
63 |
|
|
64 |
super.onPause(); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
@Override |
|
70 |
protected void onResume() |
|
71 |
{ |
|
72 |
super.onResume(); |
|
73 |
|
|
74 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.surfaceViewFOV); |
|
75 |
mView.onResume(); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
@Override |
|
81 |
protected void onDestroy() |
|
82 |
{ |
|
83 |
Distorted.onDestroy(); |
|
84 |
super.onDestroy(); |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
90 |
{ |
|
91 |
switch (bar.getId()) |
|
92 |
{ |
|
93 |
case R.id.seekFOV: FOVRenderer.setFOV(progress); |
|
94 |
textFOV.setText("FOV: "+progress); |
|
95 |
break; |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
} |
src/main/java/org/distorted/examples/fov/FOVRenderer.java | ||
---|---|---|
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 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
FOVRenderer(GLSurfaceView view) |
|
50 |
{ |
|
51 |
mView = view; |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
static void setFOV(int fov) |
|
57 |
{ |
|
58 |
Distorted.setFov(fov); |
|
59 |
} |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
public void onDrawFrame(GL10 glUnused) |
|
64 |
{ |
|
65 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
|
66 |
fov.draw(System.currentTimeMillis()); |
|
67 |
} |
|
68 |
|
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
72 |
{ |
|
73 |
Distorted.onSurfaceChanged(width, height); |
|
74 |
setupBitmap(width,height); |
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
80 |
{ |
|
81 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
82 |
|
|
83 |
try |
|
84 |
{ |
|
85 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
86 |
} |
|
87 |
catch(Exception ex) |
|
88 |
{ |
|
89 |
android.util.Log.e("FOV", ex.getMessage() ); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
private void setupBitmap(int w, int h) |
|
96 |
{ |
|
97 |
Paint paint = new Paint(); |
|
98 |
fov = new DistortedBitmap(w,h, 50); |
|
99 |
Bitmap fovBitmap = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888); |
|
100 |
Canvas fovCanvas = new Canvas(fovBitmap); |
|
101 |
|
|
102 |
paint.setColor(0xff008800); |
|
103 |
paint.setStyle(Style.FILL); |
|
104 |
fovCanvas.drawRect(0, 0, w, h, paint); |
|
105 |
paint.setColor(0xffffffff); |
|
106 |
|
|
107 |
for(int i=0; i<=NUMLINES ; i++ ) |
|
108 |
{ |
|
109 |
fovCanvas.drawRect(w*i/NUMLINES - 1, 0, w*i/NUMLINES + 1, h , paint); |
|
110 |
fovCanvas.drawRect( 0, h *i/NUMLINES -1, w , h*i/NUMLINES + 1, paint); |
|
111 |
} |
|
112 |
|
|
113 |
fov.setBitmap(fovBitmap); |
|
114 |
|
|
115 |
int min = w<h ? w:h; |
|
116 |
|
|
117 |
Static3D vector = new Static3D(0,0,min/5); |
|
118 |
Static4D region = new Static4D(0,0,min/5,min/5); |
|
119 |
|
|
120 |
fov.distort(vector, new Static3D( w/4, h/4, 0), region); |
|
121 |
fov.distort(vector, new Static3D(3*w/4, h/4, 0), region); |
|
122 |
fov.distort(vector, new Static3D( w/4, 3*h/4, 0), region); |
|
123 |
fov.distort(vector, new Static3D(3*w/4, 3*h/4, 0), region); |
|
124 |
} |
|
125 |
|
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
|
|
128 |
} |
src/main/java/org/distorted/examples/fov/FOVSurfaceView.java | ||
---|---|---|
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 android.content.Context; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.os.Build; |
|
25 |
import android.util.AttributeSet; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class FOVSurfaceView extends GLSurfaceView |
|
30 |
{ |
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public FOVSurfaceView(Context c, AttributeSet attrs) |
|
34 |
{ |
|
35 |
super(c, attrs); |
|
36 |
|
|
37 |
if(!isInEditMode()) |
|
38 |
{ |
|
39 |
setEGLContextClientVersion(2); |
|
40 |
setRenderer(new FOVRenderer(this)); |
|
41 |
} |
|
42 |
} |
|
43 |
} |
|
44 |
|
src/main/java/org/distorted/examples/projection/ProjectionActivity.java | ||
---|---|---|
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.projection; |
|
21 |
|
|
22 |
import org.distorted.library.Distorted; |
|
23 |
import org.distorted.examples.R; |
|
24 |
|
|
25 |
import android.app.Activity; |
|
26 |
import android.opengl.GLSurfaceView; |
|
27 |
import android.os.Bundle; |
|
28 |
import android.widget.SeekBar; |
|
29 |
import android.widget.TextView; |
|
30 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public class ProjectionActivity extends Activity implements OnSeekBarChangeListener |
|
35 |
{ |
|
36 |
private TextView textF, textX, textY; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
@Override |
|
41 |
protected void onCreate(Bundle icicle) |
|
42 |
{ |
|
43 |
super.onCreate(icicle); |
|
44 |
setContentView(R.layout.projectionlayout); |
|
45 |
|
|
46 |
textF = (TextView)findViewById(R.id.projectionTextFOV); |
|
47 |
textX = (TextView)findViewById(R.id.projectionTextX); |
|
48 |
textY = (TextView)findViewById(R.id.projectionTextY); |
|
49 |
|
|
50 |
SeekBar bar; |
|
51 |
|
|
52 |
bar = (SeekBar)findViewById(R.id.projectionSeekFOV); |
|
53 |
bar.setOnSeekBarChangeListener(this); |
|
54 |
bar.setProgress(50); |
|
55 |
bar = (SeekBar)findViewById(R.id.projectionSeekX); |
|
56 |
bar.setOnSeekBarChangeListener(this); |
|
57 |
bar.setProgress(50); |
|
58 |
bar = (SeekBar)findViewById(R.id.projectionSeekY); |
|
59 |
bar.setOnSeekBarChangeListener(this); |
|
60 |
bar.setProgress(50); |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
@Override |
|
66 |
protected void onPause() |
|
67 |
{ |
|
68 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.surfaceViewProjection); |
|
69 |
mView.onPause(); |
|
70 |
|
|
71 |
super.onPause(); |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
@Override |
|
77 |
protected void onResume() |
|
78 |
{ |
|
79 |
super.onResume(); |
|
80 |
|
|
81 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.surfaceViewProjection); |
|
82 |
mView.onResume(); |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
@Override |
|
88 |
protected void onDestroy() |
|
89 |
{ |
|
90 |
Distorted.onDestroy(); |
|
91 |
super.onDestroy(); |
|
92 |
} |
|
93 |
|
|
94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
95 |
|
|
96 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
97 |
{ |
|
98 |
int ret; |
|
99 |
|
|
100 |
switch (bar.getId()) |
|
101 |
{ |
|
102 |
case R.id.projectionSeekFOV: ret = ProjectionRenderer.setFOV(progress); |
|
103 |
textF.setText("FOV: "+ret); |
|
104 |
break; |
|
105 |
case R.id.projectionSeekX : ret = ProjectionRenderer.setX(progress); |
|
106 |
textX.setText("X: "+ret); |
|
107 |
break; |
|
108 |
case R.id.projectionSeekY : ret = ProjectionRenderer.setY(progress); |
|
109 |
textY.setText("Y: "+ret); |
|
110 |
break; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
|
|
116 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
} |
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java | ||
---|---|---|
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.projection; |
|
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.Static3D; |
|
28 |
import org.distorted.library.type.Static4D; |
|
29 |
|
|
30 |
import android.graphics.Bitmap; |
|
31 |
import android.graphics.Canvas; |
|
32 |
import android.graphics.Paint; |
|
33 |
import android.graphics.Paint.Style; |
|
34 |
import android.opengl.GLES20; |
|
35 |
import android.opengl.GLSurfaceView; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
class ProjectionRenderer implements GLSurfaceView.Renderer |
|
40 |
{ |
|
41 |
private GLSurfaceView mView; |
|
42 |
private DistortedBitmap mProjection; |
|
43 |
|
|
44 |
private static float mF, mX, mY; |
|
45 |
private static int mWidth, mHeight; |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
ProjectionRenderer(GLSurfaceView view) |
|
50 |
{ |
|
51 |
mView = view; |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
static int setFOV(int f) |
|
57 |
{ |
|
58 |
mF = f; |
|
59 |
Distorted.setProjection(mF,mX,mY); |
|
60 |
return (int)mF; |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
static int setX(int x) |
|
66 |
{ |
|
67 |
mX = (x-50)*0.01f*mWidth; |
|
68 |
Distorted.setProjection(mF,mX,mY); |
|
69 |
return (int)mX; |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
static int setY(int y) |
|
75 |
{ |
|
76 |
mY = (y-50)*0.01f*mHeight; |
|
77 |
Distorted.setProjection(mF,mX,mY); |
|
78 |
return (int)mY; |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
public void onDrawFrame(GL10 glUnused) |
|
84 |
{ |
|
85 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
|
86 |
mProjection.draw(System.currentTimeMillis()); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
92 |
{ |
|
93 |
mWidth = width; |
|
94 |
mHeight= height; |
|
95 |
|
|
96 |
Distorted.onSurfaceChanged(width, height); |
|
97 |
setupBitmap(width,height); |
|
98 |
} |
|
99 |
|
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
|
|
102 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
103 |
{ |
|
104 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
105 |
|
|
106 |
try |
|
107 |
{ |
|
108 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
109 |
} |
|
110 |
catch(Exception ex) |
|
111 |
{ |
|
112 |
android.util.Log.e("Projection", ex.getMessage() ); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
private void setupBitmap(int w, int h) |
|
119 |
{ |
|
120 |
Paint paint = new Paint(); |
|
121 |
mProjection = new DistortedBitmap(w,h, 50); |
|
122 |
Bitmap bmp = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888); |
|
123 |
Canvas bmpCanvas = new Canvas(bmp); |
|
124 |
|
|
125 |
paint.setColor(0xff008800); |
|
126 |
paint.setStyle(Style.FILL); |
|
127 |
bmpCanvas.drawRect(0, 0, w, h, paint); |
|
128 |
paint.setColor(0xffffffff); |
|
129 |
|
|
130 |
final int NUMLINES = 10; |
|
131 |
|
|
132 |
for(int i=0; i<=NUMLINES ; i++ ) |
|
133 |
{ |
|
134 |
bmpCanvas.drawRect(w*i/NUMLINES - 1, 0, w*i/NUMLINES + 1, h , paint); |
|
135 |
bmpCanvas.drawRect( 0, h *i/NUMLINES -1, w , h*i/NUMLINES + 1, paint); |
|
136 |
} |
|
137 |
|
|
138 |
mProjection.setBitmap(bmp); |
|
139 |
|
|
140 |
int min = w<h ? w:h; |
|
141 |
|
|
142 |
Static3D vector = new Static3D(0,0,min/5); |
|
143 |
Static4D region = new Static4D(0,0,min/5,min/5); |
|
144 |
|
|
145 |
mProjection.distort(vector, new Static3D( w/4, h/4, 0), region); |
|
146 |
mProjection.distort(vector, new Static3D(3*w/4, h/4, 0), region); |
|
147 |
mProjection.distort(vector, new Static3D( w/4, 3*h/4, 0), region); |
|
148 |
mProjection.distort(vector, new Static3D(3*w/4, 3*h/4, 0), region); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
} |
src/main/java/org/distorted/examples/projection/ProjectionSurfaceView.java | ||
---|---|---|
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.projection; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.util.AttributeSet; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
class ProjectionSurfaceView extends GLSurfaceView |
|
29 |
{ |
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public ProjectionSurfaceView(Context c, AttributeSet attrs) |
|
33 |
{ |
|
34 |
super(c, attrs); |
|
35 |
|
|
36 |
if(!isInEditMode()) |
|
37 |
{ |
|
38 |
setEGLContextClientVersion(2); |
|
39 |
setRenderer(new ProjectionRenderer(this)); |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
|
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java | ||
---|---|---|
113 | 113 |
{ |
114 | 114 |
mView = v; |
115 | 115 |
|
116 |
Distorted.setFov(60.0f);
|
|
116 |
Distorted.setProjection(60.0f, 0.0f, 0.0f);
|
|
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/res/layout/fovlayout.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<org.distorted.examples.fov.FOVSurfaceView |
|
8 |
android:id="@+id/surfaceViewFOV" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="0dp" |
|
11 |
android:layout_weight="1" /> |
|
12 |
|
|
13 |
<LinearLayout |
|
14 |
android:id="@+id/linearLayout1" |
|
15 |
android:layout_width="fill_parent" |
|
16 |
android:layout_height="wrap_content" |
|
17 |
android:gravity="center|fill_horizontal" |
|
18 |
android:orientation="horizontal" |
|
19 |
android:paddingBottom="10dp" |
|
20 |
android:paddingTop="10dp" > |
|
21 |
|
|
22 |
<TextView |
|
23 |
android:id="@+id/textFOV" |
|
24 |
android:layout_width="0dp" |
|
25 |
android:layout_height="wrap_content" |
|
26 |
android:layout_weight="0.5" |
|
27 |
android:paddingLeft="15dp" |
|
28 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
29 |
|
|
30 |
<SeekBar |
|
31 |
android:id="@+id/seekFOV" |
|
32 |
android:layout_width="wrap_content" |
|
33 |
android:layout_height="wrap_content" |
|
34 |
android:layout_weight="1" |
|
35 |
android:paddingLeft="15dp" |
|
36 |
android:paddingRight="10dp" /> |
|
37 |
|
|
38 |
</LinearLayout> |
|
39 |
|
|
40 |
</LinearLayout> |
src/main/res/layout/projectionlayout.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<org.distorted.examples.projection.ProjectionSurfaceView |
|
8 |
android:id="@+id/surfaceViewProjection" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="0dp" |
|
11 |
android:layout_weight="1" /> |
|
12 |
|
|
13 |
<LinearLayout |
|
14 |
android:id="@+id/linearLayout1" |
|
15 |
android:layout_width="fill_parent" |
|
16 |
android:layout_height="wrap_content" |
|
17 |
android:gravity="center|fill_horizontal" |
|
18 |
android:orientation="horizontal" |
|
19 |
android:paddingBottom="5dp" |
|
20 |
android:paddingTop="5dp" > |
|
21 |
|
|
22 |
<TextView |
|
23 |
android:id="@+id/projectionTextFOV" |
|
24 |
android:layout_width="0dp" |
|
25 |
android:layout_height="wrap_content" |
|
26 |
android:layout_weight="0.5" |
|
27 |
android:paddingStart="15dp" |
|
28 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
29 |
|
|
30 |
<SeekBar |
|
31 |
android:id="@+id/projectionSeekFOV" |
|
32 |
android:layout_width="wrap_content" |
|
33 |
android:layout_height="wrap_content" |
|
34 |
android:layout_weight="1" |
|
35 |
android:paddingStart="15dp" |
|
36 |
android:paddingEnd="15dp" /> |
|
37 |
</LinearLayout> |
|
38 |
|
|
39 |
<LinearLayout |
|
40 |
android:id="@+id/linearLayout2" |
|
41 |
android:layout_width="fill_parent" |
|
42 |
android:layout_height="wrap_content" |
|
43 |
android:gravity="center|fill_horizontal" |
|
44 |
android:orientation="horizontal" |
|
45 |
android:paddingBottom="5dp" |
|
46 |
android:paddingTop="5dp" > |
|
47 |
|
|
48 |
<TextView |
|
49 |
android:id="@+id/projectionTextX" |
|
50 |
android:layout_width="0dp" |
|
51 |
android:layout_height="wrap_content" |
|
52 |
android:layout_weight="0.5" |
|
53 |
android:paddingStart="15dp" |
|
54 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
55 |
|
|
56 |
<SeekBar |
|
57 |
android:id="@+id/projectionSeekX" |
|
58 |
android:layout_width="wrap_content" |
|
59 |
android:layout_height="wrap_content" |
|
60 |
android:layout_weight="1" |
|
61 |
android:paddingStart="15dp" |
|
62 |
android:paddingEnd="15dp" /> |
|
63 |
</LinearLayout> |
|
64 |
|
|
65 |
<LinearLayout |
|
66 |
android:id="@+id/linearLayout3" |
|
67 |
android:layout_width="fill_parent" |
|
68 |
android:layout_height="wrap_content" |
|
69 |
android:gravity="center|fill_horizontal" |
|
70 |
android:orientation="horizontal" |
|
71 |
android:paddingBottom="5dp" |
|
72 |
android:paddingTop="5dp" > |
|
73 |
|
|
74 |
<TextView |
|
75 |
android:id="@+id/projectionTextY" |
|
76 |
android:layout_width="0dp" |
|
77 |
android:layout_height="wrap_content" |
|
78 |
android:layout_weight="0.5" |
|
79 |
android:paddingStart="15dp" |
|
80 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
81 |
|
|
82 |
<SeekBar |
|
83 |
android:id="@+id/projectionSeekY" |
|
84 |
android:layout_width="wrap_content" |
|
85 |
android:layout_height="wrap_content" |
|
86 |
android:layout_weight="1" |
|
87 |
android:paddingStart="15dp" |
|
88 |
android:paddingEnd="15dp" /> |
|
89 |
</LinearLayout> |
|
90 |
|
|
91 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
64 | 64 |
<string name="example_sink_subtitle">Learn about sinks.</string> |
65 | 65 |
<string name="example_bean">Mr. Bean</string> |
66 | 66 |
<string name="example_bean_subtitle">Interpolation between more than two Points.</string> |
67 |
<string name="example_fov">Field Of View</string>
|
|
68 |
<string name="example_fov_subtitle">Adjust the Projection Matrix.</string>
|
|
67 |
<string name="example_projection">Projection</string>
|
|
68 |
<string name="example_projection_subtitle">Adjust the Projection Matrix.</string>
|
|
69 | 69 |
<string name="example_deform">Deformations and Distortions</string> |
70 | 70 |
<string name="example_deform_subtitle">Deform the whole bitmap or Distort a part of it.</string> |
71 | 71 |
<string name="example_listener">DistortedListener</string> |
Also available in: Unified diff
Turn the former 'FOV' app into 'Projection' app that also checks the (x,y) the camera looks at.