Revision e0b71e6e
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
|---|---|---|
| 35 | 35 |
|
| 36 | 36 |
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
| 37 | 37 |
{
|
| 38 |
private static final int DURATION = 1000; |
|
| 39 |
|
|
| 38 | 40 |
static final int COLOR_DEFAULT = 0xffffff55; |
| 39 | 41 |
static final int COLOR_MARKED = 0xffff0000; |
| 40 | 42 |
|
| ... | ... | |
| 76 | 78 |
private final Static3D mScale; |
| 77 | 79 |
private final BandagedCubit[] mCubits; |
| 78 | 80 |
private final Static4D mQuatT, mQuatA; |
| 79 |
private float mScaleValue; |
|
| 80 | 81 |
|
| 82 |
private boolean mInitialPhase; |
|
| 83 |
private long mStartTime; |
|
| 84 |
private float mScaleValue; |
|
| 81 | 85 |
private float mX, mY, mZ, mW; |
| 82 |
private boolean mResetQuats, mSetQuatT; |
|
| 86 |
private boolean mResetQuats, mSetQuatT, mResettingObject;
|
|
| 83 | 87 |
|
| 84 | 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 | 89 |
|
| ... | ... | |
| 92 | 96 |
|
| 93 | 97 |
mView = v; |
| 94 | 98 |
|
| 95 |
mResetQuats = false; |
|
| 96 |
mSetQuatT = false; |
|
| 99 |
mResetQuats = false; |
|
| 100 |
mSetQuatT = false; |
|
| 101 |
mResettingObject= false; |
|
| 97 | 102 |
|
| 98 | 103 |
mScreen = new DistortedScreen(); |
| 99 | 104 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
| ... | ... | |
| 101 | 106 |
mCubits= createCubits(); |
| 102 | 107 |
} |
| 103 | 108 |
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
private boolean isAdjacent(float[] pos1, float[] pos2) |
|
| 112 |
{
|
|
| 113 |
int len1 = pos1.length/3; |
|
| 114 |
int len2 = pos2.length/3; |
|
| 115 |
|
|
| 116 |
for(int i=0; i<len1; i++) |
|
| 117 |
for(int j=0; j<len2; j++) |
|
| 118 |
{
|
|
| 119 |
float d0 = pos1[3*i ] - pos2[3*j ]; |
|
| 120 |
float d1 = pos1[3*i+1] - pos2[3*j+1]; |
|
| 121 |
float d2 = pos1[3*i+2] - pos2[3*j+2]; |
|
| 122 |
|
|
| 123 |
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true; |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
return false; |
|
| 127 |
} |
|
| 128 |
|
|
| 104 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 105 | 130 |
|
| 106 | 131 |
private BandagedCubit[] createCubits() |
| ... | ... | |
| 116 | 141 |
return cubits; |
| 117 | 142 |
} |
| 118 | 143 |
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
|
|
| 146 |
private void resetObject() |
|
| 147 |
{
|
|
| 148 |
mView.resetCubits(); |
|
| 149 |
|
|
| 150 |
int len = POSITIONS.length; |
|
| 151 |
|
|
| 152 |
for(int c=0; c<len; c++) |
|
| 153 |
{
|
|
| 154 |
if( !mCubits[c].isAttached() ) |
|
| 155 |
{
|
|
| 156 |
mCubits[c].attach(); |
|
| 157 |
mScreen.attach(mCubits[c].getNode()); |
|
| 158 |
} |
|
| 159 |
if( mCubits[c].getPosition().length>3 ) |
|
| 160 |
{
|
|
| 161 |
mCubits[c].reset(mScaleValue); |
|
| 162 |
} |
|
| 163 |
} |
|
| 164 |
} |
|
| 165 |
|
|
| 119 | 166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 120 | 167 |
|
| 121 | 168 |
@Override |
| ... | ... | |
| 152 | 199 |
mQuatT.set(0f, 0f, 0f, 1f); |
| 153 | 200 |
mQuatA.set(tx, ty, tz, tw); |
| 154 | 201 |
} |
| 202 |
|
|
| 203 |
if( mResettingObject ) |
|
| 204 |
{
|
|
| 205 |
boolean done = continueResetting(time); |
|
| 206 |
if( done ) mResettingObject = false; |
|
| 207 |
} |
|
| 155 | 208 |
} |
| 156 | 209 |
|
| 157 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 208 | 261 |
return mScreen; |
| 209 | 262 |
} |
| 210 | 263 |
|
| 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 212 |
|
|
| 213 |
private boolean isAdjacent(float[] pos1, float[] pos2) |
|
| 214 |
{
|
|
| 215 |
int len1 = pos1.length/3; |
|
| 216 |
int len2 = pos2.length/3; |
|
| 217 |
|
|
| 218 |
for(int i=0; i<len1; i++) |
|
| 219 |
for(int j=0; j<len2; j++) |
|
| 220 |
{
|
|
| 221 |
float d0 = pos1[3*i ] - pos2[3*j ]; |
|
| 222 |
float d1 = pos1[3*i+1] - pos2[3*j+1]; |
|
| 223 |
float d2 = pos1[3*i+2] - pos2[3*j+2]; |
|
| 224 |
|
|
| 225 |
if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true; |
|
| 226 |
} |
|
| 227 |
|
|
| 228 |
return false; |
|
| 229 |
} |
|
| 230 |
|
|
| 231 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 232 | 265 |
|
| 233 | 266 |
public void tryConnectingCubits(int index1, int index2) |
| ... | ... | |
| 274 | 307 |
|
| 275 | 308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 276 | 309 |
|
| 277 |
public void reset()
|
|
| 310 |
public boolean isBusy()
|
|
| 278 | 311 |
{
|
| 312 |
return mResettingObject; |
|
| 313 |
} |
|
| 314 |
|
|
| 315 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 316 |
|
|
| 317 |
public void saveObject() |
|
| 318 |
{
|
|
| 319 |
|
|
| 320 |
} |
|
| 321 |
|
|
| 322 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 323 |
|
|
| 324 |
public void setupReset() |
|
| 325 |
{
|
|
| 326 |
mResettingObject = true; |
|
| 327 |
mInitialPhase = true; |
|
| 328 |
mStartTime = System.currentTimeMillis(); |
|
| 329 |
} |
|
| 330 |
|
|
| 331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 332 |
|
|
| 333 |
public boolean continueResetting(long time) |
|
| 334 |
{
|
|
| 335 |
long diff = time-mStartTime; |
|
| 336 |
float quotient = ((float)diff)/DURATION; |
|
| 337 |
|
|
| 338 |
if( mInitialPhase && quotient>0.5f ) |
|
| 339 |
{
|
|
| 340 |
mInitialPhase=false; |
|
| 341 |
resetObject(); |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
double angle = 2*Math.PI*quotient*quotient*(3-2*quotient); |
|
| 345 |
|
|
| 346 |
float sinA = (float)Math.sin(angle); |
|
| 347 |
float cosA = (float)Math.cos(angle); |
|
| 348 |
|
|
| 349 |
mQuatT.set(0, -sinA, 0, cosA); |
|
| 279 | 350 |
|
| 351 |
return quotient>1.0f; |
|
| 280 | 352 |
} |
| 281 | 353 |
} |
| src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java | ||
|---|---|---|
| 72 | 72 |
@Override |
| 73 | 73 |
public void onClick(View v) |
| 74 | 74 |
{
|
| 75 |
|
|
| 75 |
BandagedCreatorRenderer renderer = act.getRenderer(); |
|
| 76 |
if( !renderer.isBusy() ) renderer.saveObject(); |
|
| 76 | 77 |
} |
| 77 | 78 |
}); |
| 78 | 79 |
} |
| ... | ... | |
| 91 | 92 |
public void onClick(View v) |
| 92 | 93 |
{
|
| 93 | 94 |
BandagedCreatorRenderer renderer = act.getRenderer(); |
| 94 |
renderer.reset();
|
|
| 95 |
if( !renderer.isBusy() ) renderer.setupReset();
|
|
| 95 | 96 |
} |
| 96 | 97 |
}); |
| 97 | 98 |
} |
| src/main/java/org/distorted/bandaged/BandagedCreatorView.java | ||
|---|---|---|
| 100 | 100 |
return mRenderer; |
| 101 | 101 |
} |
| 102 | 102 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
public void resetCubits() |
|
| 106 |
{
|
|
| 107 |
if( mTouchedIndex1>=0 ) mTouchControl.markCubit(mTouchedIndex1, BandagedCreatorRenderer.COLOR_DEFAULT); |
|
| 108 |
if( mTouchedIndex2>=0 ) mTouchControl.markCubit(mTouchedIndex2, BandagedCreatorRenderer.COLOR_DEFAULT); |
|
| 109 |
|
|
| 110 |
mTouchedIndex1 = -1; |
|
| 111 |
mTouchedIndex2 = -1; |
|
| 112 |
} |
|
| 113 |
|
|
| 103 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 104 | 115 |
|
| 105 | 116 |
public void setScreenSize(int width, int height) |
| ... | ... | |
| 114 | 125 |
@Override |
| 115 | 126 |
public boolean onTouchEvent(MotionEvent event) |
| 116 | 127 |
{
|
| 128 |
if( mRenderer.isBusy() ) return true; |
|
| 129 |
|
|
| 117 | 130 |
int action = event.getAction(); |
| 118 | 131 |
int x = (int)event.getX(); |
| 119 | 132 |
int y = (int)event.getY(); |
| src/main/java/org/distorted/bandaged/BandagedCubit.java | ||
|---|---|---|
| 119 | 119 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 123 |
|
|
| 124 |
public void reset(float scale) |
|
| 125 |
{
|
|
| 126 |
float x0 = mPosition[0]; |
|
| 127 |
float x1 = mPosition[1]; |
|
| 128 |
float x2 = mPosition[2]; |
|
| 129 |
|
|
| 130 |
mPosition = new float[3]; |
|
| 131 |
mPosition[0] = x0; |
|
| 132 |
mPosition[1] = x1; |
|
| 133 |
mPosition[2] = x2; |
|
| 134 |
|
|
| 135 |
computeMove(mPosition); |
|
| 136 |
|
|
| 137 |
FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance(); |
|
| 138 |
MeshBase mesh = factory.createMesh(mPosition); |
|
| 139 |
mNode.setMesh(mesh); |
|
| 140 |
mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ); |
|
| 141 |
} |
|
| 142 |
|
|
| 122 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 123 | 144 |
|
| 124 | 145 |
public void scaleMove(float scale) |
| ... | ... | |
| 140 | 161 |
mIsAttached = false; |
| 141 | 162 |
} |
| 142 | 163 |
|
| 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 |
|
|
| 166 |
public void attach() |
|
| 167 |
{
|
|
| 168 |
mIsAttached = true; |
|
| 169 |
} |
|
| 170 |
|
|
| 143 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 144 | 172 |
|
| 145 | 173 |
public boolean isAttached() |
Also available in: Unified diff
Bandaged 3x3: implement object reset.