Revision b62eb334
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/examples/rubik/RubikCube.java | ||
|---|---|---|
| 32 | 32 |
import org.distorted.library.main.DistortedScreen; |
| 33 | 33 |
import org.distorted.library.main.DistortedTexture; |
| 34 | 34 |
import org.distorted.library.mesh.MeshCubes; |
| 35 |
import org.distorted.library.message.EffectListener; |
|
| 35 | 36 |
import org.distorted.library.type.Dynamic1D; |
| 36 | 37 |
import org.distorted.library.type.Static1D; |
| 37 | 38 |
import org.distorted.library.type.Static3D; |
| ... | ... | |
| 53 | 54 |
private Static3D[][][] mRotationAxis; |
| 54 | 55 |
private Dynamic1D[][][] mRotationAngle; |
| 55 | 56 |
private Static3D[][][] mCurrentPosition; |
| 56 |
private Static1D mRotationAngleStatic; |
|
| 57 |
private Static1D mRotationAngleStatic, mRotationAngleNearest;
|
|
| 57 | 58 |
private DistortedTexture mTexture; |
| 59 |
private DistortedEffects mEffectsListeningForNow; |
|
| 58 | 60 |
|
| 59 | 61 |
private int mRotAxis, mRotRow; |
| 60 | 62 |
private int mSize; |
| ... | ... | |
| 65 | 67 |
{
|
| 66 | 68 |
mSize = size; |
| 67 | 69 |
|
| 68 |
mRotationAngleStatic = new Static1D(0); |
|
| 70 |
mRotationAngleStatic = new Static1D(0); |
|
| 71 |
mRotationAngleNearest = new Static1D(0); |
|
| 72 |
|
|
| 69 | 73 |
mRotAxis= RubikSurfaceView.VECTX; |
| 70 | 74 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
| 71 | 75 |
|
| ... | ... | |
| 192 | 196 |
|
| 193 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 194 | 198 |
|
| 195 |
void continueRotation(float angle) |
|
| 199 |
void continueRotation(float angleInDegrees) |
|
| 200 |
{
|
|
| 201 |
mRotationAngleStatic.set1(angleInDegrees); |
|
| 202 |
} |
|
| 203 |
|
|
| 204 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 205 |
|
|
| 206 |
private int computeNearestAngle(float angle) |
|
| 196 | 207 |
{
|
| 197 |
mRotationAngleStatic.set1(angle); |
|
| 208 |
final int NEAREST = 90; |
|
| 209 |
|
|
| 210 |
int tmp = (int)((angle+NEAREST/2)/NEAREST); |
|
| 211 |
if( angle< -(NEAREST/2) ) tmp-=1; |
|
| 212 |
|
|
| 213 |
return NEAREST*tmp; |
|
| 198 | 214 |
} |
| 199 | 215 |
|
| 200 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 201 | 217 |
|
| 202 |
void finishRotationCalledOnNextRender() |
|
| 218 |
void finishRotationCalledOnNextRender(EffectListener listener)
|
|
| 203 | 219 |
{
|
| 204 |
float nearestAngle = (mRotationAngleStatic.get1()+45.0f)/90.0f; |
|
| 205 |
if( nearestAngle<0 ) nearestAngle-=1.0f; |
|
| 206 |
int nearestAngleInDegrees = 90*(4-((int)nearestAngle+4)%4); |
|
| 220 |
boolean first = true; |
|
| 221 |
int nearestAngleInDegrees = computeNearestAngle(mRotationAngleStatic.get1()); |
|
| 222 |
|
|
| 223 |
|
|
| 224 |
android.util.Log.e("cube", "finish: angle="+((int)mRotationAngleStatic.get1())+" ret: "+nearestAngleInDegrees);
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
mRotationAngleNearest.set1(nearestAngleInDegrees); |
|
| 228 |
|
|
| 229 |
for(int x=0; x<mSize; x++) |
|
| 230 |
for(int y=0; y<mSize; y++) |
|
| 231 |
for(int z=0; z<mSize; z++) |
|
| 232 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
| 233 |
{
|
|
| 234 |
if( belongsToRotation(x,y,z,mRotAxis,mRotRow) ) |
|
| 235 |
{
|
|
| 236 |
mRotationAngle[x][y][z].makeRunNowFor(2000); |
|
| 237 |
mRotationAngle[x][y][z].add(mRotationAngleNearest); |
|
| 238 |
|
|
| 239 |
if( first ) |
|
| 240 |
{
|
|
| 241 |
first = false; |
|
| 242 |
mEffectsListeningForNow = mEffects[x][y][z]; |
|
| 243 |
mEffectsListeningForNow.registerForMessages(listener); |
|
| 244 |
} |
|
| 245 |
} |
|
| 246 |
} |
|
| 247 |
} |
|
| 248 |
|
|
| 249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 250 |
|
|
| 251 |
void removeRotationCalledOnNextRender(EffectListener listener) |
|
| 252 |
{
|
|
| 253 |
mEffectsListeningForNow.deregisterForMessages(listener); |
|
| 254 |
|
|
| 255 |
int nearestAngleInDegrees = computeNearestAngle(mRotationAngleStatic.get1()); |
|
| 207 | 256 |
double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180; |
| 208 |
float sinA = (float)Math.sin(nearestAngleInRadians*0.5);
|
|
| 257 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
|
|
| 209 | 258 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
| 210 | 259 |
|
| 260 |
android.util.Log.e("cube", "remove: angle="+((int)mRotationAngleStatic.get1())+" ret: "+nearestAngleInDegrees);
|
|
| 261 |
|
|
| 211 | 262 |
mRotationAngleStatic.set1(0); |
| 263 |
mRotationAngleNearest.set1(0); |
|
| 212 | 264 |
|
| 213 | 265 |
float qx=0,qy=0,qz=0; |
| 214 | 266 |
|
| ... | ... | |
| 228 | 280 |
{
|
| 229 | 281 |
if( belongsToRotation(x,y,z,mRotAxis,mRotRow) ) |
| 230 | 282 |
{
|
| 283 |
mRotationAngle[x][y][z].makeRunNowFor(0); |
|
| 231 | 284 |
mRotationAngle[x][y][z].removeAll(); |
| 232 | 285 |
mQuatScramble[x][y][z].set(RubikSurfaceView.quatMultiply(quat,mQuatScramble[x][y][z])); |
| 233 | 286 |
modifyCurrentPosition(x,y,z,quat); |
Also available in: Unified diff
Many things.
1) make the Dynamic.setDuration() able to be called AFTER the Dynamic has already been run. (and rename it to 'makeRunNowFor()' )
2) remove the automatic removal of zero Effects from EffectQueues.
3) adjust several Apps to cope with 2)
4) add post-rotation to Rubik (still not finished)