Project

General

Profile

« Previous | Next » 

Revision 427ab7bf

Added by Leszek Koltunski over 8 years ago

  • ID 427ab7bfd394c54407b45b4ae194fa826e9638da
  • Child 5068fa06

Initial commit

View differences:

.gitignore
1
# built application files
2
*.apk
3
*.ap_
4

  
5
# files for the dex VM
6
*.dex
7

  
8
# Java class files
9
*.class
10

  
11
# built native files (uncomment if you build your own)
12
# *.o
13
# *.so
14

  
15
# generated files
16
bin/
17
gen/
18

  
19
# Ignore gradle files
20
.gradle/
21
build/
22

  
23
# Local configuration file (sdk path, etc)
24
local.properties
25

  
26
# Proguard folder generated by Eclipse
27
proguard/
28

  
29
# Eclipse Metadata
30
.metadata/
31

  
32
# Mac OS X clutter
33
*.DS_Store
34

  
35
# Windows clutter
36
Thumbs.db
37

  
38
# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
39
.idea/workspace.xml
40
.idea/tasks.xml
41
.idea/datasources.xml
42
.idea/dataSources.ids
43

  
44
# yes, ignore the .iml
45
*.iml
build.gradle
1
apply plugin: 'com.android.application'
2

  
3
android {
4
    compileSdkVersion 22
5
    buildToolsVersion "23.0.3"
6

  
7
    defaultConfig {
8
        applicationId "org.distortedandroid.examples"
9
        minSdkVersion 15
10
        targetSdkVersion 23
11
    }
12

  
13
    buildTypes {
14
        release {
15
            minifyEnabled false
16
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17
        }
18
    }
19
}
20

  
21
dependencies {
22
    compile project(':distorted-library')
23
}
src/main/AndroidManifest.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
    package="org.distortedandroid.examples"
4
    android:versionCode="1"
5
    android:versionName="1.0" >
6

  
7
    <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="23" />
8
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
9

  
10
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
11
        <activity android:name=".TableOfContents">
12
            <intent-filter>
13
                <action android:name="android.intent.action.MAIN" />
14
                <category android:name="android.intent.category.LAUNCHER" />
15
            </intent-filter>
16
        </activity>
17
        <activity android:name=".monalisa.MonaLisaActivity" />
18
        <activity android:name=".sink.SinkActivity" />
19
        <activity android:name=".bean.BeanActivity" />
20
        <activity android:name=".fov.FOVActivity" />
21
        <activity android:name=".deform.DeformActivity" />    
22
        <activity android:name=".listener.ListenerActivity" />    
23
        <activity android:name=".interpolator.InterpolatorActivity" />   
24
        <activity android:name=".girl.GirlActivity" />   
25
        <activity android:name=".macroblock.MacroblockActivity" /> 
26
        <activity android:name=".movingeffects.MovingEffectsActivity" />    
27
        <activity android:name=".differenteffects.DifferentEffectsActivity" />    
28
        <activity android:name=".differentbitmaps.DifferentBitmapsActivity" />    
29
        <activity android:name=".scratchpad.ScratchpadActivity" />    
30
        <activity android:name=".check.CheckActivity" />    
31
        <activity android:name=".fbo.FBOActivity" />    
32
        <activity android:name=".starwars.StarWarsActivity" />      
33
        <activity android:name=".olimpic.OlimpicActivity" />  
34
        <activity android:name=".cubes.CubesActivity" />       
35
        <activity android:name=".quaternion.QuaternionActivity" />          
36
        <activity android:name=".effects3d.Effects3DActivity" />  
37
    </application>
38
</manifest>
src/main/java/org/distortedandroid/examples/TableOfContents.java
1
package org.distortedandroid.examples;
2

  
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import android.app.Activity;
9
import android.app.ListActivity;
10
import android.content.Intent;
11
import android.os.Bundle;
12
import android.util.SparseArray;
13
import android.view.View;
14
import android.widget.AdapterView;
15
import android.widget.AdapterView.OnItemClickListener;
16
import android.widget.SimpleAdapter;
17

  
18
import org.distortedandroid.examples.R;
19
import org.distortedandroid.examples.monalisa.MonaLisaActivity;
20
import org.distortedandroid.examples.sink.SinkActivity;
21
import org.distortedandroid.examples.fov.FOVActivity;
22
import org.distortedandroid.examples.deform.DeformActivity;
23
import org.distortedandroid.examples.listener.ListenerActivity;
24
import org.distortedandroid.examples.interpolator.InterpolatorActivity;
25
import org.distortedandroid.examples.girl.GirlActivity;
26
import org.distortedandroid.examples.macroblock.MacroblockActivity;
27
import org.distortedandroid.examples.movingeffects.MovingEffectsActivity;
28
import org.distortedandroid.examples.olimpic.OlimpicActivity;
29
import org.distortedandroid.examples.differenteffects.DifferentEffectsActivity;
30
import org.distortedandroid.examples.differentbitmaps.DifferentBitmapsActivity;
31
import org.distortedandroid.examples.scratchpad.ScratchpadActivity;
32
import org.distortedandroid.examples.check.CheckActivity;
33
import org.distortedandroid.examples.bean.BeanActivity;
34
import org.distortedandroid.examples.fbo.FBOActivity;
35
import org.distortedandroid.examples.starwars.StarWarsActivity;
36
import org.distortedandroid.examples.cubes.CubesActivity;
37
import org.distortedandroid.examples.quaternion.QuaternionActivity;
38
import org.distortedandroid.examples.effects3d.Effects3DActivity;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
public class TableOfContents extends ListActivity 
43
  {
44
  private static final String ITEM_IMAGE = "item_image";
45
  private static final String ITEM_TITLE = "item_title";
46
  private static final String ITEM_SUBTITLE = "item_subtitle"; 
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
   
50
  @Override
51
  public void onCreate(Bundle savedInstanceState) 
52
   {
53
   super.onCreate(savedInstanceState);
54
   setTitle(R.string.toc);
55
   setContentView(R.layout.table_of_contents);
56
      
57
   final List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
58
   final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<Class<? extends Activity>>();
59
      
60
   int i = 0;
61
   
62
   {
63
      final Map<String, Object> item = new HashMap<String, Object>();
64
      item.put(ITEM_IMAGE, R.drawable.icon_example_monalisa);
65
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_monalisa));
66
      item.put(ITEM_SUBTITLE, getText(R.string.example_monalisa_subtitle));
67
      data.add(item);
68
      activityMapping.put(i++, MonaLisaActivity.class);        
69
   }
