Project

General

Profile

Download (22.7 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / tutorials / TutorialSurfaceView.java @ 967b79dc

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube 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
// Magic Cube 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 Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.tutorials;
21

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

    
31
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32

    
33
import org.distorted.library.type.Static2D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.objects.Movement;
36
import org.distorted.objects.TwistyObject;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TutorialSurfaceView extends GLSurfaceView
41
{
42
    private static final int NUM_SPEED_PROBES = 10;
43
    private static final int INVALID_POINTER_ID = -1;
44

    
45
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
46
    // given face by SWIPING_SENSITIVITY/2 degrees.
47
    private final static int SWIPING_SENSITIVITY  = 240;
48
    // Moving the finger by 0.3 of an inch will start a Rotation.
49
    private final static float ROTATION_SENSITIVITY = 0.3f;
50

    
51
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 1, 0);
52

    
53
    private TutorialRenderer mRenderer;
54
    private TutorialPreRender mPreRender;
55
    private Movement mMovement;
56
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
57
    private int mScreenWidth, mScreenHeight, mScreenMin;
58

    
59
    private float mRotAngle, mInitDistance;
60
    private int mPtrID1, mPtrID2;
61
    private float mX, mY;
62
    private float mStartRotX, mStartRotY;
63
    private float mAxisX, mAxisY;
64
    private float mRotationFactor;
65
    private int mCurrentAxis, mCurrentRow;
66
    private float mCurrentAngle, mCurrRotSpeed;
67
    private float[] mLastX;
68
    private float[] mLastY;
69
    private long[] mLastT;
70
    private int mFirstIndex, mLastIndex;
71
    private int mDensity;
72

    
73
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
74
    private static final Static4D mTemp= new Static4D(0,0,0,1);
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
    void setScreenSize(int width, int height)
79
      {
80
      mScreenWidth = width;
81
      mScreenHeight= height;
82

    
83
      mScreenMin = Math.min(width, height);
84
      }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
    boolean isVertical()
89
      {
90
      return mScreenHeight>mScreenWidth;
91
      }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
    TutorialRenderer getRenderer()
96
      {
97
      return mRenderer;
98
      }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
    TutorialPreRender getPreRender()
103
      {
104
      return mPreRender;
105
      }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
    void setQuat()
110
      {
111
      mQuat.set(mTemp);
112
      }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
    Static4D getQuat()
117
      {
118
      return mQuat;
119
      }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
    void setMovement(Movement movement)
124
      {
125
      mMovement = movement;
126
      }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
    private Static4D quatFromDrag(float dragX, float dragY)
131
      {
132
      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
133
      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
134
      float axisZ = 0;
135
      float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
136

    
137
      if( axisL>0 )
138
        {
139
        axisX /= axisL;
140
        axisY /= axisL;
141
        axisZ /= axisL;
142

    
143
        float ratio = axisL;
144
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
145

    
146
        float cosA = (float)Math.cos(Math.PI*ratio);
147
        float sinA = (float)Math.sqrt(1-cosA*cosA);
148

    
149
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
150
        }
151

    
152
      return new Static4D(0f, 0f, 0f, 1f);
153
      }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
157
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
158

    
159
    private void computeCurrentAxis(Static4D axis)
160
      {
161
      Static4D result = rotateVectorByQuat(axis, mQuat);
162

    
163
      mAxisX =result.get0();
164
      mAxisY =result.get1();
165

    
166
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
167
      mAxisX /= len;
168
      mAxisY /= len;
169
      }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
// return quat1*quat2
173

    
174
    public static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
175
      {
176
      float qx = quat1.get0();
177
      float qy = quat1.get1();
178
      float qz = quat1.get2();
179
      float qw = quat1.get3();
180

    
181
      float rx = quat2.get0();
182
      float ry = quat2.get1();
183
      float rz = quat2.get2();
184
      float rw = quat2.get3();
185

    
186
      float tx = rw*qx - rz*qy + ry*qz + rx*qw;
187
      float ty = rw*qy + rz*qx + ry*qw - rx*qz;
188
      float tz = rw*qz + rz*qw - ry*qx + rx*qy;
189
      float tw = rw*qw - rz*qz - ry*qy - rx*qx;
190

    
191
      return new Static4D(tx,ty,tz,tw);
192
      }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
196

    
197
    public static Static4D rotateVectorByQuat(Static4D vector, Static4D quat)
198
      {
199
      float qx = quat.get0();
200
      float qy = quat.get1();
201
      float qz = quat.get2();
202
      float qw = quat.get3();
203

    
204
      Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
205
      Static4D tmp = quatMultiply(quat,vector);
206

    
207
      return quatMultiply(tmp,quatInverted);
208
      }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211
// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
212

    
213
    public static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
214
      {
215
      float qx = quat.get0();
216
      float qy = quat.get1();
217
      float qz = quat.get2();
218
      float qw = quat.get3();
219

    
220
      Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw);
221
      Static4D tmp = quatMultiply(quatInverted,vector);
222

    
223
      return quatMultiply(tmp,quat);
224
      }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
    private void addSpeedProbe(float x, float y)
