Revision 51f51f83
Added by Leszek Koltunski over 4 years ago
| src/main/java/org/distorted/control/RubikControl.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.control; |
| 21 | 21 |
|
| 22 |
import org.distorted.library.main.DistortedNode; |
|
| 22 | 23 |
import org.distorted.library.message.EffectListener; |
| 23 | 24 |
import org.distorted.main.RubikActivity; |
| 25 |
import org.distorted.main.RubikPreRender; |
|
| 26 |
import org.distorted.objects.TwistyObject; |
|
| 24 | 27 |
|
| 25 | 28 |
import java.lang.ref.WeakReference; |
| 26 | 29 |
|
| 27 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 31 |
|
| 29 |
public class RubikControl implements EffectListener, Runnable
|
|
| 32 |
public class RubikControl implements EffectListener |
|
| 30 | 33 |
{
|
| 31 | 34 |
WeakReference<RubikActivity> mRefAct; |
| 32 |
long mWholeID, mRotateID; |
|
| 33 | 35 |
boolean mWholeReturned, mRotateReturned; |
| 34 | 36 |
|
| 35 |
long mRetID; |
|
| 37 |
RubikControlWhole mWhole; |
|
| 38 |
RubikControlRotate mRotate; |
|
| 36 | 39 |
|
| 37 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 41 |
|
| 39 |
private void addWholeObjects()
|
|
| 42 |
private TwistyObject getObject()
|
|
| 40 | 43 |
{
|
| 41 |
mWholeID = 0;
|
|
| 44 |
RubikActivity act = mRefAct.get();
|
|
| 42 | 45 |
|
| 43 |
mRetID = mWholeID; |
|
| 46 |
if( act!=null ) |
|
| 47 |
{
|
|
| 48 |
RubikPreRender pre = act.getPreRender(); |
|
| 49 |
return pre!=null ? pre.getObject() : null; |
|
| 50 |
} |
|
| 44 | 51 |
|
| 45 |
Thread networkThrd = new Thread(this); |
|
| 46 |
networkThrd.start(); |
|
| 52 |
return null; |
|
| 47 | 53 |
} |
| 48 | 54 |
|
| 49 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | 56 |
|
| 51 |
private void addWholeEffects()
|
|
| 57 |
private void addWholeObjects()
|
|
| 52 | 58 |
{
|
| 59 |
TwistyObject object = getObject(); |
|
| 60 |
DistortedNode[] nodes = mWhole.getNodes(); |
|
| 53 | 61 |
|
| 62 |
if( object!=null && nodes!=null ) |
|
| 63 |
{
|
|
| 64 |
for (DistortedNode node : nodes) object.attach(node); |
|
| 65 |
} |
|
| 54 | 66 |
} |
| 55 | 67 |
|
| 56 | 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 57 | 69 |
|
| 58 | 70 |
private void removeWholeObjects() |
| 59 | 71 |
{
|
| 72 |
TwistyObject object = getObject(); |
|
| 73 |
DistortedNode[] nodes = mWhole.returnNodes(); |
|
| 60 | 74 |
|
| 75 |
if( object!=null && nodes!=null ) |
|
| 76 |
{
|
|
| 77 |
for (DistortedNode node : nodes) object.detach(node); |
|
| 78 |
} |
|
| 61 | 79 |
} |
| 62 | 80 |
|
| 63 | 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 64 | 82 |
|
| 65 | 83 |
private void addRotateObjects() |
| 66 | 84 |
{
|
| 67 |
mRotateID = 1; |
|
| 68 |
|
|
| 69 |
mRetID = mRotateID; |
|
| 70 |
|
|
| 71 |
Thread networkThrd = new Thread(this); |
|
| 72 |
networkThrd.start(); |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void addRotateEffects() |
|
| 78 |
{
|
|
| 85 |
TwistyObject object = getObject(); |
|
| 86 |
DistortedNode[] nodes = mRotate.getNodes(); |
|
| 79 | 87 |
|
| 88 |
if( object!=null && nodes!=null ) |
|
| 89 |
{
|
|
| 90 |
for (DistortedNode node : nodes) object.attach(node); |
|
| 91 |
} |
|
| 80 | 92 |
} |
| 81 | 93 |
|
| 82 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 83 | 95 |
|
| 84 | 96 |
private void removeRotateObjects() |
| 85 | 97 |
{
|
| 98 |
TwistyObject object = getObject(); |
|
| 99 |
DistortedNode[] nodes = mRotate.returnNodes(); |
|
| 86 | 100 |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
private void animateCubeWhole() |
|
| 92 |
{
|
|
| 93 |
addWholeObjects(); |
|
| 94 |
addWholeEffects(); |
|
| 101 |
if( object!=null && nodes!=null ) |
|
| 102 |
{
|
|
| 103 |
for (DistortedNode node : nodes) object.detach(node); |
|
| 104 |
} |
|
| 95 | 105 |
} |
| 96 | 106 |
|
| 97 | 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 102 | 112 |
|
| 103 | 113 |
mWholeReturned = true; |
| 104 | 114 |
|
| 105 |
if( !mRotateReturned ) animateCubeRotate(); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
|
|
| 110 |
private void animateCubeRotate() |
|
| 111 |
{
|
|
| 112 |
addRotateObjects(); |
|
| 113 |
addRotateEffects(); |
|
| 115 |
if( !mRotateReturned ) addRotateObjects(); |
|
| 114 | 116 |
} |
| 115 | 117 |
|
| 116 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 126 | 128 |
} |
| 127 | 129 |
|
| 128 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 129 |
// PUBLIC |
|
| 130 | 131 |
|
| 131 |
@Override |
|
| 132 |
public void run() |
|
| 132 |
RubikActivity getActivity() |
|
| 133 | 133 |
{
|
| 134 |
android.util.Log.e("D", "running...");
|
|
| 135 |
|
|
| 136 |
try |
|
| 137 |
{
|
|
| 138 |
Thread.sleep(4000); |
|
| 139 |
} |
|
| 140 |
catch(InterruptedException ex) |
|
| 141 |
{
|
|
| 142 |
// ignore |
|
| 143 |
} |
|
| 134 |
return mRefAct.get(); |
|
| 135 |
} |
|
| 144 | 136 |
|
| 145 |
android.util.Log.e("D", "end running...");
|
|
| 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 |
// PUBLIC |
|
| 146 | 139 |
|
| 147 |
effectFinished(mRetID); |
|
| 140 |
public RubikControl() |
|
| 141 |
{
|
|
| 142 |
mWhole = new RubikControlWhole(this); |
|
| 143 |
mRotate= new RubikControlRotate(this); |
|
| 148 | 144 |
} |
| 149 | 145 |
|
| 150 | 146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 151 | 147 |
|
| 152 | 148 |
public void effectFinished(long effectID) |
| 153 | 149 |
{
|
| 154 |
if( effectID==mWholeID ) finishWhole();
|
|
| 155 |
if( effectID==mRotateID ) finishRotate();
|
|
| 150 |
if( effectID==mWhole.getEffectID() ) finishWhole();
|
|
| 151 |
if( effectID==mRotate.getEffectID() ) finishRotate();
|
|
| 156 | 152 |
} |
| 157 | 153 |
|
| 158 | 154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 165 | 161 |
mWholeReturned = false; |
| 166 | 162 |
mRotateReturned= false; |
| 167 | 163 |
|
| 168 |
animateCubeWhole();
|
|
| 164 |
addWholeObjects();
|
|
| 169 | 165 |
} |
| 170 | 166 |
|
| 171 | 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 178 | 174 |
mWholeReturned = true; |
| 179 | 175 |
mRotateReturned= false; |
| 180 | 176 |
|
| 181 |
animateCubeRotate();
|
|
| 177 |
addRotateObjects();
|
|
| 182 | 178 |
} |
| 183 | 179 |
} |
| src/main/java/org/distorted/control/RubikControlRotate.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2021 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.control; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 23 |
import org.distorted.library.main.DistortedEffects; |
|
| 24 |
import org.distorted.library.main.DistortedNode; |
|
| 25 |
import org.distorted.library.main.DistortedTexture; |
|
| 26 |
import org.distorted.library.mesh.MeshQuad; |
|
| 27 |
import org.distorted.library.type.Dynamic; |
|
| 28 |
import org.distorted.library.type.Dynamic3D; |
|
| 29 |
import org.distorted.library.type.Static3D; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
class RubikControlRotate |
|
| 34 |
{
|
|
| 35 |
private static final int NUM_NODE = 1; |
|
| 36 |
|
|
| 37 |
private final RubikControl mControl; |
|
| 38 |
private DistortedEffects[] mEffects; |
|
| 39 |
private DistortedNode[] mNodes; |
|
| 40 |
private long mEffectID; |
|
| 41 |
|
|
| 42 |
private Dynamic3D mDynamic; |
|
| 43 |
private MatrixEffectScale mScale; |
|
| 44 |
|
|
| 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 46 |
|
|
| 47 |
private void createEffects() |
|
| 48 |
{
|
|
| 49 |
if( mEffects==null ) |
|
| 50 |
{
|
|
| 51 |
mEffects = new DistortedEffects[NUM_NODE]; |
|
| 52 |
mEffects[0]= new DistortedEffects(); |
|
| 53 |
|
|
| 54 |
Static3D scaleStart= new Static3D(1,1,1); |
|
| 55 |
Static3D scaleEnd = new Static3D(1000,1000,1000); |
|
| 56 |
|
|
| 57 |
mDynamic = new Dynamic3D(10000,0.5f); |
|
| 58 |
mDynamic.add(scaleStart); |
|
| 59 |
mDynamic.add(scaleEnd ); |
|
| 60 |
mDynamic.add(scaleStart); |
|
| 61 |
mDynamic.setMode(Dynamic.MODE_PATH); |
|
| 62 |
|
|
| 63 |
mScale = new MatrixEffectScale(mDynamic); |
|
| 64 |
mScale.notifyWhenFinished(mControl); |
|
| 65 |
mEffectID = mScale.getID(); |
|
| 66 |
mEffects[0].apply(mScale); |
|
| 67 |
} |
|
| 68 |
else |
|
| 69 |
{
|
|
| 70 |
mDynamic.resetToBeginning(); |
|
| 71 |
mScale.notifyWhenFinished(mControl); |
|
| 72 |
} |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void createNodes() |
|
| 78 |
{
|
|
| 79 |
if( mNodes==null ) |
|
| 80 |
{
|
|
| 81 |
mNodes = new DistortedNode[NUM_NODE]; |
|
| 82 |
MeshQuad mesh = new MeshQuad(); |
|
| 83 |
DistortedTexture texture = new DistortedTexture(); |
|
| 84 |
texture.setColorARGB(0xff00ff00); |
|
| 85 |
|
|
| 86 |
mNodes[0]= new DistortedNode(texture,mEffects[0],mesh); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 91 |
|
|
| 92 |
long getEffectID() |
|
| 93 |
{
|
|
| 94 |
return mEffectID; |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
DistortedNode[] getNodes() |
|
| 100 |
{
|
|
| 101 |
createEffects(); |
|
| 102 |
createNodes(); |
|
| 103 |
|
|
| 104 |
return mNodes; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
DistortedNode[] returnNodes() |
|
| 110 |
{
|
|
| 111 |
return mNodes; |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
RubikControlRotate(RubikControl control) |
|
| 117 |
{
|
|
| 118 |
mControl = control; |
|
| 119 |
} |
|
| 120 |
} |
|
| src/main/java/org/distorted/control/RubikControlWhole.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2021 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.control; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.effect.MatrixEffectScale; |
|
| 23 |
import org.distorted.library.main.DistortedEffects; |
|
| 24 |
import org.distorted.library.main.DistortedNode; |
|
| 25 |
import org.distorted.library.main.DistortedTexture; |
|
| 26 |
import org.distorted.library.mesh.MeshQuad; |
|
| 27 |
import org.distorted.library.type.Dynamic; |
|
| 28 |
import org.distorted.library.type.Dynamic3D; |
|
| 29 |
import org.distorted.library.type.Static3D; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
class RubikControlWhole |
|
| 34 |
{
|
|
| 35 |
private static final int NUM_NODE = 1; |
|
| 36 |
|
|
| 37 |
private final RubikControl mControl; |
|
| 38 |
private DistortedEffects[] mEffects; |
|
| 39 |
private DistortedNode[] mNodes; |
|
| 40 |
private long mEffectID; |
|
| 41 |
|
|
| 42 |
private Dynamic3D mDynamic; |
|
| 43 |
private MatrixEffectScale mScale; |
|
| 44 |
|
|
| 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 46 |
|
|
| 47 |
private void createEffects() |
|
| 48 |
{
|
|
| 49 |
if( mEffects==null ) |
|
| 50 |
{
|
|
| 51 |
mEffects = new DistortedEffects[NUM_NODE]; |
|
| 52 |
mEffects[0]= new DistortedEffects(); |
|
| 53 |
|
|
| 54 |
Static3D scaleStart= new Static3D(1,1,1); |
|
| 55 |
Static3D scaleEnd = new Static3D(1000,1000,1000); |
|
| 56 |
|
|
| 57 |
mDynamic = new Dynamic3D(10000,0.5f); |
|
| 58 |
mDynamic.add(scaleStart); |
|
| 59 |
mDynamic.add(scaleEnd ); |
|
| 60 |
mDynamic.add(scaleStart); |
|
| 61 |
mDynamic.setMode(Dynamic.MODE_PATH); |
|
| 62 |
|
|
| 63 |
mScale = new MatrixEffectScale(mDynamic); |
|
| 64 |
mScale.notifyWhenFinished(mControl); |
|
| 65 |
mEffectID = mScale.getID(); |
|
| 66 |
mEffects[0].apply(mScale); |
|
| 67 |
} |
|
| 68 |
else |
|
| 69 |
{
|
|
| 70 |
mDynamic.resetToBeginning(); |
|
| 71 |
mScale.notifyWhenFinished(mControl); |
|
| 72 |
} |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void createNodes() |
|
| 78 |
{
|
|
| 79 |
if( mNodes==null ) |
|
| 80 |
{
|
|
| 81 |
mNodes = new DistortedNode[NUM_NODE]; |
|
| 82 |
MeshQuad mesh = new MeshQuad(); |
|
| 83 |
DistortedTexture texture = new DistortedTexture(); |
|
| 84 |
texture.setColorARGB(0xffff0000); |
|
| 85 |
|
|
| 86 |
mNodes[0]= new DistortedNode(texture,mEffects[0],mesh); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
|
|
| 90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 91 |
|
|
| 92 |
long getEffectID() |
|
| 93 |
{
|
|
| 94 |
return mEffectID; |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
DistortedNode[] getNodes() |
|
| 100 |
{
|
|
| 101 |
createEffects(); |
|
| 102 |
createNodes(); |
|
| 103 |
|
|
| 104 |
return mNodes; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
DistortedNode[] returnNodes() |
|
| 110 |
{
|
|
| 111 |
return mNodes; |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
RubikControlWhole(RubikControl control) |
|
| 117 |
{
|
|
| 118 |
mControl = control; |
|
| 119 |
} |
|
| 120 |
} |
|
Also available in: Unified diff
Progress with RubikControl.