Revision 03a2fd30
Added by Leszek Koltunski almost 8 years ago
src/main/AndroidManifest.xml | ||
---|---|---|
42 | 42 |
<activity android:name=".flag.FlagActivity"/> |
43 | 43 |
<activity android:name=".wind.WindActivity"/> |
44 | 44 |
<activity android:name=".aroundtheworld.AroundTheWorldActivity"/> |
45 |
<activity android:name=".mirror.MirrorActivity"/> |
|
45 | 46 |
</application> |
46 | 47 |
</manifest> |
src/main/java/org/distorted/examples/TableOfContents.java | ||
---|---|---|
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.mirror.MirrorActivity; |
|
63 | 64 |
|
64 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 66 |
|
... | ... | |
316 | 317 |
activityMapping.put(i++, AroundTheWorldActivity.class); |
317 | 318 |
} |
318 | 319 |
|
320 |
{ |
|
321 |
final Map<String, Object> item = new HashMap<>(); |
|
322 |
item.put(ITEM_IMAGE, R.drawable.icon_example_mirror); |
|
323 |
item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_mirror)); |
|
324 |
item.put(ITEM_SUBTITLE, getText(R.string.example_mirror_subtitle)); |
|
325 |
data.add(item); |
|
326 |
activityMapping.put(i++, MirrorActivity.class); |
|
327 |
} |
|
328 |
|
|
319 | 329 |
final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle}); |
320 | 330 |
setListAdapter(dataAdapter); |
321 | 331 |
|
src/main/java/org/distorted/examples/mirror/MirrorActivity.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.mirror; |
|
21 |
|
|
22 |
import android.app.Activity; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.widget.SeekBar; |
|
26 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
|
27 |
|
|
28 |
import org.distorted.examples.R; |
|
29 |
import org.distorted.library.Distorted; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public class MirrorActivity extends Activity implements OnSeekBarChangeListener |
|
34 |
{ |
|
35 |
@Override |
|
36 |
protected void onCreate(Bundle icicle) |
|
37 |
{ |
|
38 |
super.onCreate(icicle); |
|
39 |
setContentView(R.layout.mirrorlayout); |
|
40 |
|
|
41 |
SeekBar bar = (SeekBar)findViewById(R.id.mirrorSeek); |
|
42 |
bar.setOnSeekBarChangeListener(this); |
|
43 |
bar.setProgress(100); |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void onPause() |
|
50 |
{ |
|
51 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.mirrorSurfaceView); |
|
52 |
view.onPause(); |
|
53 |
super.onPause(); |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
@Override |
|
59 |
protected void onResume() |
|
60 |
{ |
|
61 |
super.onResume(); |
|
62 |
MirrorSurfaceView view = (MirrorSurfaceView) this.findViewById(R.id.mirrorSurfaceView); |
|
63 |
view.onResume(); |
|
64 |
view.getRenderer().onResume(); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
@Override |
|
70 |
protected void onDestroy() |
|
71 |
{ |
|
72 |
Distorted.onDestroy(); |
|
73 |
super.onDestroy(); |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
79 |
{ |
|
80 |
switch (bar.getId()) |
|
81 |
{ |
|
82 |
case R.id.mirrorSeek: MirrorSurfaceView view = (MirrorSurfaceView) this.findViewById(R.id.mirrorSurfaceView); |
|
83 |
view.getRenderer().setPosition(progress); |
|
84 |
break; |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
} |
src/main/java/org/distorted/examples/mirror/MirrorRenderer.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.mirror; |
|
21 |
|
|
22 |
import android.graphics.Bitmap; |
|
23 |
import android.graphics.BitmapFactory; |
|
24 |
import android.opengl.GLES20; |
|
25 |
import android.opengl.GLSurfaceView; |
|
26 |
|
|
27 |
import org.distorted.examples.R; |
|
28 |
import org.distorted.library.Distorted; |
|
29 |
import org.distorted.library.DistortedEffects; |
|
30 |
import org.distorted.library.DistortedFramebuffer; |
|
31 |
import org.distorted.library.DistortedTexture; |
|
32 |
import org.distorted.library.GridFlat; |
|
33 |
import org.distorted.library.type.Dynamic3D; |
|
34 |
import org.distorted.library.type.Static3D; |
|
35 |
|
|
36 |
import java.io.IOException; |
|
37 |
import java.io.InputStream; |
|
38 |
|
|
39 |
import javax.microedition.khronos.egl.EGLConfig; |
|
40 |
import javax.microedition.khronos.opengles.GL10; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
class MirrorRenderer implements GLSurfaceView.Renderer |
|
45 |
{ |
|
46 |
private static final float SCALE = 0.5f; |
|
47 |
|
|
48 |
private GLSurfaceView mView; |
|
49 |
private DistortedEffects mEffectsMirror, mEffectsGirl, mEffectsOffscreen, mEffectsNull; |
|
50 |
private DistortedTexture mTextureMirror, mTextureGirl; |
|
51 |
private DistortedFramebuffer mScreen, mOffScreen1, mOffScreen2; |
|
52 |
private GridFlat mQuad; |
|
53 |
private Static3D mGirlPosition; |
|
54 |
private Dynamic3D mGirlDyn; |
|
55 |
|
|
56 |
private int mMirrorW, mMirrorH, mGirlW, mGirlH; |
|
57 |
private int mScreenW, mScreenH; |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
MirrorRenderer(GLSurfaceView view) |
|
62 |
{ |
|
63 |
mView = view; |
|
64 |
mQuad = new GridFlat(1,1); |
|
65 |
mScreen = new DistortedFramebuffer(0); |
|
66 |
|
|
67 |
mEffectsMirror = new DistortedEffects(); |
|
68 |
mEffectsGirl = new DistortedEffects(); |
|
69 |
mEffectsOffscreen= new DistortedEffects(); |
|
70 |
mEffectsNull = new DistortedEffects(); |
|
71 |
|
|
72 |
mGirlPosition = new Static3D(0,0,0); |
|
73 |
mGirlDyn = new Dynamic3D(); |
|
74 |
mGirlDyn.add(mGirlPosition); |
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
void setPosition(int pos) |
|
80 |
{ |
|
81 |
mGirlPosition.set1(pos*mScreenW / 100.0f); |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
public void onResume() |
|
87 |
{ |
|
88 |
mScreenW = 0; |
|
89 |
mScreenH = 0; |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void onDrawFrame(GL10 glUnused) |
|
95 |
{ |
|
96 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
|
97 |
|
|
98 |
long time = System.currentTimeMillis(); |
|
99 |
|
|
100 |
mOffScreen1.renderTo( mTextureMirror, mQuad, mEffectsMirror , time ); |
|
101 |
mOffScreen1.renderTo( mOffScreen2 , mQuad, mEffectsOffscreen, time ); |
|
102 |
mOffScreen1.renderTo( mTextureGirl , mQuad, mEffectsGirl , time ); |
|
103 |
mOffScreen2.renderTo( mOffScreen1 , mQuad, mEffectsNull , time ); |
|
104 |
mScreen.renderTo ( mOffScreen1 , mQuad, mEffectsMirror , time ); |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
110 |
{ |
|
111 |
if( mScreenW!=width || mScreenH!=height) |
|
112 |
{ |
|
113 |
mScreenW = width; |
|
114 |
mScreenH = height; |
|
115 |
|
|
116 |
mOffScreen1 = new DistortedFramebuffer(mScreenW,mScreenH); |
|
117 |
mOffScreen2 = new DistortedFramebuffer( (int)(SCALE*mScreenW), (int)(SCALE*mScreenH) ); |
|
118 |
|
|
119 |
mEffectsGirl.abortAllEffects(); |
|
120 |
mEffectsMirror.abortAllEffects(); |
|
121 |
mEffectsOffscreen.abortAllEffects(); |
|
122 |
|
|
123 |
mEffectsMirror.scale( new Static3D( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f) ); |
|
124 |
mEffectsOffscreen.move( new Static3D( mScreenW/10, mScreenH/10, 0) ); |
|
125 |
mEffectsGirl.move(mGirlDyn); |
|
126 |
mGirlPosition.set2(mScreenH*0.9f); |
|
127 |
|
|
128 |
mScreen.resize(mScreenW,mScreenH); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
135 |
{ |
|
136 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
137 |
|
|
138 |
InputStream isM = mView.getContext().getResources().openRawResource(R.raw.mirror); |
|
139 |
InputStream isG = mView.getContext().getResources().openRawResource(R.raw.face); |
|
140 |
|
|
141 |
Bitmap bitmapM, bitmapG; |
|
142 |
|
|
143 |
try |
|
144 |
{ |
|
145 |
bitmapM = BitmapFactory.decodeStream(isM); |
|
146 |
bitmapG = BitmapFactory.decodeStream(isG); |
|
147 |
} |
|
148 |
finally |
|
149 |
{ |
|
150 |
try |
|
151 |
{ |
|
152 |
isM.close(); |
|
153 |
isG.close(); |
|
154 |
} |
|
155 |
catch(IOException e) { } |
|
156 |
} |
|
157 |
|
|
158 |
mMirrorW = bitmapM.getWidth(); |
|
159 |
mMirrorH = bitmapM.getHeight(); |
|
160 |
mGirlW = bitmapG.getWidth(); |
|
161 |
mGirlH = bitmapG.getHeight(); |
|
162 |
|
|
163 |
mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH); |
|
164 |
mTextureGirl = new DistortedTexture(mGirlW, mGirlH); |
|
165 |
|
|
166 |
mTextureMirror.setTexture(bitmapM); |
|
167 |
mTextureGirl.setTexture(bitmapG); |
|
168 |
|
|
169 |
try |
|
170 |
{ |
|
171 |
Distorted.onSurfaceCreated(mView.getContext()); |
|
172 |
} |
|
173 |
catch(Exception ex) |
|
174 |
{ |
|
175 |
android.util.Log.e("Mirror", ex.getMessage() ); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
src/main/java/org/distorted/examples/mirror/MirrorSurfaceView.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.mirror; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
import android.opengl.GLSurfaceView; |
|
24 |
import android.util.AttributeSet; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
class MirrorSurfaceView extends GLSurfaceView |
|
29 |
{ |
|
30 |
private MirrorRenderer mRenderer; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public MirrorSurfaceView(Context c, AttributeSet attrs) |
|
35 |
{ |
|
36 |
super(c, attrs); |
|
37 |
|
|
38 |
if(!isInEditMode()) |
|
39 |
{ |
|
40 |
setEGLContextClientVersion(2); |
|
41 |
mRenderer = new MirrorRenderer(this); |
|
42 |
setRenderer(mRenderer); |
|
43 |
} |
|
44 |
} |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
public MirrorRenderer getRenderer() |
|
48 |
{ |
|
49 |
return mRenderer; |
|
50 |
} |
|
51 |
} |
|
52 |
|
src/main/res/layout/mirrorlayout.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.mirror.MirrorSurfaceView |
|
8 |
android:id="@+id/mirrorSurfaceView" |
|
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 |
<SeekBar |
|
23 |
android:id="@+id/mirrorSeek" |
|
24 |
android:layout_weight="1" |
|
25 |
android:layout_width="wrap_content" |
|
26 |
android:layout_height="wrap_content" |
|
27 |
android:paddingLeft="10dp" |
|
28 |
android:paddingRight="10dp" /> |
|
29 |
|
|
30 |
</LinearLayout> |
|
31 |
|
|
32 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
124 | 124 |
<string name="example_wind_subtitle">A couple of effects put together to create an effect of a waving flag.</string> |
125 | 125 |
<string name="example_aroundtheworld">Around the World</string> |
126 | 126 |
<string name="example_aroundtheworld_subtitle">Combine several effects to change facial features.</string> |
127 |
<string name="example_mirror">Mirror</string> |
|
128 |
<string name="example_mirror_subtitle">Ping-pong between offscreen buffers to achieve the \'infinite mirror\' effect.</string> |
|
127 | 129 |
|
128 | 130 |
<string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string> |
129 | 131 |
<string name="example_rotate_toast">Rotate the scene by swiping the screen</string> |
Also available in: Unified diff
First attempt at the 'Mirror' app.