Revision eaf46415
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
32 | 32 |
|
33 |
import org.distorted.library.main.DistortedScreen; |
|
33 | 34 |
import org.distorted.library.type.Static2D; |
34 | 35 |
import org.distorted.library.type.Static4D; |
35 | 36 |
import org.distorted.library.main.QuatHelper; |
36 | 37 |
|
38 |
import org.distorted.objectlib.helpers.ObjectSurfaceView; |
|
39 |
import org.distorted.objectlib.helpers.TwistyActivity; |
|
40 |
import org.distorted.objectlib.main.ObjectPreRender; |
|
37 | 41 |
import org.distorted.objectlib.main.TwistyObject; |
38 | 42 |
import org.distorted.objectlib.main.Movement; |
39 | 43 |
|
... | ... | |
46 | 50 |
|
47 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 52 |
|
49 |
public class RubikSurfaceView extends GLSurfaceView |
|
53 |
public class RubikSurfaceView extends GLSurfaceView implements ObjectSurfaceView
|
|
50 | 54 |
{ |
51 | 55 |
public static final int NUM_SPEED_PROBES = 10; |
52 | 56 |
public static final int INVALID_POINTER_ID = -1; |
... | ... | |
64 | 68 |
private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0); |
65 | 69 |
|
66 | 70 |
private RubikRenderer mRenderer; |
67 |
private RubikPreRender mPreRender; |
|
68 |
private RubikObjectStateActioner mActioner; |
|
71 |
private ObjectPreRender mPreRender; |
|
69 | 72 |
private Movement mMovement; |
70 | 73 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
71 | 74 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
... | ... | |
116 | 119 |
|
117 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
118 | 121 |
|
119 |
RubikPreRender getPreRender()
|
|
122 |
ObjectPreRender getPreRender()
|
|
120 | 123 |
{ |
121 | 124 |
return mPreRender; |
122 | 125 |
} |
123 | 126 |
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
void setQuat() |
|
127 |
{ |
|
128 |
mQuat.set(mTemp); |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
Static4D getQuat() |
|
134 |
{ |
|
135 |
return mQuat; |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
void setMovement(Movement movement) |
|
141 |
{ |
|
142 |
mMovement = movement; |
|
143 |
} |
|
144 |
|
|
145 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
146 | 128 |
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the |
147 | 129 |
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis |
... | ... | |
237 | 219 |
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat); |
238 | 220 |
Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat); |
239 | 221 |
|
240 |
if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) ) |
|
222 |
if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera,object.getObjectRatio() ) )
|
|
241 | 223 |
{ |
242 | 224 |
mDragging = false; |
243 | 225 |
mContinuingRotation = false; |
... | ... | |
535 | 517 |
mFirstIndex =0; |
536 | 518 |
mLastIndex =0; |
537 | 519 |
|
538 |
mActioner = new RubikObjectStateActioner(); |
|
539 | 520 |
mRenderer = new RubikRenderer(this); |
540 |
mPreRender = new RubikPreRender(this,mActioner);
|
|
521 |
mPreRender = new ObjectPreRender(this,new RubikObjectStateActioner());
|
|
541 | 522 |
|
542 | 523 |
RubikActivity act = (RubikActivity)context; |
543 | 524 |
DisplayMetrics dm = new DisplayMetrics(); |
... | ... | |
573 | 554 |
} |
574 | 555 |
} |
575 | 556 |
|
557 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
558 |
|
|
559 |
public void setQuat() |
|
560 |
{ |
|
561 |
mQuat.set(mTemp); |
|
562 |
} |
|
563 |
|
|
564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
565 |
|
|
566 |
public Static4D getQuat() |
|
567 |
{ |
|
568 |
return mQuat; |
|
569 |
} |
|
570 |
|
|
571 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
572 |
|
|
573 |
public void setMovement(Movement movement) |
|
574 |
{ |
|
575 |
mMovement = movement; |
|
576 |
} |
|
577 |
|
|
578 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
579 |
|
|
580 |
public TwistyActivity getActivity() |
|
581 |
{ |
|
582 |
return (TwistyActivity)getContext(); |
|
583 |
} |
|
584 |
|
|
585 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
586 |
|
|
587 |
public DistortedScreen getScreen() |
|
588 |
{ |
|
589 |
return mRenderer.getScreen(); |
|
590 |
} |
|
591 |
|
|
576 | 592 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
577 | 593 |
|
578 | 594 |
public void prepareDown() |
Also available in: Unified diff
Move PreRender to objectlib.
This code is now shared betweeen the Rubik and Tutorial activities.