70
      
71
   {
72
      final Map<String, Object> item = new HashMap<String, Object>();
73
      item.put(ITEM_IMAGE, R.drawable.icon_example_sink);
74
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_sink));
75
      item.put(ITEM_SUBTITLE, getText(R.string.example_sink_subtitle));
76
      data.add(item);
77
      activityMapping.put(i++, SinkActivity.class);
78
   }
79
   
80
   {
81
      final Map<String, Object> item = new HashMap<String, Object>();
82
      item.put(ITEM_IMAGE, R.drawable.icon_example_bean);
83
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_bean));
84
      item.put(ITEM_SUBTITLE, getText(R.string.example_bean_subtitle));
85
      data.add(item);
86
      activityMapping.put(i++, BeanActivity.class);
87
   }
88
   
89
   {
90
      final Map<String, Object> item = new HashMap<String, Object>();
91
      item.put(ITEM_IMAGE, R.drawable.icon_example_fov);
92
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fov));
93
      item.put(ITEM_SUBTITLE, getText(R.string.example_fov_subtitle));
94
      data.add(item);
95
      activityMapping.put(i++, FOVActivity.class);
96
   }
97
         
98
   {
99
      final Map<String, Object> item = new HashMap<String, Object>();
100
      item.put(ITEM_IMAGE, R.drawable.icon_example_deform);
101
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_deform));
102
      item.put(ITEM_SUBTITLE, getText(R.string.example_deform_subtitle));
103
      data.add(item);
104
      activityMapping.put(i++, DeformActivity.class);
105
   }
106
  
107
   {
108
      final Map<String, Object> item = new HashMap<String, Object>();
109
      item.put(ITEM_IMAGE, R.drawable.icon_example_listener);
110
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_listener));
111
      item.put(ITEM_SUBTITLE, getText(R.string.example_listener_subtitle));
112
      data.add(item);
113
      activityMapping.put(i++, ListenerActivity.class);
114
   }
115
   
116
   {
117
      final Map<String, Object> item = new HashMap<String, Object>();
118
      item.put(ITEM_IMAGE, R.drawable.icon_example_interpolator);
119
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_interpolator));
120
      item.put(ITEM_SUBTITLE, getText(R.string.example_interpolator_subtitle));
121
      data.add(item);
122
      activityMapping.put(i++, InterpolatorActivity.class);
123
   }
124
   
125
   {
126
      final Map<String, Object> item = new HashMap<String, Object>();
127
      item.put(ITEM_IMAGE, R.drawable.icon_example_girl);
128
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_girl));
129
      item.put(ITEM_SUBTITLE, getText(R.string.example_girl_subtitle));
130
      data.add(item);
131
      activityMapping.put(i++, GirlActivity.class);
132
   }
133
   
134
   {
135
      final Map<String, Object> item = new HashMap<String, Object>();
136
      item.put(ITEM_IMAGE, R.drawable.icon_example_macroblock);
137
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_macroblock));
138
      item.put(ITEM_SUBTITLE, getText(R.string.example_macroblock_subtitle));
139
      data.add(item);
140
      activityMapping.put(i++, MacroblockActivity.class);
141
   }
142
   
143
   {
144
      final Map<String, Object> item = new HashMap<String, Object>();
145
      item.put(ITEM_IMAGE, R.drawable.icon_example_movingeffects);
146
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_movingeffects));
147
      item.put(ITEM_SUBTITLE, getText(R.string.example_movingeffects_subtitle));
148
      data.add(item);
149
      activityMapping.put(i++, MovingEffectsActivity.class);
150
   }
151
   
152
   {
153
      final Map<String, Object> item = new HashMap<String, Object>();
154
      item.put(ITEM_IMAGE, R.drawable.icon_example_differenteffects);
155
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differenteffects));
156
      item.put(ITEM_SUBTITLE, getText(R.string.example_differenteffects_subtitle));
157
      data.add(item);
158
      activityMapping.put(i++, DifferentEffectsActivity.class);
159
   }
160
   
161
   {
162
      final Map<String, Object> item = new HashMap<String, Object>();
163
      item.put(ITEM_IMAGE, R.drawable.icon_example_differentbitmaps);
164
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_differentbitmaps));
165
      item.put(ITEM_SUBTITLE, getText(R.string.example_differentbitmaps_subtitle));
166
      data.add(item);
167
      activityMapping.put(i++, DifferentBitmapsActivity.class);
168
   }
169
   
