Revision 826abd80
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
|---|---|---|
| 65 | 65 |
static final float SCREEN_RATIO = 0.5f; |
| 66 | 66 |
static final float OBJECT_SIZE = 3.0f; |
| 67 | 67 |
|
| 68 |
private final float[][] POSITIONS = new float[][] |
|
| 69 |
{
|
|
| 70 |
{-1, 1, 1},
|
|
| 71 |
{-1, 1, 0},
|
|
| 72 |
{-1, 1, -1},
|
|
| 73 |
{-1, 0, 1},
|
|
| 74 |
{-1, 0, 0},
|
|
| 75 |
{-1, 0, -1},
|
|
| 76 |
{-1, -1, 1},
|
|
| 77 |
{-1, -1, 0},
|
|
| 78 |
{-1, -1, -1},
|
|
| 79 |
{ 0, -1, 1},
|
|
| 80 |
{ 0, -1, 0},
|
|
| 81 |
{ 0, 1, 1},
|
|
| 82 |
{ 0, 1, 0},
|
|
| 83 |
{ 0, 1, -1},
|
|
| 84 |
{ 0, 0, 1},
|
|
| 85 |
{ 0, 0, -1},
|
|
| 86 |
{ 1, 1, 1},
|
|
| 87 |
{ 1, 1, 0},
|
|
| 88 |
{ 1, 1, -1},
|
|
| 89 |
{ 1, 0, 1},
|
|
| 90 |
{ 1, 0, 0},
|
|
| 91 |
{ 1, -1, 1},
|
|
| 92 |
{ 1, 0, -1},
|
|
| 93 |
{ 1, -1, -1},
|
|
| 94 |
{ 1, -1, 0},
|
|
| 95 |
{ 0, -1, -1},
|
|
| 96 |
}; |
|
| 97 |
|
|
| 98 | 68 |
private final BandagedCreatorView mView; |
| 99 | 69 |
private final DistortedScreen mScreen; |
| 100 | 70 |
private final Static3D mScale; |
| ... | ... | |
| 105 | 75 |
private long mStartTime; |
| 106 | 76 |
private float mScaleValue; |
| 107 | 77 |
private float mQuatX, mQuatY, mQuatZ, mQuatW; |
| 108 |
private int mX, mY, mZ; |
|
| 78 |
private int mX, mY, mZ, mNumCubits;
|
|
| 109 | 79 |
private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits; |
| 110 | 80 |
private int mIndex1, mIndex2; |
| 111 | 81 |
private int mSaveIcon; |
| ... | ... | |
| 155 | 125 |
return false; |
| 156 | 126 |
} |
| 157 | 127 |
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
|
|
| 130 |
private int computeNumCubits(int x, int y, int z) |
|
| 131 |
{
|
|
| 132 |
return ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2); |
|
| 133 |
} |
|
| 134 |
|
|
| 158 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 159 | 136 |
|
| 160 | 137 |
private void createCubits() |
| 161 | 138 |
{
|
| 162 | 139 |
android.util.Log.e("D", "creating cubits : "+mX+" "+mY+" "+mZ);
|
| 163 | 140 |
|
| 164 |
int len = POSITIONS.length;
|
|
| 165 |
mCubits = new BandagedCubit[len];
|
|
| 141 |
mCubits = new BandagedCubit[mNumCubits];
|
|
| 142 |
int c=0;
|
|
| 166 | 143 |
|
| 167 |
for(int c=0; c<len; c++) |
|
| 168 |
{
|
|
| 169 |
mCubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,false); |
|
| 170 |
} |
|
| 144 |
for(int x=0; x<mX; x++) |
|
| 145 |
for(int y=0; y<mY; y++) |
|
| 146 |
for(int z=0; z<mZ; z++) |
|
| 147 |
if( x==0 || x==mX-1 || y==0 || y==mY-1 || z==0 || z==mZ-1 ) |
|
| 148 |
{
|
|
| 149 |
float[] pos = new float[] { 0.5f*(1-mX)+x,0.5f*(1-mY)+y,0.5f*(1-mZ)+z };
|
|
| 150 |
mCubits[c] = new BandagedCubit(pos,mX,mY,mZ,mQuatT,mQuatA,mScale,false); |
|
| 151 |
c++; |
|
| 152 |
} |
|
| 171 | 153 |
|
| 172 | 154 |
mView.setCubits(mCubits); |
| 173 | 155 |
} |
| ... | ... | |
| 178 | 160 |
{
|
| 179 | 161 |
mView.resetCubits(); |
| 180 | 162 |
|
| 181 |
int len = POSITIONS.length; |
|
| 182 |
|
|
| 183 |
for(int c=0; c<len; c++) |
|
| 163 |
for(int c=0; c<mNumCubits; c++) |
|
| 184 | 164 |
{
|
| 185 | 165 |
if( !mCubits[c].isAttached() ) |
| 186 | 166 |
{
|
| ... | ... | |
| 265 | 245 |
mScaleValue = width<height ? Q*width : Q*height; |
| 266 | 246 |
|
| 267 | 247 |
mScreen.detachAll(); |
| 268 |
int len = POSITIONS.length; |
|
| 269 | 248 |
int touched = mView.getTouched(); |
| 270 | 249 |
|
| 271 |
for(int i=0; i<len; i++)
|
|
| 250 |
for(int i=0; i<mNumCubits; i++)
|
|
| 272 | 251 |
if( mCubits[i].isAttached() ) |
| 273 | 252 |
{
|
| 274 | 253 |
mCubits[i].scaleMove(mScaleValue); |
| ... | ... | |
| 386 | 365 |
|
| 387 | 366 |
public void saveObject() |
| 388 | 367 |
{
|
| 389 |
int len = POSITIONS.length; |
|
| 390 | 368 |
int numAttached=0; |
| 391 | 369 |
|
| 392 |
for(int i=0; i<len; i++)
|
|
| 370 |
for(int i=0; i<mNumCubits; i++)
|
|
| 393 | 371 |
if( mCubits[i].isAttached() ) numAttached++; |
| 394 | 372 |
|
| 395 | 373 |
float[][] pos = new float[numAttached][]; |
| 396 | 374 |
int attached=0; |
| 397 | 375 |
|
| 398 |
for(int i=0; i<len; i++)
|
|
| 376 |
for(int i=0; i<mNumCubits; i++)
|
|
| 399 | 377 |
if( mCubits[i].isAttached() ) |
| 400 | 378 |
{
|
| 401 | 379 |
pos[attached++] = mCubits[i].getPosition(); |
| ... | ... | |
| 545 | 523 |
mX = x; |
| 546 | 524 |
mY = y; |
| 547 | 525 |
mZ = z; |
| 526 |
mNumCubits = computeNumCubits(mX,mY,mZ); |
|
| 548 | 527 |
|
| 549 | 528 |
if( mCubitsCreated ) |
| 550 | 529 |
{
|
| 551 | 530 |
createCubits(); |
| 552 | 531 |
|
| 553 | 532 |
mScreen.detachAll(); |
| 554 |
int len = POSITIONS.length; |
|
| 555 | 533 |
mView.resetCubits(); |
| 556 | 534 |
|
| 557 |
for(int i=0; i<len; i++)
|
|
| 535 |
for(int i=0; i<mNumCubits; i++)
|
|
| 558 | 536 |
{
|
| 559 | 537 |
mCubits[i].scaleMove(mScaleValue); |
| 560 | 538 |
DistortedNode node = mCubits[i].getNode(); |
| src/main/java/org/distorted/bandaged/BandagedCubit.java | ||
|---|---|---|
| 59 | 59 |
private final DistortedEffects mEffects; |
| 60 | 60 |
private final Static3D mMove; |
| 61 | 61 |
private final boolean mRoundCorners; |
| 62 |
private final int mX, mY, mZ; |
|
| 62 | 63 |
|
| 63 | 64 |
private float mUnscaledX, mUnscaledY, mUnscaledZ; |
| 64 | 65 |
private float[] mPosition; |
| ... | ... | |
| 163 | 164 |
// PUBLIC API |
| 164 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 165 | 166 |
|
| 166 |
public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale, boolean roundCorners) |
|
| 167 |
public BandagedCubit(float[] position, int x, int y, int z, Static4D quat1, |
|
| 168 |
Static4D quat2, Static3D scale, boolean roundCorners) |
|
| 167 | 169 |
{
|
| 170 |
mX = x; |
|
| 171 |
mY = y; |
|
| 172 |
mZ = z; |
|
| 168 | 173 |
mRoundCorners = roundCorners; |
| 169 | 174 |
mPosition = position; |
| 170 | 175 |
mIsAttached = true; |
| ... | ... | |
| 174 | 179 |
mMove = new Static3D(0,0,0); |
| 175 | 180 |
|
| 176 | 181 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
| 177 |
MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners); |
|
| 182 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners);
|
|
| 178 | 183 |
|
| 179 | 184 |
DistortedTexture texture = new DistortedTexture(); |
| 180 | 185 |
if( mBitmap==null ) createBitmap(); |
| ... | ... | |
| 212 | 217 |
mPosition = tmpPosition; |
| 213 | 218 |
|
| 214 | 219 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
| 215 |
MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners); |
|
| 220 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners);
|
|
| 216 | 221 |
resetTextureMaps(mesh); |
| 217 | 222 |
mNode.setMesh(mesh); |
| 218 | 223 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
| ... | ... | |
| 234 | 239 |
computeMove(mPosition); |
| 235 | 240 |
|
| 236 | 241 |
FactoryBandagedCubit factory = FactoryBandagedCubit.getInstance(); |
| 237 |
MeshBase mesh = factory.createMesh(mPosition,false,mRoundCorners); |
|
| 242 |
MeshBase mesh = factory.createMesh(mPosition,mX,mY,mZ,false,mRoundCorners);
|
|
| 238 | 243 |
resetTextureMaps(mesh); |
| 239 | 244 |
mNode.setMesh(mesh); |
| 240 | 245 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
Also available in: Unified diff
Bandaged: progress.