Revision 57ef6378
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.touchcontrol; |
21 | 21 |
|
22 |
import org.distorted.library.type.Static2D;
|
|
22 |
import org.distorted.library.main.QuatHelper;
|
|
23 | 23 |
import org.distorted.library.type.Static3D; |
24 | 24 |
import org.distorted.library.type.Static4D; |
25 |
import org.distorted.objectlib.main.TwistyObject; |
|
25 | 26 |
|
26 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 28 |
|
... | ... | |
41 | 42 |
private float[][][] mCastedRotAxis; |
42 | 43 |
private Static4D[][] mCastedRotAxis4D; |
43 | 44 |
private float[][] mTouchBorders, mA, mB; |
44 |
private float mObjectRatio; |
|
45 | 45 |
|
46 |
private final int mType;
|
|
46 |
private final int mSplit;
|
|
47 | 47 |
private final int[][][] mEnabled; |
48 | 48 |
|
49 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
53 | 53 |
|
54 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 55 |
|
56 |
TouchControlShapeConstant(Static3D[] rotAxis, Static3D[] faceAxis, float[][] cuts, boolean[][] rotatable, |
|
57 |
float[] distance3D, float size, int type, int[][][] enabled) |
|
56 |
TouchControlShapeConstant(TwistyObject object, float[] distance3D, Static3D[] faceAxis) |
|
58 | 57 |
{ |
58 |
int[] numLayers = object.getNumLayers(); |
|
59 |
float[][] cuts = object.getCuts(numLayers); |
|
60 |
boolean[][] rotatable = object.getLayerRotatable(numLayers); |
|
61 |
float size = object.getSize(); |
|
62 |
Static3D[] rotAxis = object.getRotationAxis(); |
|
63 |
|
|
59 | 64 |
mPoint = new float[3]; |
60 | 65 |
mCamera= new float[3]; |
61 | 66 |
mTouch = new float[3]; |
... | ... | |
63 | 68 |
mPoint2D = new float[2]; |
64 | 69 |
mMove2D = new float[2]; |
65 | 70 |
|
66 |
mType = type; |
|
67 |
mEnabled = enabled; |
|
68 |
mObjectRatio= 1.0f; |
|
71 |
mSplit = object.getMovementSplit(); |
|
72 |
mEnabled = object.getEnabled(); |
|
69 | 73 |
mFaceAxis = faceAxis; |
70 | 74 |
mNumFaceAxis= mFaceAxis.length; |
71 | 75 |
|
... | ... | |
401 | 405 |
|
402 | 406 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
403 | 407 |
{ |
404 |
int part = returnPart(mType,face,touchPoint);
|
|
408 |
int part = returnPart(mSplit,face,touchPoint);
|
|
405 | 409 |
|
406 | 410 |
int num = mEnabled[face][0].length; |
407 | 411 |
enabled[0] = num; |
... | ... | |
412 | 416 |
// PUBLIC API |
413 | 417 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
414 | 418 |
|
415 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera)
|
|
419 |
public boolean objectTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera)
|
|
416 | 420 |
{ |
417 | 421 |
mPoint[0] = rotatedTouchPoint.get0()/mObjectRatio; |
418 | 422 |
mPoint[1] = rotatedTouchPoint.get1()/mObjectRatio; |
... | ... | |
437 | 441 |
|
438 | 442 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
439 | 443 |
|
440 |
public Static2D newRotation(Static4D rotatedTouchPoint)
|
|
444 |
public void newRotation(int[] output, Static4D rotatedTouchPoint)
|
|
441 | 445 |
{ |
442 | 446 |
mPoint[0] = rotatedTouchPoint.get0()/mObjectRatio; |
443 | 447 |
mPoint[1] = rotatedTouchPoint.get1()/mObjectRatio; |
... | ... | |
454 | 458 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]); |
455 | 459 |
int row = computeRowFromOffset(mLastTouchedFace,rotIndex,offset); |
456 | 460 |
|
457 |
return new Static2D(rotIndex,row); |
|
461 |
output[0] = rotIndex; |
|
462 |
output[1] = row; |
|
458 | 463 |
} |
459 | 464 |
|
460 | 465 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
466 |
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the |
|
467 |
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis |
|
461 | 468 |
|
462 |
public Static4D getCastedRotAxis(int rotIndex)
|
|
469 |
public void getCastedRotAxis(float[] output, Static4D quat, int rotIndex)
|
|
463 | 470 |
{ |
464 |
return mCastedRotAxis4D[mLastTouchedFace][rotIndex]; |
|
471 |
Static4D axis = mCastedRotAxis4D[mLastTouchedFace][rotIndex]; |
|
472 |
Static4D result = QuatHelper.rotateVectorByQuat(axis, quat); |
|
473 |
|
|
474 |
output[0] =result.get0(); |
|
475 |
output[1] =result.get1(); |
|
476 |
|
|
477 |
float len = (float)Math.sqrt(output[0]*output[0] + output[1]*output[1]); |
|
478 |
output[0] /= len; |
|
479 |
output[1] /= len; |
|
465 | 480 |
} |
466 | 481 |
|
467 | 482 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
477 | 492 |
{ |
478 | 493 |
return mTouch; |
479 | 494 |
} |
480 |
|
|
481 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
482 |
|
|
483 |
public void setObjectRatio(float ratio) |
|
484 |
{ |
|
485 |
mObjectRatio = ratio; |
|
486 |
} |
|
487 | 495 |
} |
Also available in: Unified diff
Float vertices - scratchbook