170
   {
171
      final Map<String, Object> item = new HashMap<String, Object>();
172
      item.put(ITEM_IMAGE, R.drawable.icon_example_scratchpad);
173
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_scratchpad));
174
      item.put(ITEM_SUBTITLE, getText(R.string.example_scratchpad_subtitle));
175
      data.add(item);
176
      activityMapping.put(i++, ScratchpadActivity.class);
177
   }
178
   
179
   {
180
      final Map<String, Object> item = new HashMap<String, Object>();
181
      item.put(ITEM_IMAGE, R.drawable.icon_example_check);
182
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_check));
183
      item.put(ITEM_SUBTITLE, getText(R.string.example_check_subtitle));
184
      data.add(item);
185
      activityMapping.put(i++, CheckActivity.class);
186
   }
187
   
188
   {
189
      final Map<String, Object> item = new HashMap<String, Object>();
190
      item.put(ITEM_IMAGE, R.drawable.icon_example_fbo);
191
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_fbo));
192
      item.put(ITEM_SUBTITLE, getText(R.string.example_fbo_subtitle));
193
      data.add(item);
194
      activityMapping.put(i++, FBOActivity.class);
195
   }
196
      
197
   {
198
      final Map<String, Object> item = new HashMap<String, Object>();
199
      item.put(ITEM_IMAGE, R.drawable.icon_example_starwars);
200
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_starwars));
201
      item.put(ITEM_SUBTITLE, getText(R.string.example_starwars_subtitle));
202
      data.add(item);
203
      activityMapping.put(i++, StarWarsActivity.class);
204
   }
205
         
206
   {
207
      final Map<String, Object> item = new HashMap<String, Object>();
208
      item.put(ITEM_IMAGE, R.drawable.icon_example_olimpic);
209
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_olimpic));
210
      item.put(ITEM_SUBTITLE, getText(R.string.example_olimpic_subtitle));
211
      data.add(item);
212
      activityMapping.put(i++, OlimpicActivity.class);
213
   }
214
   
215
   {
216
      final Map<String, Object> item = new HashMap<String, Object>();
217
      item.put(ITEM_IMAGE, R.drawable.icon_example_quaternion);
218
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_quaternion));
219
      item.put(ITEM_SUBTITLE, getText(R.string.example_quaternion_subtitle));
220
      data.add(item);
221
      activityMapping.put(i++, QuaternionActivity.class);
222
   }
223
   
224
   {
225
      final Map<String, Object> item = new HashMap<String, Object>();
226
      item.put(ITEM_IMAGE, R.drawable.icon_example_cubes);
227
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_cubes));
228
      item.put(ITEM_SUBTITLE, getText(R.string.example_cubes_subtitle));
229
      data.add(item);
230
      activityMapping.put(i++, CubesActivity.class);
231
   }
232
   
233
   {
234
      final Map<String, Object> item = new HashMap<String, Object>();
235
      item.put(ITEM_IMAGE, R.drawable.icon_example_matrix3d);
236
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects3d));
237
      item.put(ITEM_SUBTITLE, getText(R.string.example_effects3d_subtitle));
238
      data.add(item);
239
      activityMapping.put(i++, Effects3DActivity.class);
240
   }
241
     
242
   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});
243
   setListAdapter(dataAdapter);  
244
      
245
   getListView().setOnItemClickListener(new OnItemClickListener() 
246
     {
247
     @Override
248
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
249
      {
250
      final Class<? extends Activity> activityToLaunch = activityMapping.get(position);
251
            
252
      if (activityToLaunch != null)
253
        {
254
        final Intent launchIntent = new Intent(TableOfContents.this, activityToLaunch);
255
        startActivity(launchIntent);
256
        }            
257
      }
258
     });
259
   }  
260
  }
