| 1 |
70b76549
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.objects;
|
| 21 |
70b76549
|
Leszek Koltunski
|
|
| 22 |
|
|
import android.content.SharedPreferences;
|
| 23 |
|
|
|
| 24 |
ac130d72
|
Leszek Koltunski
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
| 25 |
|
|
|
| 26 |
70b76549
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectMove;
|
| 27 |
|
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
| 28 |
|
|
import org.distorted.library.effect.MatrixEffectRotate;
|
| 29 |
|
|
import org.distorted.library.main.DistortedEffects;
|
| 30 |
|
|
import org.distorted.library.main.DistortedNode;
|
| 31 |
b32444ee
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
| 32 |
70b76549
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
| 33 |
|
|
import org.distorted.library.type.Dynamic1D;
|
| 34 |
|
|
import org.distorted.library.type.Static1D;
|
| 35 |
|
|
import org.distorted.library.type.Static3D;
|
| 36 |
|
|
import org.distorted.library.type.Static4D;
|
| 37 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.RubikSurfaceView;
|
| 38 |
70b76549
|
Leszek Koltunski
|
|
| 39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 40 |
|
|
|
| 41 |
|
|
class Cubit
|
| 42 |
|
|
{
|
| 43 |
|
|
private static final Static3D matrCenter = new Static3D(0,0,0);
|
| 44 |
|
|
|
| 45 |
|
|
private final Static3D mOrigPosition;
|
| 46 |
|
|
|
| 47 |
|
|
private RubikObject mParent;
|
| 48 |
b32444ee
|
Leszek Koltunski
|
private MeshBase mMesh;
|
| 49 |
70b76549
|
Leszek Koltunski
|
private Static3D mRotationAxis;
|
| 50 |
|
|
private MatrixEffectRotate mRotateEffect;
|
| 51 |
0e7bcfb1
|
Leszek Koltunski
|
private Static3D mCurrentPosition;
|
| 52 |
e844c116
|
Leszek Koltunski
|
private int mNumAxis;
|
| 53 |
70b76549
|
Leszek Koltunski
|
|
| 54 |
|
|
Dynamic1D mRotationAngle;
|
| 55 |
|
|
DistortedNode mNode;
|
| 56 |
|
|
DistortedEffects mEffect;
|
| 57 |
|
|
Static4D mQuatScramble;
|
| 58 |
66cbdd21
|
Leszek Koltunski
|
float[] mRotationRow;
|
| 59 |
70b76549
|
Leszek Koltunski
|
|
| 60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 61 |
|
|
// Because of quatMultiplication, errors can accumulate - so to avoid this, we
|
| 62 |
|
|
// correct the value of the 'scramble' quat to what it should be - one of the legal quats from the
|
| 63 |
|
|
// list LEGAL_QUATS.
|
| 64 |
|
|
//
|
| 65 |
|
|
// We also have to remember that the group of unit quaternions is a double-cover of rotations
|
| 66 |
|
|
// in 3D ( q represents the same rotation as -q ) - so invert if needed.
|
| 67 |
|
|
|
| 68 |
|
|
private void normalizeScrambleQuat(Static4D quat)
|
| 69 |
|
|
{
|
| 70 |
9f4c44fe
|
Leszek Koltunski
|
final float MAX_ERROR = 0.0001f;
|
| 71 |
|
|
|
| 72 |
70b76549
|
Leszek Koltunski
|
float x = quat.get0();
|
| 73 |
|
|
float y = quat.get1();
|
| 74 |
|
|
float z = quat.get2();
|
| 75 |
|
|
float w = quat.get3();
|
| 76 |
|
|
float diff;
|
| 77 |
|
|
|
| 78 |
|
|
for(float legal: mParent.LEGAL_QUATS)
|
| 79 |
|
|
{
|
| 80 |
|
|
diff = x-legal;
|
| 81 |
9f4c44fe
|
Leszek Koltunski
|
if( diff*diff<MAX_ERROR ) x = legal;
|
| 82 |
70b76549
|
Leszek Koltunski
|
diff = y-legal;
|
| 83 |
9f4c44fe
|
Leszek Koltunski
|
if( diff*diff<MAX_ERROR ) y = legal;
|
| 84 |
70b76549
|
Leszek Koltunski
|
diff = z-legal;
|
| 85 |
9f4c44fe
|
Leszek Koltunski
|
if( diff*diff<MAX_ERROR ) z = legal;
|
| 86 |
70b76549
|
Leszek Koltunski
|
diff = w-legal;
|
| 87 |
9f4c44fe
|
Leszek Koltunski
|
if( diff*diff<MAX_ERROR ) w = legal;
|
| 88 |
70b76549
|
Leszek Koltunski
|
}
|
| 89 |
|
|
|
| 90 |
|
|
if( w<0 )
|
| 91 |
|
|
{
|
| 92 |
|
|
w = -w;
|
| 93 |
|
|
z = -z;
|
| 94 |
|
|
y = -y;
|
| 95 |
|
|
x = -x;
|
| 96 |
|
|
}
|
| 97 |
|
|
else if( w==0 )
|
| 98 |
|
|
{
|
| 99 |
|
|
if( z<0 )
|
| 100 |
|
|
{
|
| 101 |
|
|
z = -z;
|
| 102 |
|
|
y = -y;
|
| 103 |
|
|
x = -x;
|
| 104 |
|
|
}
|
| 105 |
|
|
else if( z==0 )
|
| 106 |
|
|
{
|
| 107 |
|
|
if( y<0 )
|
| 108 |
|
|
{
|
| 109 |
|
|
y = -y;
|
| 110 |
|
|
x = -x;
|
| 111 |
|
|
}
|
| 112 |
|
|
else if( y==0 )
|
| 113 |
|
|
{
|
| 114 |
|
|
if( x<0 )
|
| 115 |
|
|
{
|
| 116 |
|
|
x = -x;
|
| 117 |
|
|
}
|
| 118 |
|
|
}
|
| 119 |
|
|
}
|
| 120 |
|
|
}
|
| 121 |
|
|
|
| 122 |
|
|
quat.set(x,y,z,w);
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 126 |
|
|
|
| 127 |
94ad5a8f
|
Leszek Koltunski
|
private void modifyCurrentPosition(Static4D quat)
|
| 128 |
70b76549
|
Leszek Koltunski
|
{
|
| 129 |
94ad5a8f
|
Leszek Koltunski
|
float cubitCenterX = mCurrentPosition.get0();
|
| 130 |
|
|
float cubitCenterY = mCurrentPosition.get1();
|
| 131 |
|
|
float cubitCenterZ = mCurrentPosition.get2();
|
| 132 |
70b76549
|
Leszek Koltunski
|
|
| 133 |
|
|
Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0);
|
| 134 |
|
|
Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat);
|
| 135 |
|
|
|
| 136 |
49f67f9b
|
Leszek Koltunski
|
float rotatedX = rotatedCenter.get0();
|
| 137 |
|
|
float rotatedY = rotatedCenter.get1();
|
| 138 |
|
|
float rotatedZ = rotatedCenter.get2();
|
| 139 |
70b76549
|
Leszek Koltunski
|
|
| 140 |
94ad5a8f
|
Leszek Koltunski
|
mCurrentPosition.set(rotatedX, rotatedY, rotatedZ);
|
| 141 |
|
|
mParent.clampPos(mCurrentPosition);
|
| 142 |
70b76549
|
Leszek Koltunski
|
|
| 143 |
10a2e360
|
Leszek Koltunski
|
computeRotationRow();
|
| 144 |
|
|
}
|
| 145 |
|
|
|
| 146 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 147 |
e844c116
|
Leszek Koltunski
|
// cast current position on axis; use mStart and mStep to compute the rotation row for each axis.
|
| 148 |
10a2e360
|
Leszek Koltunski
|
|
| 149 |
|
|
private void computeRotationRow()
|
| 150 |
|
|
{
|
| 151 |
e844c116
|
Leszek Koltunski
|
float tmp;
|
| 152 |
|
|
Static3D axis;
|
| 153 |
|
|
float x = mCurrentPosition.get0();
|
| 154 |
|
|
float y = mCurrentPosition.get1();
|
| 155 |
|
|
float z = mCurrentPosition.get2();
|
| 156 |
|
|
|
| 157 |
|
|
for(int i=0; i<mNumAxis; i++)
|
| 158 |
|
|
{
|
| 159 |
|
|
axis = mParent.ROTATION_AXIS[i];
|
| 160 |
|
|
tmp = x*axis.get0() + y*axis.get1() + z*axis.get2();
|
| 161 |
66cbdd21
|
Leszek Koltunski
|
mRotationRow[i] = (tmp-mParent.mStart)/mParent.mStep;
|
| 162 |
e844c116
|
Leszek Koltunski
|
}
|
| 163 |
70b76549
|
Leszek Koltunski
|
}
|
| 164 |
|
|
|
| 165 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 166 |
|
|
|
| 167 |
b32444ee
|
Leszek Koltunski
|
Cubit(RubikObject parent, MeshBase mesh, Static3D position)
|
| 168 |
70b76549
|
Leszek Koltunski
|
{
|
| 169 |
|
|
float x = position.get0();
|
| 170 |
|
|
float y = position.get1();
|
| 171 |
|
|
float z = position.get2();
|
| 172 |
|
|
|
| 173 |
49f67f9b
|
Leszek Koltunski
|
Static3D vector = new Static3D(x,y,z);
|
| 174 |
70b76549
|
Leszek Koltunski
|
|
| 175 |
|
|
mParent = parent;
|
| 176 |
b32444ee
|
Leszek Koltunski
|
mMesh = mesh;
|
| 177 |
70b76549
|
Leszek Koltunski
|
mOrigPosition = new Static3D(x,y,z);
|
| 178 |
|
|
mQuatScramble = new Static4D(0,0,0,1);
|
| 179 |
|
|
mRotationAngle = new Dynamic1D();
|
| 180 |
|
|
mRotationAxis = new Static3D(1,0,0);
|
| 181 |
|
|
mCurrentPosition = position;
|
| 182 |
|
|
mRotateEffect = new MatrixEffectRotate(mRotationAngle, mRotationAxis, matrCenter);
|
| 183 |
|
|
|
| 184 |
e844c116
|
Leszek Koltunski
|
mNumAxis = mParent.ROTATION_AXIS.length;
|
| 185 |
66cbdd21
|
Leszek Koltunski
|
mRotationRow = new float[mNumAxis];
|
| 186 |
10a2e360
|
Leszek Koltunski
|
computeRotationRow();
|
| 187 |
|
|
|
| 188 |
36273130
|
Leszek Koltunski
|
mEffect = new DistortedEffects();
|
| 189 |
70b76549
|
Leszek Koltunski
|
mEffect.apply(mParent.mSinkEffect);
|
| 190 |
|
|
mEffect.apply( new MatrixEffectMove(vector) );
|
| 191 |
|
|
mEffect.apply( new MatrixEffectQuaternion(mQuatScramble, matrCenter));
|
| 192 |
|
|
mEffect.apply(mRotateEffect);
|
| 193 |
|
|
mEffect.apply(mParent.mQuatAEffect);
|
| 194 |
|
|
mEffect.apply(mParent.mQuatCEffect);
|
| 195 |
|
|
mEffect.apply(mParent.mScaleEffect);
|
| 196 |
|
|
|
| 197 |
b32444ee
|
Leszek Koltunski
|
mNode = new DistortedNode(mParent.mTexture,mEffect,mMesh);
|
| 198 |
70b76549
|
Leszek Koltunski
|
}
|
| 199 |
|
|
|
| 200 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 201 |
|
|
|
| 202 |
|
|
void savePreferences(SharedPreferences.Editor editor)
|
| 203 |
|
|
{
|
| 204 |
|
|
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
| 205 |
|
|
|
| 206 |
|
|
editor.putFloat("qx_"+number, mQuatScramble.get0());
|
| 207 |
|
|
editor.putFloat("qy_"+number, mQuatScramble.get1());
|
| 208 |
|
|
editor.putFloat("qz_"+number, mQuatScramble.get2());
|
| 209 |
|
|
editor.putFloat("qw_"+number, mQuatScramble.get3());
|
| 210 |
|
|
}
|
| 211 |
|
|
|
| 212 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 213 |
|
|
|
| 214 |
|
|
void restorePreferences(SharedPreferences preferences)
|
| 215 |
|
|
{
|
| 216 |
|
|
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
| 217 |
|
|
|
| 218 |
|
|
float qx = preferences.getFloat("qx_"+number, 0.0f);
|
| 219 |
|
|
float qy = preferences.getFloat("qy_"+number, 0.0f);
|
| 220 |
|
|
float qz = preferences.getFloat("qz_"+number, 0.0f);
|
| 221 |
|
|
float qw = preferences.getFloat("qw_"+number, 1.0f);
|
| 222 |
|
|
|
| 223 |
|
|
mQuatScramble.set(qx,qy,qz,qw);
|
| 224 |
94ad5a8f
|
Leszek Koltunski
|
modifyCurrentPosition(mQuatScramble);
|
| 225 |
|
|
}
|
| 226 |
|
|
|
| 227 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 228 |
|
|
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
|
| 229 |
|
|
// then if it were rotated by quaternion 'quat'.
|
| 230 |
|
|
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two
|
| 231 |
|
|
// middle squares get interchanged. No visible difference!
|
| 232 |
|
|
//
|
| 233 |
|
|
// So: this is true iff the cubit
|
| 234 |
|
|
// a) is a corner or edge and the quaternions are the same
|
| 235 |
|
|
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
|
| 236 |
|
|
|
| 237 |
|
|
boolean thereIsNoVisibleDifference(Static4D quat)
|
| 238 |
|
|
{
|
| 239 |
|
|
if ( mQuatScramble.get0()==quat.get0() &&
|
| 240 |
|
|
mQuatScramble.get1()==quat.get1() &&
|
| 241 |
|
|
mQuatScramble.get2()==quat.get2() &&
|
| 242 |
|
|
mQuatScramble.get3()==quat.get3() ) return true;
|
| 243 |
|
|
|
| 244 |
|
|
int belongsToHowManyFaces = 0;
|
| 245 |
|
|
int size = mParent.getSize()-1;
|
| 246 |
7437ebb3
|
Leszek Koltunski
|
float row;
|
| 247 |
|
|
final float MAX_ERROR = 0.01f;
|
| 248 |
94ad5a8f
|
Leszek Koltunski
|
|
| 249 |
|
|
for(int i=0; i<mNumAxis; i++)
|
| 250 |
|
|
{
|
| 251 |
7437ebb3
|
Leszek Koltunski
|
row = mRotationRow[i];
|
| 252 |
|
|
if( (row <MAX_ERROR && row >-MAX_ERROR) ||
|
| 253 |
|
|
(row-size<MAX_ERROR && row-size>-MAX_ERROR) ) belongsToHowManyFaces++;
|
| 254 |
94ad5a8f
|
Leszek Koltunski
|
}
|
| 255 |
|
|
|
| 256 |
|
|
switch(belongsToHowManyFaces)
|
| 257 |
|
|
{
|
| 258 |
|
|
case 0 : return true ; // 'inside' cubit that does not lie on any face
|
| 259 |
|
|
case 1 : // cubit that lies inside one of the faces
|
| 260 |
|
|
float cubitCenterX = mCurrentPosition.get0();
|
| 261 |
|
|
float cubitCenterY = mCurrentPosition.get1();
|
| 262 |
|
|
float cubitCenterZ = mCurrentPosition.get2();
|
| 263 |
|
|
|
| 264 |
|
|
Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0);
|
| 265 |
|
|
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat);
|
| 266 |
|
|
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, mQuatScramble );
|
| 267 |
|
|
|
| 268 |
7437ebb3
|
Leszek Koltunski
|
float row1, row2, row3, row4;
|
| 269 |
94ad5a8f
|
Leszek Koltunski
|
float ax,ay,az;
|
| 270 |
|
|
Static3D axis;
|
| 271 |
|
|
float x1 = rotated1.get0();
|
| 272 |
|
|
float y1 = rotated1.get1();
|
| 273 |
|
|
float z1 = rotated1.get2();
|
| 274 |
|
|
float x2 = rotated2.get0();
|
| 275 |
|
|
float y2 = rotated2.get1();
|
| 276 |
|
|
float z2 = rotated2.get2();
|
| 277 |
|
|
|
| 278 |
|
|
for(int i=0; i<mNumAxis; i++)
|
| 279 |
|
|
{
|
| 280 |
|
|
axis = mParent.ROTATION_AXIS[i];
|
| 281 |
|
|
ax = axis.get0();
|
| 282 |
|
|
ay = axis.get1();
|
| 283 |
|
|
az = axis.get2();
|
| 284 |
|
|
|
| 285 |
7437ebb3
|
Leszek Koltunski
|
row1 = ((x1*ax + y1*ay + z1*az) - mParent.mStart) / mParent.mStep;
|
| 286 |
|
|
row2 = ((x2*ax + y2*ay + z2*az) - mParent.mStart) / mParent.mStep;
|
| 287 |
|
|
row3 = row1 - size;
|
| 288 |
|
|
row4 = row2 - size;
|
| 289 |
94ad5a8f
|
Leszek Koltunski
|
|
| 290 |
7437ebb3
|
Leszek Koltunski
|
if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) ||
|
| 291 |
|
|
(row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR) )
|
| 292 |
94ad5a8f
|
Leszek Koltunski
|
{
|
| 293 |
|
|
return true;
|
| 294 |
|
|
}
|
| 295 |
|
|
}
|
| 296 |
|
|
return false;
|
| 297 |
|
|
default: return false; // edge or corner
|
| 298 |
|
|
}
|
| 299 |
70b76549
|
Leszek Koltunski
|
}
|
| 300 |
|
|
|
| 301 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 302 |
|
|
|
| 303 |
|
|
long finishRotationNow(EffectListener listener)
|
| 304 |
|
|
{
|
| 305 |
|
|
int pointNum = mRotationAngle.getNumPoints();
|
| 306 |
|
|
|
| 307 |
|
|
if( pointNum>=1 )
|
| 308 |
|
|
{
|
| 309 |
|
|
float startingAngle = mRotationAngle.getPoint(pointNum-1).get0();
|
| 310 |
0e5ad27c
|
Leszek Koltunski
|
int nearestAngleInDegrees = mParent.computeNearestAngle(startingAngle);
|
| 311 |
70b76549
|
Leszek Koltunski
|
mParent.mRotationAngleStatic.set0(startingAngle);
|
| 312 |
|
|
mParent.mRotationAngleFinal.set0(nearestAngleInDegrees);
|
| 313 |
|
|
mParent.mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
|
| 314 |
|
|
return setUpCallback(listener);
|
| 315 |
|
|
}
|
| 316 |
ac130d72
|
Leszek Koltunski
|
else
|
| 317 |
|
|
{
|
| 318 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
| 319 |
|
|
crashlytics.setCustomKey("points", "finish, points in RotationAngle: "+pointNum );
|
| 320 |
|
|
return 0;
|
| 321 |
|
|
}
|
| 322 |
70b76549
|
Leszek Koltunski
|
}
|
| 323 |
|
|
|
| 324 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 325 |
|
|
|
| 326 |
efef689c
|
Leszek Koltunski
|
Static4D returnRotationQuat(int axis)
|
| 327 |
70b76549
|
Leszek Koltunski
|
{
|
| 328 |
|
|
int pointNum = mRotationAngle.getNumPoints();
|
| 329 |
|
|
|
| 330 |
|
|
if( pointNum>=1 )
|
| 331 |
|
|
{
|
| 332 |
efef689c
|
Leszek Koltunski
|
float axisX = mParent.ROTATION_AXIS[axis].get0();
|
| 333 |
|
|
float axisY = mParent.ROTATION_AXIS[axis].get1();
|
| 334 |
|
|
float axisZ = mParent.ROTATION_AXIS[axis].get2();
|
| 335 |
|
|
|
| 336 |
70b76549
|
Leszek Koltunski
|
float startingAngle = mRotationAngle.getPoint(pointNum-1).get0();
|
| 337 |
0e5ad27c
|
Leszek Koltunski
|
int nearestAngleInDegrees = mParent.computeNearestAngle(startingAngle);
|
| 338 |
70b76549
|
Leszek Koltunski
|
double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180;
|
| 339 |
|
|
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
|
| 340 |
|
|
float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
|
| 341 |
efef689c
|
Leszek Koltunski
|
return new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
|
| 342 |
70b76549
|
Leszek Koltunski
|
}
|
| 343 |
ac130d72
|
Leszek Koltunski
|
else
|
| 344 |
|
|
{
|
| 345 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
| 346 |
|
|
crashlytics.setCustomKey("points", "return, points in RotationAngle: "+pointNum );
|
| 347 |
|
|
return null;
|
| 348 |
|
|
}
|
| 349 |
70b76549
|
Leszek Koltunski
|
}
|
| 350 |
|
|
|
| 351 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 352 |
|
|
|
| 353 |
|
|
void removeRotationNow(Static4D quat)
|
| 354 |
|
|
{
|
| 355 |
|
|
mRotationAngle.removeAll();
|
| 356 |
|
|
mQuatScramble.set(RubikSurfaceView.quatMultiply(quat,mQuatScramble));
|
| 357 |
|
|
normalizeScrambleQuat( mQuatScramble );
|
| 358 |
94ad5a8f
|
Leszek Koltunski
|
modifyCurrentPosition(quat);
|
| 359 |
70b76549
|
Leszek Koltunski
|
}
|
| 360 |
|
|
|
| 361 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 362 |
|
|
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of
|
| 363 |
|
|
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major
|
| 364 |
|
|
// memory leak.
|
| 365 |
|
|
|
| 366 |
|
|
void releaseResources()
|
| 367 |
|
|
{
|
| 368 |
b32444ee
|
Leszek Koltunski
|
mMesh.markForDeletion();
|
| 369 |
70b76549
|
Leszek Koltunski
|
mNode.markForDeletion();
|
| 370 |
|
|
}
|
| 371 |
|
|
|
| 372 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 373 |
|
|
|
| 374 |
|
|
void solve()
|
| 375 |
|
|
{
|
| 376 |
|
|
mQuatScramble.set(0,0,0,1);
|
| 377 |
|
|
mCurrentPosition.set(mOrigPosition);
|
| 378 |
0e7bcfb1
|
Leszek Koltunski
|
computeRotationRow();
|
| 379 |
70b76549
|
Leszek Koltunski
|
}
|
| 380 |
|
|
|
| 381 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 382 |
|
|
|
| 383 |
efef689c
|
Leszek Koltunski
|
void beginNewRotation(int axis)
|
| 384 |
70b76549
|
Leszek Koltunski
|
{
|
| 385 |
efef689c
|
Leszek Koltunski
|
mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
|
| 386 |
70b76549
|
Leszek Koltunski
|
mRotationAngle.add(mParent.mRotationAngleStatic);
|
| 387 |
|
|
}
|
| 388 |
|
|
|
| 389 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 390 |
|
|
|
| 391 |
efef689c
|
Leszek Koltunski
|
void addNewRotation(int axis, long durationMillis, int angle)
|
| 392 |
70b76549
|
Leszek Koltunski
|
{
|
| 393 |
efef689c
|
Leszek Koltunski
|
mRotationAxis.set( mParent.ROTATION_AXIS[axis] );
|
| 394 |
70b76549
|
Leszek Koltunski
|
mRotationAngle.setDuration(durationMillis);
|
| 395 |
|
|
mRotationAngle.resetToBeginning();
|
| 396 |
|
|
mRotationAngle.add(new Static1D(0));
|
| 397 |
|
|
mRotationAngle.add(new Static1D(angle));
|
| 398 |
|
|
}
|
| 399 |
|
|
|
| 400 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 401 |
|
|
|
| 402 |
|
|
long setUpCallback(EffectListener listener)
|
| 403 |
|
|
{
|
| 404 |
|
|
mRotateEffect.notifyWhenFinished(listener);
|
| 405 |
|
|
return mRotateEffect.getID();
|
| 406 |
|
|
}
|
| 407 |
1f9772f3
|
Leszek Koltunski
|
|
| 408 |
9621255f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 409 |
|
|
|
| 410 |
|
|
float getDistSquared(float[] point)
|
| 411 |
|
|
{
|
| 412 |
|
|
float dx = mCurrentPosition.get0() - point[0];
|
| 413 |
|
|
float dy = mCurrentPosition.get1() - point[1];
|
| 414 |
|
|
float dz = mCurrentPosition.get2() - point[2];
|
| 415 |
|
|
|
| 416 |
|
|
return dx*dx + dy*dy + dz*dz;
|
| 417 |
|
|
}
|
| 418 |
|
|
|
| 419 |
a304ee64
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 420 |
|
|
|
| 421 |
|
|
int getColorIndex(int face)
|
| 422 |
|
|
{
|
| 423 |
|
|
Static4D texMap = mMesh.getTextureMap(face);
|
| 424 |
|
|
return (int)(texMap.get0() / texMap.get2());
|
| 425 |
|
|
}
|
| 426 |
|
|
|
| 427 |
1f9772f3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 428 |
|
|
|
| 429 |
|
|
MeshBase getMesh()
|
| 430 |
|
|
{
|
| 431 |
|
|
return mMesh;
|
| 432 |
|
|
}
|
| 433 |
70b76549
|
Leszek Koltunski
|
}
|