Project

General

Profile

« Previous | Next » 

Revision 887e1853

Added by Leszek Koltunski almost 4 years ago

Skeleton of the new app: Deferred Jobs.

View differences:

src/main/AndroidManifest.xml
59 59
        <activity android:name=".meshjoin.MeshJoinActivity"/>
60 60
        <activity android:name=".predeform.PredeformActivity"/>
61 61
        <activity android:name=".predeform.PredeformActivity2"/>
62
        <activity android:name=".deferredjob.DeferredJobActivity"/>
62 63
    </application>
63 64
</manifest>
src/main/java/org/distorted/examples/TableOfContents.java
34 34
import android.widget.AdapterView.OnItemClickListener;
35 35
import android.widget.SimpleAdapter;
36 36

  
37
import org.distorted.examples.deferredjob.DeferredJobActivity;
37 38
import org.distorted.examples.monalisa.MonaLisaActivity;
38 39
import org.distorted.examples.sink.SinkActivity;
39 40
import org.distorted.examples.projection.ProjectionActivity;
......
121 122
    RUBIK             (R.drawable.icon_example_rubik           , R.string.example_rubik           , R.string.example_rubik_subtitle           ,            RubikActivity.class),
122 123
    MESHJOIN          (R.drawable.icon_example_meshjoin        , R.string.example_meshjoin           , R.string.example_meshjoin_subtitle           ,            MeshJoinActivity.class),
123 124
    PREDEFORM         (R.drawable.icon_example_predeform       , R.string.example_predeform           , R.string.example_predeform_subtitle           ,            PredeformActivity.class),
125
    DEFERREDJOB       (R.drawable.icon_example_wip             , R.string.example_deferredjob           , R.string.example_deferredjob_subtitle           ,            DeferredJobActivity.class),
124 126
    ;
125 127

  
126 128
    final int icon, title, subtitle;