261

  
262
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distortedandroid/examples/bean/BeanActivity.java
1

  
2
package org.distortedandroid.examples.bean;
3

  
4
import org.distortedandroid.library.Distorted;
5

  
6
import android.app.Activity;
7
import android.os.Bundle;
8

  
9
///////////////////////////////////////////////////////////////////////////////////////////////////
10

  
11
public class BeanActivity extends Activity 
12
{
13
    private BeanSurfaceView mView;
14

  
15
///////////////////////////////////////////////////////////////////////////////////////////////////
16
    
17
    @Override
18
    protected void onCreate(Bundle icicle) 
19
      {
20
      super.onCreate(icicle);
21
      mView = new BeanSurfaceView(this);
22
      setContentView(mView);
23
      }
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26
    
27
    @Override
28
    protected void onPause() 
29
      {
30
      mView.onPause();  
31
      super.onPause();
32
      }
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
    
36
    @Override
37
    protected void onResume() 
38
      {
39
      super.onResume();
40
      mView.onResume();
41
      }
42
    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
    
45
    @Override
46
    protected void onDestroy() 
47
      {
48
      Distorted.onDestroy();  
49
      super.onDestroy();
50
      }
51
    
52
}
src/main/java/org/distortedandroid/examples/bean/BeanRenderer.java
1

  
2
package org.distortedandroid.examples.bean;
3

  
4
import java.io.IOException;
5
import java.io.InputStream;
6

  
7
import javax.microedition.khronos.egl.EGLConfig;
8
import javax.microedition.khronos.opengles.GL10;
9

  
10
import org.distortedandroid.examples.R;
11

  
12
import org.distortedandroid.library.Interpolator2D;
13
import org.distortedandroid.library.Distorted;
14
import org.distortedandroid.library.DistortedBitmap;
15
import org.distortedandroid.library.Float2D;
16
import org.distortedandroid.library.Float4D;
17

  
18
import android.graphics.Bitmap;
19
import android.graphics.BitmapFactory;
20
import android.opengl.GLES20;
21
import android.opengl.GLSurfaceView;
22

  
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

  
25
class BeanRenderer implements GLSurfaceView.Renderer 
26
{
27
   private GLSurfaceView mView;
28
   private DistortedBitmap mBean;
29
   private Float2D pLeft, pRight;
30
   private Interpolator2D iLeft, iRight;
31
   private Float4D rLeft, rRight;
32
   private int bmpHeight, bmpWidth;
33
    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
   public BeanRenderer(GLSurfaceView v) 
37
      {
38
      mView = v;
39
     
40
      pLeft = new Float2D(100, 199);
41
      pRight= new Float2D(230, 150);
42
      
43
      rLeft = new Float4D(-9,-31,35,35);
44
      rRight= new Float4D(-9,-31,35,35);
45
     
46
      iLeft = new Interpolator2D();
47
      iRight= new Interpolator2D();
48
     
49
      iLeft.setCount(0.0f);
50
      iRight.setCount(0.0f);
51
      iLeft.setDuration(1500);
52
      iRight.setDuration(1500);
53
      
54
      Float2D p1 = new Float2D(0,0);
55
      Float2D p2 = new Float2D(-10,-34);
56
      
57
      iLeft.add(p1);
58
      iLeft.add(p1);
59
      iLeft.add(p1);
60
      iLeft.add(p1);
61
      iLeft.add(p2);
62
      iLeft.add(p2);
63
      
64
      iRight.add(p1);
65
      iRight.add(p2);
66
      iRight.add(p2);
67
      iRight.add(p1);
68
      iRight.add(p1);
69
      iRight.add(p1);
70
      }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
   
74
    public void onDrawFrame(GL10 glUnused) 
75
      {
76
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
77
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
78
      
79
      mBean.draw(System.currentTimeMillis());
80
      }
81

  
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
    
84
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
85
      { 
86
      mBean.abortAllEffects(Distorted.TYPE_MATR);  
87
         
88
      if( bmpHeight/bmpWidth > height/width )
89
        {
90
        int w = (height*bmpWidth)/bmpHeight;
91
        mBean.move((width-w)/2 ,0, 0);
92
        mBean.scale((float)height/bmpHeight);
93
        }
94
      else
95
        {
96
        int h = (width*bmpHeight)/bmpWidth;
97
        mBean.move(0 ,(height-h)/2, 0);
98
        mBean.scale((float)width/bmpWidth);
99
        }
100
      
101
      Distorted.onSurfaceChanged(width, height); 
102
      }
103

  
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
    
106
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
107
      {
108
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.bean);
109
      Bitmap bitmap;
110
        
111
      try 
112
        {
113
        bitmap = BitmapFactory.decodeStream(is);
114
        } 
115
      finally 
116
        {
117
        try 
118
          {
119
          is.close();
120
          } 
121
        catch(IOException e) { }
122
        }  
123
      
124
      bmpHeight = bitmap.getHeight();
125
      bmpWidth  = bitmap.getWidth();
126
      
127
      mBean = new DistortedBitmap(bitmap, 10);     
128
      mBean.distort(iLeft , rLeft , pLeft );
129
      mBean.distort(iRight, rRight, pRight);
130
      
131
      try
132
        {
133
        Distorted.onSurfaceCreated(mView);
134
        }
135
      catch(Exception ex)
136
        {
137
        android.util.Log.e("Bean", ex.getMessage() );
138
        }
139
      }
140
}
src/main/java/org/distortedandroid/examples/bean/BeanSurfaceView.java
1

  
2
package org.distortedandroid.examples.bean;
3

  
4
import android.content.Context;
5
import android.opengl.GLSurfaceView;
6
import android.os.Build;
7

  
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
class BeanSurfaceView extends GLSurfaceView 
11
{
12
///////////////////////////////////////////////////////////////////////////////////////////////////
13
   
14
    public BeanSurfaceView(Context context) 
15
      {
16
      super(context);
17
      setEGLContextClientVersion(2);
18
        
19
      if( Build.FINGERPRINT.startsWith("generic") )
20
        { 
21
        setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
22
        }
23
        
24
      setRenderer(new BeanRenderer(this));
25
      }
26
}
27

  
src/main/java/org/distortedandroid/examples/check/CheckActivity.java
1

  
2
package org.distortedandroid.examples.check;
3

  
4
import org.distortedandroid.library.Distorted;
5
import org.distortedandroid.examples.R;
6

  
7
import android.app.Activity;
8
import android.opengl.GLSurfaceView;
9
import android.os.Bundle;
10
import android.widget.NumberPicker;
11
import android.widget.NumberPicker.OnValueChangeListener;
12
import android.view.View;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class CheckActivity extends Activity
17
{
18
    private NumberPicker mVPicker, mFPicker;
19
    private static int maxV, maxF;
20
    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22
    
23
    @Override
24
    protected void onCreate(Bundle icicle) 
25
      {
26
      super.onCreate(icicle);
27
      setContentView(R.layout.check1layout);
28
       
29
      mVPicker = (NumberPicker)findViewById(R.id.check1NumberPickerVertex);
30
      mFPicker = (NumberPicker)findViewById(R.id.check1NumberPickerFragment);
31
      
32
      mVPicker.setMaxValue(1000);
33
      mVPicker.setMinValue(   0);
34
      mFPicker.setMaxValue(1000);
35
      mFPicker.setMinValue(   0);
36
     
37
      mVPicker.setOnValueChangedListener(new OnValueChangeListener() 
38
         {
39
         @Override
40
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
41
           { 
42
           maxV = newVal;
43
           }
44
         });
45
      
46
      mFPicker.setOnValueChangedListener(new OnValueChangeListener() 
47
         {
48
         @Override
49
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
50
           { 
51
           maxF = newVal;
52
           }
53
         });
54
      }
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
    
58
    @Override
59
    protected void onPause() 
60
      {
61
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.checkSurfaceView);
62
      if( mView!=null ) 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.checkSurfaceView);
