Revision b89898c5
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
65 | 65 |
static final int COLOR_VIOLET = 0xff7700bb; |
66 | 66 |
static final int COLOR_BLACK = 0xff000000; |
67 | 67 |
|
68 |
static final int TEXTURE_HEIGHT = 256; |
|
69 |
|
|
68 | 70 |
static final float SQ2 = (float)Math.sqrt(2); |
69 | 71 |
static final float SQ3 = (float)Math.sqrt(3); |
70 | 72 |
static final float SQ6 = (float)Math.sqrt(6); |
... | ... | |
77 | 79 |
|
78 | 80 |
private static final Static3D CENTER = new Static3D(0,0,0); |
79 | 81 |
private static final int POST_ROTATION_MILLISEC = 500; |
80 |
static final int TEXTURE_HEIGHT = 256; |
|
81 | 82 |
|
82 | 83 |
final Static3D[] ROTATION_AXIS; |
83 | 84 |
final Static4D[] QUATS; |
... | ... | |
328 | 329 |
} |
329 | 330 |
} |
330 | 331 |
|
331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
332 |
|
|
333 |
private float computeAngle(float dx, float dy) |
|
334 |
{ |
|
335 |
float PI = (float)Math.PI; |
|
336 |
double angle = Math.atan2(dy,dx); |
|
337 |
float ret = (float)(3*PI/2-angle); |
|
338 |
|
|
339 |
if( ret>2*PI ) ret-= 2*PI; |
|
340 |
|
|
341 |
return ret; |
|
342 |
} |
|
343 |
|
|
344 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
345 |
|
|
346 |
private void drawCurrVertex(Canvas canvas, Paint paint, float left, float r, float stroke, float pX,float pY, float cX, float cY, float nX, float nY) |
|
347 |
{ |
|
348 |
pX = (0.5f+pX)*TEXTURE_HEIGHT; |
|
349 |
pY = (0.5f-pY)*TEXTURE_HEIGHT; |
|
350 |
cX = (0.5f+cX)*TEXTURE_HEIGHT; |
|
351 |
cY = (0.5f-cY)*TEXTURE_HEIGHT; |
|
352 |
nX = (0.5f+nX)*TEXTURE_HEIGHT; |
|
353 |
nY = (0.5f-nY)*TEXTURE_HEIGHT; |
|
354 |
|
|
355 |
canvas.drawLine(left+pX,pY,left+cX,cY,paint); |
|
356 |
|
|
357 |
float aX = pX-cX; |
|
358 |
float aY = pY-cY; |
|
359 |
float bX = cX-nX; |
|
360 |
float bY = cY-nY; |
|
361 |
|
|
362 |
float aLen = (float)Math.sqrt(aX*aX+aY*aY); |
|
363 |
float bLen = (float)Math.sqrt(bX*bX+bY*bY); |
|
364 |
|
|
365 |
aX /= aLen; |
|
366 |
aY /= aLen; |
|
367 |
bX /= bLen; |
|
368 |
bY /= bLen; |
|
369 |
|
|
370 |
float sX = (aX-bX)/2; |
|
371 |
float sY = (aY-bY)/2; |
|
372 |
float sLen = (float)Math.sqrt(sX*sX+sY*sY); |
|
373 |
sX /= sLen; |
|
374 |
sY /= sLen; |
|
375 |
|
|
376 |
float startAngle = computeAngle(bX,-bY); |
|
377 |
float endAngle = computeAngle(aX,-aY); |
|
378 |
float sweepAngle = endAngle-startAngle; |
|
379 |
if( sweepAngle<0 ) sweepAngle += 2*Math.PI; |
|
380 |
|
|
381 |
float R = r*TEXTURE_HEIGHT+stroke/2; |
|
382 |
|
|
383 |
float A = (float)(R/(Math.cos(sweepAngle/2))); |
|
384 |
|
|
385 |
float rX = cX + A*sX; |
|
386 |
float rY = cY + A*sY; |
|
387 |
|
|
388 |
startAngle *= 180/(Math.PI); |
|
389 |
sweepAngle *= 180/(Math.PI); |
|
390 |
|
|
391 |
canvas.drawArc( left+rX-R, rY-R, left+rX+R, rY+R, startAngle, sweepAngle, false, paint); |
|
392 |
} |
|
393 |
|
|
394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
395 |
|
|
396 |
void drawRoundedPolygon(Canvas canvas, Paint paint, int left, float[] vertices, float stroke, int color, float r) |
|
397 |
{ |
|
398 |
stroke *= TEXTURE_HEIGHT; |
|
399 |
|
|
400 |
paint.setAntiAlias(true); |
|
401 |
paint.setStrokeWidth(stroke); |
|
402 |
paint.setColor(color); |
|
403 |
paint.setStyle(Paint.Style.FILL); |
|
404 |
|
|
405 |
canvas.drawRect(left,0,left+TEXTURE_HEIGHT,TEXTURE_HEIGHT,paint); |
|
406 |
|
|
407 |
paint.setColor(COLOR_BLACK); |
|
408 |
paint.setStyle(Paint.Style.STROKE); |
|
409 |
|
|
410 |
int length = vertices.length; |
|
411 |
int numVertices = length/2; |
|
412 |
|
|
413 |
float prevX = vertices[length-2]; |
|
414 |
float prevY = vertices[length-1]; |
|
415 |
float currX = vertices[0]; |
|
416 |
float currY = vertices[1]; |
|
417 |
float nextX = vertices[2]; |
|
418 |
float nextY = vertices[3]; |
|
419 |
|
|
420 |
for(int vert=0; vert<numVertices; vert++) |
|
421 |
{ |
|
422 |
drawCurrVertex(canvas, paint, left, r, stroke, prevX,prevY,currX,currY,nextX,nextY); |
|
423 |
|
|
424 |
prevX = currX; |
|
425 |
prevY = currY; |
|
426 |
currX = nextX; |
|
427 |
currY = nextY; |
|
428 |
|
|
429 |
if( 2*(vert+2)+1 < length ) |
|
430 |
{ |
|
431 |
nextX = vertices[2*(vert+2) ]; |
|
432 |
nextY = vertices[2*(vert+2)+1]; |
|
433 |
} |
|
434 |
else |
|
435 |
{ |
|
436 |
nextX = vertices[0]; |
|
437 |
nextY = vertices[1]; |
|
438 |
} |
|
439 |
} |
|
440 |
} |
|
441 |
|
|
442 | 332 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
443 | 333 |
|
444 | 334 |
int getCubitFaceColorIndex(int cubit, int face) |
Also available in: Unified diff
Progress with Skewb familty; separate StickerFactory class.