src/main/java/org/distorted/examples/deferredjob/DeferredJobActivity.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.deferredjob;
21

  
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.view.View;
26
import android.widget.CheckBox;
27

  
28
import org.distorted.examples.R;
29
import org.distorted.library.main.DistortedLibrary;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
public class DeferredJobActivity extends Activity
34
{
35
    @Override
36
    protected void onCreate(Bundle icicle) 
37
      {
38
      super.onCreate(icicle);
39
      setContentView(R.layout.deferredjoblayout);
40
      }
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
    
44
    @Override
45
    protected void onPause() 
46
      {
47
      GLSurfaceView view = this.findViewById(R.id.deferredjobSurfaceView);
48
      view.onPause();
49
      DistortedLibrary.onPause();
50
      super.onPause();
51
      }
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
    
55
    @Override
56
    protected void onResume() 
57
      {
58
      super.onResume();
59
      GLSurfaceView view = this.findViewById(R.id.deferredjobSurfaceView);
60
      view.onResume();
61
      }
62
    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
    
65
    @Override
66
    protected void onDestroy() 
67
      {
68
      DistortedLibrary.onDestroy();
69
      super.onDestroy();
70
      }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
    public void onClick(View view)
75
      {
76
      CheckBox box = (CheckBox)view;
77
      int id = box.getId();
78
      boolean checked = box.isChecked();
79
      DeferredJobSurfaceView sView = findViewById(R.id.deferredjobSurfaceView);
80

  
81
      switch(id)
82
        {
83
        case R.id.deferredjobCheckBox0  : sView.getRenderer().setChecked(0,checked); break;
84
        case R.id.deferredjobCheckBox1  : sView.getRenderer().setChecked(1,checked); break;
85
        case R.id.deferredjobCheckBox2  : sView.getRenderer().setChecked(2,checked); break;
86
        case R.id.deferredjobCheckBox3  : sView.getRenderer().setChecked(3,checked); break;
87
        }
88
      }
89
}
src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.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.deferredjob;
21

  
22
import android.graphics.Bitmap;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
import android.opengl.GLSurfaceView;
26

  
27
import org.distorted.library.effect.EffectType;
28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffectDeform;
31
import org.distorted.library.effect.VertexEffectMove;
32
import org.distorted.library.effect.VertexEffectRotate;
33
import org.distorted.library.effect.VertexEffectScale;
34
import org.distorted.library.effect.VertexEffectSink;
35
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.main.DistortedTexture;
39
import org.distorted.library.mesh.MeshBase;
40
import org.distorted.library.mesh.MeshJoined;
41
import org.distorted.library.mesh.MeshTriangles;
42
import org.distorted.library.type.Dynamic1D;
43
import org.distorted.library.type.DynamicQuat;
44
import org.distorted.library.type.Static1D;
45
import org.distorted.library.type.Static3D;
46
import org.distorted.library.type.Static4D;
47

  
48
import javax.microedition.khronos.egl.EGLConfig;
49
import javax.microedition.khronos.opengles.GL10;
50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

  
53
class DeferredJobRenderer implements GLSurfaceView.Renderer
54
{
55
    private GLSurfaceView mView;
56
    private DistortedTexture mTexture;
57
    private DistortedScreen mScreen;
58
    private DistortedEffects mEffects;
59
    private Static3D mScale;
60
    private MeshBase mMesh;
61
    private int mSinkAssociation;
62
    private VertexEffectSink mSink;
63

  
64
    Static4D mQuat1, mQuat2;
65
    int mScreenMin;
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
    DeferredJobRenderer(GLSurfaceView v)
70
      {
71
      mView = v;
72
      mScreen = new DistortedScreen();
73
      mScale= new Static3D(1,1,1);
74
      Static3D center=new Static3D(0,0,0);
75

  
76
      Dynamic1D sink = new Dynamic1D(5000,0.0f);
77
      sink.add( new Static1D(0.5f) );
78
      sink.add( new Static1D(2.0f) );
79

  
80
      mQuat1 = new Static4D(0,0,0,1);  // unity
81
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
82

  
83
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
84
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
85

  
86
      quatInt1.add(mQuat1);
87
      quatInt2.add(mQuat2);
88

  
89
      mSinkAssociation = 0;
90
      mSink = new VertexEffectSink( sink, center, new Static4D(0,0,0,0.75f) );
91
      mSink.setMeshAssociation(-1,mSinkAssociation);
92

  
93
      mEffects = new DistortedEffects();
94
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
95
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
96
      mEffects.apply( new MatrixEffectScale(mScale));
97
      mEffects.apply( mSink );
98

  
99
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
   
104
    public void onDrawFrame(GL10 glUnused) 
105
      {
106
      mScreen.render( System.currentTimeMillis() );
107
      }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
112
      {
113
      final float SCALE = 0.7f;
114
      mScreenMin = Math.min(width, height);
115
      float factor = SCALE*mScreenMin;
116
      mScale.set(factor,factor,factor);
117
      mScreen.resize(width, height);
118
      }
119

  
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
    
122
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
123
      {
124
      if( mTexture==null ) mTexture = new DistortedTexture();
125
      mTexture.setTexture( createTetrahedronTexture() );
126

  
127
      if( mMesh==null ) mMesh = createJoinedTetrahedron();
128

  
129
      mScreen.detachAll();
130
      mScreen.attach(mTexture,mEffects,mMesh);
131

  
132
      DistortedLibrary.setMax(EffectType.VERTEX, 11);
133
      VertexEffectSink.enable();
134

  
135
      try
136
        {
137
        DistortedLibrary.onCreate(mView.getContext());
138
        }
139
      catch(Exception ex)
140
        {
141
        android.util.Log.e("MeshJoin", ex.getMessage() );
142
        }
143
      }
144

  
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

  
147
    void setChecked(int number, boolean checked)
148
      {
149
      int n = (0x1 << number);
150

  
151
      if( checked ) mSinkAssociation |= n;
152
      else          mSinkAssociation &= (15-n);
153

  
154
      mSink.setMeshAssociation(-1,mSinkAssociation);
155
      }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

  
159
    private Bitmap createTetrahedronTexture()
160
      {
161
      final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
162
      final int FACES=FACE_COLORS.length;
163
      int SIZE = 200;
164
      float STROKE = 0.05f*SIZE;
165
      float OFF = STROKE/2 -1;
166
      float OFF2 = 0.5f*SIZE + OFF;
167
      float HEIGHT = SIZE - OFF;
168
      float RADIUS = SIZE/12;
169
      float ARC1_H = 0.2f*SIZE;
170
      float ARC1_W = SIZE*0.5f;
171
      float ARC2_W = 0.153f*SIZE;
172
      float ARC2_H = 0.905f*SIZE;
173
      float ARC3_W = SIZE-ARC2_W;
174

  
175
      Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888);
176
      Canvas canvas = new Canvas(result);
177
      Paint paint = new Paint();
178
      paint.setAntiAlias(true);
179
      paint.setStrokeWidth(STROKE);
180

  
181
      for(int i=0; i<FACES; i++)
182
        {
183
        paint.setColor(FACE_COLORS[i]);
184
        paint.setStyle(Paint.Style.FILL);
185

  
186
        canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);
187

  
188
        paint.setColor(0xff000000);
189
        paint.setStyle(Paint.Style.STROKE);
190

  
191
        canvas.drawLine(           i*SIZE, HEIGHT,  SIZE       +i*SIZE, HEIGHT, paint);
192
        canvas.drawLine(      OFF +i*SIZE,   SIZE,       OFF2  +i*SIZE,      0, paint);
193
        canvas.drawLine((SIZE-OFF)+i*SIZE,   SIZE, (SIZE-OFF2) +i*SIZE,      0, paint);
194

  
195
        canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint);
196
        canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint);