75
      if( mView!=null ) mView.onResume();    
76
      }
77
 
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
    
80
    @Override
81
    protected void onDestroy() 
82
      {
83
      Distorted.onDestroy();  
84
      super.onDestroy();
85
      }
86
    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
    
89
    @Override
90
    public void onWindowFocusChanged(boolean hasFocus) 
91
      {
92
      super.onWindowFocusChanged(hasFocus);
93

  
94
      mVPicker.setValue(1);
95
      mFPicker.setValue(1);
96
      }
97

  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100
    public static int getMaxV()
101
      {
102
      return maxV;
103
      }
104
    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
    public static int getMaxF()
108
      {
109
      return maxF;
110
      }
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
    
114
    public void Check(View v)
115
      {
116
      setContentView(R.layout.check2layout);
117
      }     
118

  
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
    
121
}
src/main/java/org/distortedandroid/examples/check/CheckRenderer.java
1

  
2
package org.distortedandroid.examples.check;
3

  
4
import java.io.IOException;
5
import java.io.InputStream;
6

  
7
import javax.microedition.khronos.egl.EGLConfig;
8
import javax.microedition.khronos.opengles.GL10;
9

  
10
import org.distortedandroid.examples.R;
11

  
12
import org.distortedandroid.library.Distorted;
13
import org.distortedandroid.library.DistortedBitmap;
14
import org.distortedandroid.library.Float2D;
15
import org.distortedandroid.library.Float3D;
16

  
17
import android.app.AlertDialog;
18
import android.content.Context;
19
import android.content.DialogInterface;
20
import android.graphics.Bitmap;
21
import android.graphics.BitmapFactory;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

  
27
class CheckRenderer implements GLSurfaceView.Renderer 
28
{
29
    private GLSurfaceView mView;
30
    private DistortedBitmap mSuccess;
31
    private Float2D pUp, pDown;
32
    private Float3D vUp, vDown;
33
    
34
    private int bmpHeight, bmpWidth;
35
    
36
    public static String compilationResult;
37
    public static String compilationTitle;
38
    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
    public CheckRenderer(GLSurfaceView view) 
42
      { 
43
      mView = view;
44
    
45
      Distorted.setMaxVertex(CheckActivity.getMaxV());
46
      Distorted.setMaxFragment(CheckActivity.getMaxF());
47
      }
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
   
51
    public void onDrawFrame(GL10 glUnused) 
52
      {
53
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
54
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
55
    
56
      mSuccess.draw(System.currentTimeMillis());
57
      }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
    
61
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
62
      { 
63
      mSuccess.abortAllEffects(Distorted.TYPE_MATR);  
64
      
65
      if( bmpHeight/bmpWidth > height/width )
66
        {
67
        int w = (height*bmpWidth)/bmpHeight;
68
        mSuccess.move((width-w)/2 ,0, 0);
69
        mSuccess.scale((float)height/bmpHeight);
70
        }
71
      else
72
        {
73
        int h = (width*bmpHeight)/bmpWidth;
74
        mSuccess.move(0 ,(height-h)/2, 0);
75
        mSuccess.scale((float)width/bmpWidth);
76
        }
77
      
78
      Distorted.onSurfaceChanged(width, height);
79
      }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
    
83
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
84
      {  
85
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.success);
86
      Bitmap bitmap;
87
        
88
      try 
89
        {
90
        bitmap = BitmapFactory.decodeStream(is);
91
        } 
92
      finally 
93
        {
94
        try 
95
          {
96
          is.close();
97
          } 
98
        catch(IOException e) { }
99
        }  
100
      
101
      bmpHeight = bitmap.getHeight();
102
      bmpWidth  = bitmap.getWidth();
103
       
104
      pDown = new Float2D(bmpWidth/2,        0);
105
      pUp   = new Float2D(bmpWidth/2,bmpHeight);
106
      
107
      vUp   = new Float3D( 0,+bmpHeight,0);
108
      vDown = new Float3D( 0,-bmpHeight,0);
109
      
110
      mSuccess = new DistortedBitmap(bitmap, 30);  
111
      mSuccess.deform(  vUp,   pUp, 2000, 0.0f);
112
      mSuccess.deform(vDown, pDown, 2000, 0.0f);
113
      
114
      try
115
        {
116
        Distorted.onSurfaceCreated(mView);
117
        }
118
      catch(Exception ex)
119
        {
120
        compilationTitle = ex.getClass().getSimpleName();
121
        compilationResult= ex.getMessage();
122
      
123
        String ver;
124
      
125
        ver = GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION);   
126
        compilationResult += "\n\nGLSL version: "+(ver==null ? "null" : ver);
127
        ver = GLES20.glGetString(GLES20.GL_VERSION);  
128
        compilationResult += "\nGL version: "+(ver==null ? "null" : ver);
129
        ver = GLES20.glGetString(GLES20.GL_VENDOR);   
130
        compilationResult += "\nGL vendor: "+(ver==null ? "null" : ver);
131
        ver = GLES20.glGetString(GLES20.GL_RENDERER);    
132
        compilationResult += "\nGL renderer: "+(ver==null ? "null" : ver);
133
      
134
        CheckActivity act = (CheckActivity)mView.getContext();
135
      
136
        act.runOnUiThread(new Runnable() 
137
          {
138
          public void run() 
139
            {
140
            Context context = mView.getContext();
141
      
142
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
143
            builder.setTitle(compilationTitle);
144
            builder.setMessage(compilationResult);
145
            builder.setCancelable(true);
146
           
147
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() 
148
              {
149
              @Override
150
              public void onCancel(DialogInterface dialog) 
151
                {
152
                ((CheckActivity)mView.getContext()).finish();
153
                }
154
              });
155
            
156
            AlertDialog alert = builder.create();
157
            alert.show();
158
            }
159
          });