229
      {
230
      long currTime = System.currentTimeMillis();
231
      boolean theSame = mLastIndex==mFirstIndex;
232

    
233
      mLastIndex++;
234
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
235

    
236
      mLastT[mLastIndex] = currTime;
237
      mLastX[mLastIndex] = x;
238
      mLastY[mLastIndex] = y;
239

    
240
      if( mLastIndex==mFirstIndex)
241
        {
242
        mFirstIndex++;
243
        if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
244
        }
245

    
246
      if( theSame )
247
        {
248
        mLastT[mFirstIndex] = currTime;
249
        mLastX[mFirstIndex] = x;
250
        mLastY[mFirstIndex] = y;
251
        }
252
      }
253

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

    
256
    private void computeCurrentSpeedInInchesPerSecond()
257
      {
258
      long firstTime = mLastT[mFirstIndex];
259
      long lastTime  = mLastT[mLastIndex];
260
      float fX = mLastX[mFirstIndex];
261
      float fY = mLastY[mFirstIndex];
262
      float lX = mLastX[mLastIndex];
263
      float lY = mLastY[mLastIndex];
264

    
265
      long timeDiff = lastTime-firstTime;
266

    
267
      mLastIndex = 0;
268
      mFirstIndex= 0;
269

    
270
      mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX,fY,lX,lY)/timeDiff : 0;
271
      }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
    private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
276
      {
277
      float xDist = mScreenWidth*(xFrom-xTo);
278
      float yDist = mScreenHeight*(yFrom-yTo);
279
      float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
280

    
281
      return distInPixels/mDensity;
282
      }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
    private void setUpDragOrRotate(float x, float y)
287
      {
288
        Static4D touchPoint = new Static4D(x, y, 0, 0);
289
        Static4D rotatedTouchPoint= rotateVectorByInvertedQuat(touchPoint, mQuat);
290
        Static4D rotatedCamera= rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
291

    
292
        if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera) )
293
          {
294
          mDragging           = false;
295
          mContinuingRotation = false;
296
          mBeginningRotation= !mPreRender.isTouchBlocked();
297
          }
298
        else
299
          {
300
          final TutorialActivity act = (TutorialActivity)getContext();
301
          boolean locked      = act.isLocked();
302
          mDragging           = !locked;
303
          mContinuingRotation = false;
304
          mBeginningRotation  = false;
305

    
306
          if( !mDragging )
307
            {
308
            TutorialState state = act.getState();
309
            state.reddenLock(act);
310
            }
311
          }
312
      }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
    private void drag(MotionEvent event, float x, float y)
317
      {
318
      if( mPtrID1!=INVALID_POINTER_ID && mPtrID2!=INVALID_POINTER_ID)
319
        {
320
        int pointer = event.findPointerIndex(mPtrID2);
321
        float pX,pY;
322

    
323
        try
324
          {
325
          pX = event.getX(pointer);
326
          pY = event.getY(pointer);
327
          }
328
        catch(IllegalArgumentException ex)
329
          {
330
          mPtrID1=INVALID_POINTER_ID;
331
          mPtrID2=INVALID_POINTER_ID;
332

    
333
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
334
          crashlytics.setCustomKey("DragError", "pointer="+pointer );
335
          crashlytics.recordException(ex);
336

    
337
          return;
338
          }
339

    
340
        float x2 = (pX - mScreenWidth*0.5f)/mScreenMin;
341
        float y2 = (mScreenHeight*0.5f -pY)/mScreenMin;
342

    
343
        float angleNow = getAngle(x,y,x2,y2);
344
        float angleDiff = angleNow-mRotAngle;
345
        float sinA =-(float)Math.sin(angleDiff);
346
        float cosA = (float)Math.cos(angleDiff);
347

    
348
        Static4D dragQuat = quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
349
        mTemp.set(dragQuat);
350

    
351
        mRotAngle = angleNow;
352

    
353
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
354
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
355
        mInitDistance = distNow;
356

    
357
        TwistyObject object = mPreRender.getObject();
358
        if( object!=null ) object.setObjectRatio(distQuot);
359
        }
360
      else
361
        {
362
        Static4D dragQuat = quatMultiply(quatFromDrag(mX-x,y-mY), mQuat);
363
        mTemp.set(dragQuat);
364
        }
365

    
366
      mPreRender.setQuatOnNextRender();
367
      mX = x;
368
      mY = y;
369
      }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
    private void finishRotation()
374
      {
375
      computeCurrentSpeedInInchesPerSecond();
376
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAxis,mCurrentAngle, mCurrRotSpeed);
377
      mPreRender.finishRotation(angle);
378

    
379
      if( angle!=0 )
380
        {
381
        final TutorialActivity act = (TutorialActivity)getContext();
382
        TutorialState state = act.getState();
383
        state.addMove(act,mCurrentAxis, mCurrentRow, angle);
384
        }
385

    
386
      mContinuingRotation = false;
387
      mBeginningRotation  = false;
388
      mDragging           = true;
389
      }
390

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392

    
393
    private void continueRotation(float x, float y)
394
      {
395
      float dx = x-mStartRotX;
396
      float dy = y-mStartRotY;
397
      float alpha = dx*mAxisX + dy*mAxisY;
398
      float x2 = dx - alpha*mAxisX;
399
      float y2 = dy - alpha*mAxisY;
400

    
401
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
402

    
403
      // we have the length of 1D vector 'angle', now the direction:
404
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
405

    
406
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
407
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
408
      mPreRender.getObject().continueRotation(mCurrentAngle);
409

    
410
      addSpeedProbe(x2,y2);
411
      }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
    private void beginRotation(float x, float y)
416
      {
417
      mStartRotX = x;
418
      mStartRotY = y;
419

    
420
      TwistyObject object = mPreRender.getObject();
421
      int numLayers = object.getNumLayers();
422

    
423
      Static4D touchPoint2 = new Static4D(x, y, 0, 0);
424
      Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuat);
425
      Static2D res = mMovement.newRotation(numLayers,rotatedTouchPoint2);
426

    
427
      mCurrentAxis = (int)res.get0();
428
      mCurrentRow  = (int)res.get1();
429

    
430
      computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
431
      mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
432

    
433
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
434

    
435
      addSpeedProbe(x,y);
436

    
437
      mBeginningRotation = false;
438
      mContinuingRotation= true;
439
      }
440

    
441
///////////////////////////////////////////////////////////////////////////////////////////////////
442

    
443
    private float getAngle(float x1, float y1, float x2, float y2)
444
      {
445
      return (float) Math.atan2(y1-y2, x1-x2);
446
      }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449

    