197
        canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint);
198
        }
199

  
200
      return result;
201
      }
202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
    private MeshBase createJoinedTetrahedron()
206
      {
207
      final float SQ2 = (float)Math.sqrt(2);
208
      final float SQ3 = (float)Math.sqrt(3);
209
      final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
210
      final int MESHES=4;
211

  
212
      int association = 1;
213
      MeshBase[] meshes = new MeshTriangles[MESHES];
214

  
215
      for(int i=0; i<MESHES; i++)
216
        {
217
        meshes[i] = new MeshTriangles(5);
218
        meshes[i].setEffectAssociation(0,association);
219
        association <<= 1;
220
        }
221

  
222
      Static4D[] textureMaps = new Static4D[MESHES];
223
      for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
224
      MeshBase result = new MeshJoined(meshes);
225
      result.setTextureMap(textureMaps);
226

  
227
      Static3D a0 = new Static3D(         0,        1,       0 );
228
      Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
229
      Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
230
      Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
231

  
232
      float tetraHeight = SQ2*SQ3/3;
233
      float d1 = 0.75f*tetraHeight;
234
      float d2 =-0.10f*tetraHeight;
235
      float d3 = 0.20f*tetraHeight;
236

  
237
      Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
238
      Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
239
      Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
240
      Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
241

  
242
      Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
243
      Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
244
      Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
245
      Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
246

  
247
      Static4D dReg  = new Static4D(0,0,0,d3);
248
      Static1D dRad  = new Static1D(1);
249

  
250
      Static1D angle  = new Static1D(angleFaces);
251
      Static3D axis1  = new Static3D(  -1, 0,      0);
252
      Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
253
      Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
254
      Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
255
      Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
256

  
257
      VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
258
      VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
259
      VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
260
      VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
261
      VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
262
      VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
263
      VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
264

  
265
      VertexEffectDeform effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
266
      VertexEffectDeform effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
267
      VertexEffectDeform effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
268
      VertexEffectDeform effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
269

  
270
      effect4.setMeshAssociation(-1,14);  // apply to mesh[1], [2] and [3]
271
      effect5.setMeshAssociation(-1, 2);  // apply only to mesh[1]
272
      effect6.setMeshAssociation(-1, 4);  // apply only to mesh[2]
273
      effect7.setMeshAssociation(-1, 8);  // apply only to mesh[3]
274

  
275
      result.apply(effect1);
276
      result.apply(effect2);
277
      result.apply(effect3);
278
      result.apply(effect4);
279
      result.apply(effect5);
280
      result.apply(effect6);
281
      result.apply(effect7);
282
      result.apply(effect8);
283
      result.apply(effect9);
284
      result.apply(effect10);
285
      result.apply(effect11);
286

  
287
      return result;
288
      }