160
        }
161
      }
162
    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
    
165
}
src/main/java/org/distortedandroid/examples/check/CheckSurfaceView.java
1

  
2
package org.distortedandroid.examples.check;
3

  
4
import android.content.Context;
5
import android.opengl.GLSurfaceView;
6
import android.os.Build;
7
import android.util.AttributeSet;
8

  
9
///////////////////////////////////////////////////////////////////////////////////////////////////
10

  
11
class CheckSurfaceView extends GLSurfaceView 
12
{
13
    private CheckRenderer renderer;
14
   
15
///////////////////////////////////////////////////////////////////////////////////////////////////
16
   
17
    public CheckSurfaceView(Context c, AttributeSet attrs) 
18
      {
19
      super(c, attrs);
20
    
21
      if(!isInEditMode())
22
        {
23
        setEGLContextClientVersion(2);
24
        
25
        if( Build.FINGERPRINT.startsWith("generic") )
26
          { 
27
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
28
          }
29
    
30
        renderer = new CheckRenderer(this);
31
        setRenderer(renderer);
32
        }
33
      }
34

  
35
}
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

  
src/main/java/org/distortedandroid/examples/cubes/CubesActivity.java
1

  
2
package org.distortedandroid.examples.cubes;
3

  
4
import org.distortedandroid.library.Distorted;
5
import org.distortedandroid.examples.R;
6

  
7
import android.app.Activity;
8
import android.opengl.GLSurfaceView;
9
import android.os.Bundle;
10
import android.view.Gravity;
11
import android.view.View;
12
import android.widget.Button;
13
import android.widget.LinearLayout;
14
import android.widget.NumberPicker;
15
import android.widget.NumberPicker.OnValueChangeListener;
16
import android.widget.TableRow;
17

  
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
public class CubesActivity extends Activity implements View.OnClickListener
21
{
22
    private static int mNumCols = 3;
23
    private static int mNumRows = 3;
24
    
25
    private static final int COLOR_OFF = 0xffffe81f;
26
    private static final int COLOR_ON  = 0xff0000ff;
27
    
28
    private NumberPicker mColsPicker, mRowsPicker;
29
    private LinearLayout mLay;
30
    private static boolean[] mShape;
31
    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
    
34
    @Override
35
    protected void onCreate(Bundle savedState) 
36
      {
37
      super.onCreate(savedState);
38

  
39
      setContentView(R.layout.cubes1layout);
40
      
41
      mLay = (LinearLayout)findViewById(R.id.buttongrid);
42
      
43
      mColsPicker = (NumberPicker)findViewById(R.id.colsPicker);
44
      mRowsPicker = (NumberPicker)findViewById(R.id.rowsPicker);
45
      
46
      mColsPicker.setMaxValue(10);
47
      mColsPicker.setMinValue( 0);
48
      mRowsPicker.setMaxValue(10);
49
      mRowsPicker.setMinValue( 0);
50
     
51
      mColsPicker.setOnValueChangedListener(new OnValueChangeListener() 
52
         {
53
         @Override
54
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
55
           { 
56
           setGrid();
57
           }
58
         });
59
      
60
      mRowsPicker.setOnValueChangedListener(new OnValueChangeListener() 
61
         {
62
         @Override
63
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
64
           { 
65
           setGrid();
66
           }
67
         });
68
      }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
    public static int getCols()
73
      {
74
      return mNumCols; 
75
      }
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
    public static String getShape()
80
      {
81
      String str = ""; 
82
       
83
      for(int i=0; i<mNumRows*mNumCols; i++)
84
        str += mShape[i] ? "1" : "0";
85
      
86
      //android.util.Log.d("CUBES", str);
87
      
88
      return str; 
89
      }
90
    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
    
93
    public void setGrid()
94
      {
95
      mNumCols = mColsPicker.getValue();
96
      mNumRows = mRowsPicker.getValue();
97
      
98
      int width = mLay.getWidth();
99
      int height= mLay.getHeight();
100
      int w = mNumCols>0 ? (width / mNumCols) -10 : 0;
101
      int h = mNumRows>0 ? (height/ mNumRows) -10 : 0;
102
      int size= w<h ? w:h;
103
      int pad = size/20;
104
     
105
      mLay.removeAllViews();
106
      
107
      mShape = new boolean[mNumRows*mNumCols];
108

  
109
      TableRow.LayoutParams p = new android.widget.TableRow.LayoutParams();
110
          
111
      p.rightMargin  = pad;
112
      p.leftMargin   = pad;
113
      p.topMargin    = pad;
114
      p.bottomMargin = pad;
115
      p.height       = size;
116
      p.width        = size;
117
      
118
      for (int rows=0; rows<mNumRows; rows++) 
119
        {
120
        TableRow tr = new TableRow(this);
121
        tr.setGravity(Gravity.CENTER);
122
        
123
        for(int cols=0; cols<mNumCols; cols++) 
124
          {
125
          Button b = new Button(this);
126
          b.setOnClickListener(this);
127
          b.setId(rows*mNumCols+cols);
128
          b.setLayoutParams(p);          
129
          b.setBackgroundColor(COLOR_OFF);
130
          tr.addView(b, p);
131
          mShape[rows*mNumCols+cols] = false;
132
          }
133
        
134
        mLay.addView(tr);
135
        }
136
      }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
    
140
    public void onClick(View view) 
141
      {
142
      Button tmp = (Button)view;  
143
      int id = tmp.getId();
144
      mShape[id] = !mShape[id];
145
      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
146
      }
147

  
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
    
150
    @Override
151
    public void onWindowFocusChanged(boolean hasFocus) 
152
      {
153
      super.onWindowFocusChanged(hasFocus);
154

  
155
      mColsPicker.setValue(mNumCols);
156
      mRowsPicker.setValue(mNumRows);
157
      
158
      if( hasFocus ) setGrid();
159
      }
160
    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162
    
163
    @Override
164
    protected void onPause() 
165
      {
166
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.cubesSurfaceView);
167
      if( mView!=null ) mView.onPause();
168
        
169
      super.onPause();
170
      }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
    