450
    private void actionMove(MotionEvent event)
451
      {
452
      int pointer = event.findPointerIndex(mPtrID1 != INVALID_POINTER_ID ? mPtrID1:mPtrID2);
453

    
454
      if( pointer<0 ) return;
455

    
456
      float pX = event.getX(pointer);
457
      float pY = event.getY(pointer);
458

    
459
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
460
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
461

    
462
      if( mBeginningRotation )
463
        {
464
        if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
465
          {
466
          beginRotation(x,y);
467
          }
468
        }
469
      else if( mContinuingRotation )
470
        {
471
        continueRotation(x,y);
472
        }
473
      else if( mDragging )
474
        {
475
        drag(event,x,y);
476
        }
477
      else
478
        {
479
        setUpDragOrRotate(x,y);
480
        }
481
      }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484

    
485
    private void actionDown(MotionEvent event)
486
      {
487
      mPtrID1 = event.getPointerId(0);
488

    
489
      float x = event.getX();
490
      float y = event.getY();
491

    
492
      mX = (x - mScreenWidth*0.5f)/mScreenMin;
493
      mY = (mScreenHeight*0.5f -y)/mScreenMin;
494

    
495
      setUpDragOrRotate(mX,mY);
496
      }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499

    
500
    private void actionUp(MotionEvent event)
501
      {
502
      mPtrID1 = INVALID_POINTER_ID;
503
      mPtrID2 = INVALID_POINTER_ID;
504

    
505
      if( mContinuingRotation )
506
        {
507
        finishRotation();
508
        }
509
      }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
    private void actionDown2(MotionEvent event)
514
      {
515
      int index = event.getActionIndex();
516

    
517
      if( mPtrID1==INVALID_POINTER_ID )
518
        {
519
        mPtrID1 = event.getPointerId(index);
520
        float x = event.getX();
521
        float y = event.getY();
522

    
523
        if( mPtrID2 != INVALID_POINTER_ID )
524
          {
525
          int pointer = event.findPointerIndex(mPtrID2);
526

    
527
          try
528
            {
529
            float x2 = event.getX(pointer);
530
            float y2 = event.getY(pointer);
531

    
532
            mRotAngle = getAngle(x,-y,x2,-y2);
533
            mInitDistance = -1;
534
            }
535
          catch(IllegalArgumentException ex)
536
            {
537
            mPtrID1=INVALID_POINTER_ID;
538
            mPtrID2=INVALID_POINTER_ID;
539

    
540
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
541
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
542
            crashlytics.recordException(ex);
543

    
544
            return;
545
            }
546
          }
547

    
548
        mX = (x - mScreenWidth*0.5f)/mScreenMin;
549
        mY = (mScreenHeight*0.5f -y)/mScreenMin;
550
        }
551
      else if( mPtrID2==INVALID_POINTER_ID )
552
        {
553
        mPtrID2 = event.getPointerId(index);
554

    
555
        float x = event.getX();
556
        float y = event.getY();
557

    
558
        if( mPtrID2 != INVALID_POINTER_ID )
559
          {
560
          int pointer = event.findPointerIndex(mPtrID2);
561

    
562
          try
563
            {
564
            float x2 = event.getX(pointer);
565
            float y2 = event.getY(pointer);
566

    
567
            mRotAngle = getAngle(x,-y,x2,-y2);
568
            mInitDistance = -1;
569
            }
570
          catch(IllegalArgumentException ex)
571
            {
572
            mPtrID1=INVALID_POINTER_ID;
573
            mPtrID2=INVALID_POINTER_ID;
574

    
575
            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
576
            crashlytics.setCustomKey("DragError", "pointer="+pointer );
577
            crashlytics.recordException(ex);
578

    
579
            return;
580
            }
581
          }
582

    
583
        if( mBeginningRotation || mContinuingRotation )
584
          {
585
          mX = (x - mScreenWidth*0.5f)/mScreenMin;
586
          mY = (mScreenHeight*0.5f -y)/mScreenMin;
587
          }
588
        }
589

    
590
      if( mBeginningRotation )
591
        {
592
        mContinuingRotation = false;
593
        mBeginningRotation  = false;
594
        mDragging           = true;
595
        }
596
      else if( mContinuingRotation )
597
        {
598
        finishRotation();
599
        }
600
      }
