1 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
da56b12f
|
Leszek Koltunski
|
// Copyright 2022 Leszek Koltunski //
|
3 |
9530f6b0
|
Leszek Koltunski
|
// //
|
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.bandaged;
|
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 |
da56b12f
|
Leszek Koltunski
|
import android.view.MotionEvent;
|
29 |
9530f6b0
|
Leszek Koltunski
|
|
30 |
|
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
31 |
|
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
public class BandagedCreatorView extends GLSurfaceView
|
35 |
|
|
{
|
36 |
da56b12f
|
Leszek Koltunski
|
private final static int DIRECTION_SENSITIVITY= 12;
|
37 |
|
|
private int mX, mY;
|
38 |
9530f6b0
|
Leszek Koltunski
|
private BandagedCreatorRenderer mRenderer;
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// PUBLIC API
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
public BandagedCreatorView(Context context, AttributeSet attrs)
|
45 |
|
|
{
|
46 |
|
|
super(context,attrs);
|
47 |
|
|
|
48 |
da56b12f
|
Leszek Koltunski
|
mX = -1;
|
49 |
|
|
mY = -1;
|
50 |
|
|
|
51 |
9530f6b0
|
Leszek Koltunski
|
if(!isInEditMode())
|
52 |
|
|
{
|
53 |
|
|
BandagedCreatorActivity act = (BandagedCreatorActivity)context;
|
54 |
|
|
mRenderer = new BandagedCreatorRenderer(this);
|
55 |
|
|
|
56 |
|
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
57 |
|
|
|
58 |
|
|
try
|
59 |
|
|
{
|
60 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
61 |
|
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
62 |
|
|
setEGLContextClientVersion(esVersion);
|
63 |
|
|
setRenderer(mRenderer);
|
64 |
|
|
}
|
65 |
|
|
catch(Exception ex)
|
66 |
|
|
{
|
67 |
|
|
act.OpenGLError();
|
68 |
|
|
|
69 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
70 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
71 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
72 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
73 |
|
|
|
74 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
75 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
76 |
|
|
crashlytics.setCustomKey("GL version" , version );
|
77 |
|
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
78 |
|
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
79 |
|
|
crashlytics.recordException(ex);
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
da56b12f
|
Leszek Koltunski
|
private void resetQuats()
|
87 |
9530f6b0
|
Leszek Koltunski
|
{
|
88 |
da56b12f
|
Leszek Koltunski
|
float qx = mRenderer.mQuat1.get0();
|
89 |
|
|
float qy = mRenderer.mQuat1.get1();
|
90 |
|
|
float qz = mRenderer.mQuat1.get2();
|
91 |
|
|
float qw = mRenderer.mQuat1.get3();
|
92 |
|
|
|
93 |
|
|
float rx = mRenderer.mQuat2.get0();
|
94 |
|
|
float ry = mRenderer.mQuat2.get1();
|
95 |
|
|
float rz = mRenderer.mQuat2.get2();
|
96 |
|
|
float rw = mRenderer.mQuat2.get3();
|
97 |
|
|
|
98 |
|
|
float tx = rw*qx - rz*qy + ry*qz + rx*qw;
|
99 |
|
|
float ty = rw*qy + rz*qx + ry*qw - rx*qz;
|
100 |
|
|
float tz = rw*qz + rz*qw - ry*qx + rx*qy;
|
101 |
|
|
float tw = rw*qw - rz*qz - ry*qy - rx*qx;
|
102 |
|
|
|
103 |
|
|
mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
|
104 |
|
|
mRenderer.mQuat2.set(tx, ty, tz, tw);
|
105 |
9530f6b0
|
Leszek Koltunski
|
}
|
106 |
da56b12f
|
Leszek Koltunski
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
@Override public boolean onTouchEvent(MotionEvent event)
|
110 |
|
|
{
|
111 |
|
|
int action = event.getAction();
|
112 |
|
|
int x = (int)event.getX();
|
113 |
|
|
int y = (int)event.getY();
|
114 |
|
|
|
115 |
|
|
switch(action)
|
116 |
|
|
{
|
117 |
|
|
case MotionEvent.ACTION_DOWN: mX = x;
|
118 |
|
|
mY = y;
|
119 |
|
|
break;
|
120 |
|
|
|
121 |
|
|
case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
|
122 |
|
|
{
|
123 |
|
|
float px = mY-y;
|
124 |
|
|
float py = mX-x;
|
125 |
|
|
float pz = 0;
|
126 |
|
|
float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
|
127 |
|
|
|
128 |
|
|
if( plen>0 )
|
129 |
|
|
{
|
130 |
|
|
px /= plen;
|
131 |
|
|
py /= plen;
|
132 |
|
|
pz /= plen;
|
133 |
|
|
|
134 |
|
|
float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
|
135 |
|
|
float sinA = (float)Math.sqrt(1-cosA*cosA);
|
136 |
|
|
|
137 |
|
|
mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
|
141 |
|
|
{
|
142 |
|
|
mX = x;
|
143 |
|
|
mY = y;
|
144 |
|
|
resetQuats();
|
145 |
|
|
}
|
146 |
|
|
break;
|
147 |
|
|
|
148 |
|
|
case MotionEvent.ACTION_UP : mX = -1;
|
149 |
|
|
mY = -1;
|
150 |
|
|
resetQuats();
|
151 |
|
|
break;
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
return true;
|
155 |
|
|
}
|
156 |
9530f6b0
|
Leszek Koltunski
|
}
|