174
    @Override
175
    protected void onResume() 
176
      {
177
      super.onResume();
178
      
179
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.cubesSurfaceView);
180
      if( mView!=null ) mView.onResume();  
181
      }
182
    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
    
185
    @Override
186
    protected void onDestroy() 
187
      {
188
      Distorted.onDestroy();  
189
      super.onDestroy();
190
      }
191
 
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193
    
194
    public void Continue(View v)
195
      {   
196
      setContentView(R.layout.cubes2layout);
197
      }     
198
}
src/main/java/org/distortedandroid/examples/cubes/CubesRenderer.java
1

  
2
package org.distortedandroid.examples.cubes;
3

  
4
import java.io.IOException;
5
import java.io.InputStream;
6

  
7
import javax.microedition.khronos.egl.EGLConfig;
8
import javax.microedition.khronos.opengles.GL10;
9

  
10
import org.distortedandroid.examples.R;
11

  
12
import org.distortedandroid.library.InterpolatorQuat;
13
import org.distortedandroid.library.DistortedCubes;
14
import org.distortedandroid.library.Float4D;
15
import org.distortedandroid.library.Float3D;
16
import org.distortedandroid.library.Distorted;
17

  
18
import android.graphics.Bitmap;
19
import android.graphics.BitmapFactory;
20
import android.opengl.GLES20;
21
import android.opengl.GLSurfaceView;
22

  
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

  
25
class CubesRenderer implements GLSurfaceView.Renderer 
26
{
27
	private static final int SIZE = 100;
28
	
29
	private int mCols, mRows;
30
	
31
    private GLSurfaceView mView;
32
    private DistortedCubes mCubes;
33
    private InterpolatorQuat mQuatInt1, mQuatInt2;
34
    
35
    Float4D mQuat1, mQuat2;
36
    int mScreenMin;
37
    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
    public CubesRenderer(GLSurfaceView v) 
41
      {
42
      mView = v;
43
      
44
      String shape = CubesActivity.getShape();
45
      
46
      mCols = CubesActivity.getCols();
47
      mRows = shape.length() / mCols;
48
      
49
      mCubes = new DistortedCubes( mCols, shape, SIZE);
50
      
51
      mQuat1 = new Float4D(0,0,0,1);  // unity
52
      mQuat2 = new Float4D(0,0,0,1);  // quaternions
53
      
54
      mQuatInt1 = new InterpolatorQuat();
55
      mQuatInt2 = new InterpolatorQuat();
56
      mQuatInt1.setDuration(0);
57
      mQuatInt2.setDuration(0);
58
      mQuatInt1.setCount(0.5f);
59
      mQuatInt2.setCount(0.5f);
60
      
61
      mQuatInt1.add(mQuat1);
62
      mQuatInt2.add(mQuat2);
63
      }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
   
67
    public void onDrawFrame(GL10 glUnused) 
68
      {
69
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
70
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
71
      
72
      mCubes.draw(System.currentTimeMillis());
73
      }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
    
77
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
78
      {
79
      mScreenMin = width<height ? width:height;
80
    	
81
      mCubes.abortAllEffects(Distorted.TYPE_MATR);  
82

  
83
      if( mRows/mCols > height/width )
84
        {
85
        int w = (height*mRows)/mCols;
86
        mCubes.move((width-w)/2 ,0, 0);
87
        mCubes.scale((float)height/(mRows*SIZE));
88
        }  
89
      else
90
        {   
91
        int h = (width*mRows)/mCols;
92
        mCubes.move(0 ,(height-h)/2, 0);
93
        mCubes.scale((float)width/(mCols*SIZE));
94
        }
95
    
96
      Float3D center = new Float3D(mCols*SIZE/2,mRows*SIZE/2, 0);
97
      
98
      mCubes.quaternion(center, mQuatInt1);
99
      mCubes.quaternion(center, mQuatInt2);
100
       
101
      Distorted.onSurfaceChanged(width, height); 
102
      }
103

  
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
    
106
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
107
      {
108
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
109
      Bitmap bitmap;
110
        
111
      try 
112
        {
113
        bitmap = BitmapFactory.decodeStream(is);
114
        } 
115
      finally 
116
        {
117
        try 
118
          {
119
          is.close();
120
          } 
121
        catch(IOException e) { }
122
        }  
123
      
124
      mCubes.setBitmap(bitmap);
125
      
126
      try
127
        {
128
        Distorted.onSurfaceCreated(mView);
129
        }
130
      catch(Exception ex)
131
        {
132
        android.util.Log.e("Cubes", ex.getMessage() );
133
        }
134
      }
135
}
src/main/java/org/distortedandroid/examples/cubes/CubesSurfaceView.java
1

  
2
package org.distortedandroid.examples.cubes;
3

  
4
import org.distortedandroid.examples.R;
5

  
6
import android.content.Context;
7
import android.opengl.GLSurfaceView;
8
import android.os.Build;
9
import android.util.AttributeSet;
10
import android.view.MotionEvent;
11
import android.widget.Toast;
12

  
13
///////////////////////////////////////////////////////////////////////////////////////////////////
14

  
15
class CubesSurfaceView extends GLSurfaceView 
16
{
17
    int mX, mY;
18
    CubesRenderer mRenderer;
19
	
20
///////////////////////////////////////////////////////////////////////////////////////////////////
21
   
22
    public CubesSurfaceView(Context c, AttributeSet attrs) 
23
      {
24
      super(c,attrs);
25
    
26
      mX = -1;
27
      mY = -1;
28
      
29
      if(!isInEditMode())
30
        {
31
        setEGLContextClientVersion(2);
32
        
33
        if( Build.FINGERPRINT.startsWith("generic") )
34
          { 
35
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
36
          }
37
    
38
        mRenderer = new CubesRenderer(this);
39
        
40
        setRenderer(mRenderer);
41
        
42
        Toast.makeText(c, R.string.example_cubes_toast , Toast.LENGTH_SHORT).show();   
43
        }
44
      }
45
    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
    
48
    @Override public boolean onTouchEvent(MotionEvent event) 
49
      {
50
      int action = event.getAction();
51
      int x = (int)event.getX();
52
      int y = (int)event.getY();
53
           
54
      switch(action)
55
         {
56
         case MotionEvent.ACTION_DOWN: mX = x;
57
                                       mY = y;
58
                                       break;
59
                                       
60
         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
61
                                         {
62
                                         float px = mY-y;
63
                                         float py = mX-x;
64
                                         float pz = 0;
65
                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
66
                                         
67
                                         if( plen>0 )
68
                                           {
69
                                           px /= plen;
70
                                           py /= plen;
71
                                           pz /= plen;
72

  
73
                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
74
                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
75
                                         
76
                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
77
                                           }
78
                                         }                             
79
                                       break;
80
                                       
81
         case MotionEvent.ACTION_UP  : mX = -1;
82
                                       mY = -1;
83
        	                           
84
                                       float qx = mRenderer.mQuat1.getX();
85
                                       float qy = mRenderer.mQuat1.getY();
86
                                       float qz = mRenderer.mQuat1.getZ();
87
                                       float qw = mRenderer.mQuat1.getW();
88

  
89
                                       float rx = mRenderer.mQuat2.getX();
90
                                       float ry = mRenderer.mQuat2.getY();
91
                                       float rz = mRenderer.mQuat2.getZ();
92
                                       float rw = mRenderer.mQuat2.getW();
93

  
94
                                       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
95
                                       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
96
                                       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
97
                                       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
98
                                       
99
                                       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
100
                                       mRenderer.mQuat2.set(tx, ty, tz, tw);
101
                                       
102
                                       break;
103
         }
104
             
105
      return true;
106
      }
107
         
108
}
109

  
src/main/java/org/distortedandroid/examples/deform/DeformActivity.java
1

  
2
package org.distortedandroid.examples.deform;
3

  
4
import org.distortedandroid.library.Distorted;
5
import org.distortedandroid.examples.R;
6

  
7
import android.app.Activity;
8
import android.opengl.GLSurfaceView;
9
import android.os.Bundle;
10
import android.view.View;
11
import android.widget.RadioButton;
12
import android.widget.SeekBar;
13
import android.widget.TextView;
14
import android.widget.SeekBar.OnSeekBarChangeListener;
15

  
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

  
18
public class DeformActivity extends Activity implements OnSeekBarChangeListener
19
{
20
    private SeekBar barR;
21
    private TextView textR;
22
    private RadioButton effect;
23
    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
    
26
    @Override
27
    protected void onCreate(Bundle icicle) 
28
      {
29
      super.onCreate(icicle);
30
      setContentView(R.layout.deformlayout);
31
       
32
      barR = (SeekBar)findViewById(R.id.deformSeekRadius);
33
      barR.setOnSeekBarChangeListener(this); 
34
        
35
      textR = (TextView)findViewById(R.id.deformTextRadius);
36
     
37
      barR.setProgress(50);
38
      
39
      textR.setText("Radius: 50");
40
      
41
      effect = (RadioButton)findViewById(R.id.deformDistortButton);
42
      effect.setChecked(true);
43
      DeformRenderer.setMode(DeformRenderer.MODE_DISTORT);
44
      }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
    
48
    @Override
49
    protected void onPause() 
50
      {
51
      DeformRenderer.onPause();
52
      
53
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.deformSurfaceView);
54
      mView.onPause();
55
      
56
      super.onPause();
57
      }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff