Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorial / TutorialSurfaceView.java @ af88bf2e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.tutorial;
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
import org.distorted.states.RubikStateSolving;
38
import org.distorted.states.StateList;
39

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

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

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

    
53
    private final Static4D CAMERA_POINT = new Static4D(0, 0, 1, 0);
54

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

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

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

    
85
      mScreenMin = Math.min(width, height);
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
    boolean isVertical()
91
      {
92
      return mScreenHeight>mScreenWidth;
93
      }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
    TutorialRenderer getRenderer()
98
      {
99
      return mRenderer;
100
      }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
    TutorialPreRender getPreRender()
105
      {
106
      return mPreRender;
107
      }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
    void setQuat()
112
      {
113
      mQuat.set(mTemp);
114
      }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
    Static4D getQuat()
119
      {
120
      return mQuat;
121
      }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
    void setMovement(Movement movement)
126
      {
127
      mMovement = movement;
128
      }
129

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

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

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

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

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

    
151
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
152
        }
153

    
154
      return new Static4D(0f, 0f, 0f, 1f);
155
      }
156

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

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

    
165
      mAxisX =result.get0();
166
      mAxisY =result.get1();
167

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

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
// return quat1*quat2
175

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

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

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

    
193
      return new Static4D(tx,ty,tz,tw);
194
      }
195

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

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

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

    
209
      return quatMultiply(tmp,quatInverted);
210
      }
211

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

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

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

    
225
      return quatMultiply(tmp,quat);
226
      }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

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

    
235
      mLastIndex++;
236
      if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
237

    
238
      mLastT[mLastIndex] = currTime;
239
      mLastX[mLastIndex] = x;
240
      mLastY[mLastIndex] = y;
241

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

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

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

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

    
267
      long timeDiff = lastTime-firstTime;
268

    
269
      mLastIndex = 0;
270
      mFirstIndex= 0;
271

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

    
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

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

    
283
      return distInPixels/mDensity;
284
      }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287

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

    
294
        if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera) )
295
          {
296
          mDragging           = false;
297
          mContinuingRotation = false;
298
          mBeginningRotation  = true;
299
          }
300
        else
301
          {
302
          final TutorialActivity act = (TutorialActivity)getContext();
303
          mDragging           = !act.isLocked();
304
          mContinuingRotation = false;
305
          mBeginningRotation  = false;
306
          }
307
      }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
    private void drag(MotionEvent event, float x, float y)
312
      {
313
      if( mPtrID1!=INVALID_POINTER_ID && mPtrID2!=INVALID_POINTER_ID)
314
        {
315
        int pointer = event.findPointerIndex(mPtrID2);
316
        float pX,pY;
317

    
318
        try
319
          {
320
          pX = event.getX(pointer);
321
          pY = event.getY(pointer);
322
          }
323
        catch(IllegalArgumentException ex)
324
          {
325
          mPtrID1=INVALID_POINTER_ID;
326
          mPtrID2=INVALID_POINTER_ID;
327

    
328
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
329
          crashlytics.setCustomKey("DragError", "pointer="+pointer );
330
          crashlytics.recordException(ex);
331

    
332
          return;
333
          }
334

    
335
        float x2 = (pX - mScreenWidth*0.5f)/mScreenMin;
336
        float y2 = (mScreenHeight*0.5f -pY)/mScreenMin;
337

    
338
        float angleNow = getAngle(x,y,x2,y2);
339
        float angleDiff = angleNow-mRotAngle;
340
        float sinA =-(float)Math.sin(angleDiff);
341
        float cosA = (float)Math.cos(angleDiff);
342

    
343
        Static4D dragQuat = quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
344
        mTemp.set(dragQuat);
345

    
346
        mRotAngle = angleNow;
347

    
348
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
349
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
350
        mInitDistance = distNow;
351

    
352
        TwistyObject object = mPreRender.getObject();
353
        if( object!=null ) object.setObjectRatio(distQuot);
354
        }
355
      else
356
        {
357
        Static4D dragQuat = quatMultiply(quatFromDrag(mX-x,y-mY), mQuat);
358
        mTemp.set(dragQuat);
359
        }
360

    
361
      mPreRender.setQuatOnNextRender();
362
      mX = x;
363
      mY = y;
364
      }
365

    
366
///////////////////////////////////////////////////////////////////////////////////////////////////
367

    
368
    private void finishRotation()
369
      {
370
      computeCurrentSpeedInInchesPerSecond();
371
      int angle = mPreRender.getObject().computeNearestAngle(mCurrentAngle, mCurrRotSpeed);
372
      mPreRender.finishRotation(angle);
373

    
374
////////////
375
// TODO
376
      if( angle!=0 )
377
        {
378
        if( StateList.getCurrentState()== StateList.SOLV )
379
          {
380
          RubikStateSolving solving = (RubikStateSolving) StateList.SOLV.getStateClass();
381
          solving.addMove(mCurrentAxis, mCurrentRow, angle);
382
          }
383
        }
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

    
(4-4/4)