601

    
602
///////////////////////////////////////////////////////////////////////////////////////////////////
603

    
604
    private void actionUp2(MotionEvent event)
605
      {
606
      int index = event.getActionIndex();
607

    
608
      if( index==event.findPointerIndex(mPtrID1) )
609
        {
610
        mPtrID1 = INVALID_POINTER_ID;
611
        int pointer = event.findPointerIndex(mPtrID2);
612

    
613
        if( pointer>=0 )
614
          {
615
          float x1 = event.getX(pointer);
616
          float y1 = event.getY(pointer);
617

    
618
          mX = (x1 - mScreenWidth*0.5f)/mScreenMin;
619
          mY = (mScreenHeight*0.5f -y1)/mScreenMin;
620
          }
621
        }
622
      else if( index==event.findPointerIndex(mPtrID2) )
623
        {
624
        mPtrID2 = INVALID_POINTER_ID;
625
        }
626
      }
627

    
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

    
630
    void initialize()
631
      {
632
      mPtrID1 = INVALID_POINTER_ID;
633
      mPtrID2 = INVALID_POINTER_ID;
634
      }
635

    
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637
// PUBLIC API
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639

    
640
    public TutorialSurfaceView(Context context, AttributeSet attrs)
641
      {
642
      super(context,attrs);
643

    
644
      if(!isInEditMode())
645
        {
646
        mCurrRotSpeed= 0.0f;
647

    
648
        mLastX = new float[NUM_SPEED_PROBES];
649
        mLastY = new float[NUM_SPEED_PROBES];
650
        mLastT = new long[NUM_SPEED_PROBES];
651
        mFirstIndex =0;
652
        mLastIndex  =0;
653

    
654
        mRenderer  = new TutorialRenderer(this);
655
        mPreRender = new TutorialPreRender(this);
656

    
657
        TutorialActivity act = (TutorialActivity)context;
658
        DisplayMetrics dm = new DisplayMetrics();
659
        act.getWindowManager().getDefaultDisplay().getMetrics(dm);
660

    
661
        mDensity = dm.densityDpi;
662

    
663
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
664

    
665
        try
666
          {
667
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
668
          int esVersion = configurationInfo.reqGlEsVersion>>16;
669
          setEGLContextClientVersion(esVersion);
670
          setRenderer(mRenderer);
671
          }
672
        catch(Exception ex)
673
          {
674
          act.OpenGLError();
675

    
676
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
677
          String version = GLES30.glGetString(GLES30.GL_VERSION);
678
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
679
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
680

    
681
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
682
          crashlytics.setCustomKey("GLSL Version"  , shading );
683
          crashlytics.setCustomKey("GLversion"     , version );
684
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
685
          crashlytics.setCustomKey("GLSLrenderer"  , renderer);
686
          crashlytics.recordException(ex);
687
          }
688
        }
689
      }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
    @Override
694
    public boolean onTouchEvent(MotionEvent event)
695
      {
696
      int action = event.getActionMasked();
697

    
698
      switch(action)
699
         {
700
         case MotionEvent.ACTION_DOWN        : actionDown(event) ; break;
701
         case MotionEvent.ACTION_MOVE        : actionMove(event) ; break;
702
         case MotionEvent.ACTION_UP          : actionUp(event)   ; break;
703
         case MotionEvent.ACTION_POINTER_DOWN: actionDown2(event); break;
704
         case MotionEvent.ACTION_POINTER_UP  : actionUp2(event)  ; break;
705
         }
706

    
707
      return true;
708
      }
709
}
710

    
(6-6/7)