289
}
src/main/java/org/distorted/examples/deferredjob/DeferredJobSurfaceView.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.deferredjob;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLSurfaceView;
26
import android.util.AttributeSet;
27
import android.view.MotionEvent;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
class DeferredJobSurfaceView extends GLSurfaceView
32
{
33
    private final static int DIRECTION_SENSITIVITY=  12;
34
    private int mX, mY;
35
    private DeferredJobRenderer mRenderer;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
    public DeferredJobSurfaceView(Context context, AttributeSet attrs)
40
      {
41
      super(context,attrs);
42

  
43
      mX = -1;
44
      mY = -1;
45

  
46
      if(!isInEditMode())
47
        {
48
        mRenderer = new DeferredJobRenderer(this);
49
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
50
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
51
        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
52
        setRenderer(mRenderer);
53
        }
54
      }
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
    public DeferredJobRenderer getRenderer()
59
      {
60
      return mRenderer;
61
      }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
    private void resetQuats()
66
      {
67
      float qx = mRenderer.mQuat1.get0();
68
      float qy = mRenderer.mQuat1.get1();
69
      float qz = mRenderer.mQuat1.get2();
70
      float qw = mRenderer.mQuat1.get3();
71

  
72
      float rx = mRenderer.mQuat2.get0();
73
      float ry = mRenderer.mQuat2.get1();
74
      float rz = mRenderer.mQuat2.get2();
75
      float rw = mRenderer.mQuat2.get3();
76

  
77
       // This is quaternion multiplication. (tx,ty,tz,tw)
78
       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
79
       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
80
       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
81
       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
82
       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
83

  
84
       // The point of this is so that there are always
85
       // exactly 2 quaternions: Quat1 representing the rotation
86
       // accumulating only since the last screen touch, and Quat2
87
       // which remembers the combined effect of all previous
88
       // swipes.
89
       // We cannot be accumulating an ever-growing list of quaternions
90
       // and add a new one every time user swipes the screen - there
91
       // is a limited number of slots in the EffectQueueMatrix!
92
       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
93
       mRenderer.mQuat2.set(tx, ty, tz, tw);
94
       }
95

  
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
    @Override public boolean onTouchEvent(MotionEvent event) 
99
      {
100
      int action = event.getAction();
101
      int x = (int)event.getX();
102
      int y = (int)event.getY();
103
           
104
      switch(action)
105
         {
106
         case MotionEvent.ACTION_DOWN: mX = x;
107
                                       mY = y;
108
                                       break;
109
                                       
110
         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
111
                                         {
112
                                         float px = mY-y;
113
                                         float py = mX-x;
114
                                         float pz = 0;
115
                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
116
                                         
117
                                         if( plen>0 )
118
                                           {
119
                                           px /= plen;
120
                                           py /= plen;
121
                                           pz /= plen;
122

  
123
                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
124
                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
125
                                         
126
                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
127
                                           }
128
                                         }
129

  
130
                                       if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
131
                                         {
132
                                         mX = x;
133
                                         mY = y;
134
                                         resetQuats();
135
                                         }
136

  
137
                                       break;
138
                                       
139
         case MotionEvent.ACTION_UP  : mX = -1;
140
                                       mY = -1;
141
                                       resetQuats();
142
                                       break;
143
         }
144
             
145
      return true;
146
      }
147
         
148
}
149

  
src/main/res/layout/deferredjoblayout.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.deferredjob.DeferredJobSurfaceView
8
        android:id="@+id/deferredjobSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="1" />
12

  
13
    <TextView
14
        android:layout_width="wrap_content"
15
        android:layout_height="wrap_content"
16
        android:layout_gravity="center"
17
        android:text="@string/association"
18
        android:textAppearance="?android:attr/textAppearanceMedium" />
19

  
20
    <LinearLayout
21
        android:orientation="horizontal"
22
        android:layout_width="match_parent"
23
        android:layout_height="wrap_content">
24

  
25
        <CheckBox
26
            android:layout_width="wrap_content"
27
            android:layout_height="match_parent"
28
            android:id="@+id/deferredjobCheckBox0"
29
            android:text="@string/color_yellow"
30
            android:onClick="onClick"
31
            android:layout_weight="1"
32
            android:checked="false"/>
33
        <CheckBox
34
            android:layout_width="wrap_content"
35
            android:layout_height="match_parent"
36
            android:id="@+id/deferredjobCheckBox1"
37
            android:text="@string/color_green"
38
            android:onClick="onClick"
39
            android:layout_weight="1"
40
            android:checked="false"/>
41
        <CheckBox
42
            android:layout_width="wrap_content"
43
            android:layout_height="match_parent"
44
            android:id="@+id/deferredjobCheckBox2"
45
            android:text="@string/color_blue"
46
            android:onClick="onClick"
47
            android:layout_weight="1"
48
            android:checked="false"/>
49
        <CheckBox
50
            android:layout_width="wrap_content"
51
            android:layout_height="match_parent"
52
            android:id="@+id/deferredjobCheckBox3"
53
            android:text="@string/color_red"
54
            android:onClick="onClick"
55
            android:layout_weight="1"
56
            android:checked="false"/>
57

  
58
    </LinearLayout>
59

  
60
</LinearLayout>
src/main/res/values/strings.xml
198 198
    <string name="example_meshjoin_subtitle">See how one can join several simple meshes to form a single, more advanced one.</string>
199 199
    <string name="example_predeform">PreApply Vertex Effects to a Mesh</string>
200 200
    <string name="example_predeform_subtitle">Create a more advanced Mesh by taking one of the simple ones and pre-applying a queue of Vertex Effects to it.</string>
201
    <string name="example_deferredjob">Deferred Mesh Jobs</string>
202
    <string name="example_deferredjob_subtitle">Create an advanced mesh in steps, using deferred mesh jobs: apply vertex effects, copy meshes, join them, merge their components.</string>
201 203

  
202 204
    <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>
203 205
    <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>

Also available in: Unified diff