Revision d2e06841
Added by Leszek Koltunski 10 months ago
src/main/java/org/distorted/objectlib/bandaged/BandagedObject.java | ||
---|---|---|
23 | 23 |
private final DistortedScreen mScreen; |
24 | 24 |
private final float[][] mFaceAxis; |
25 | 25 |
private BandagedCubit[] mCubits; |
26 |
private final float[][] mRotAxis; |
|
26 | 27 |
|
28 |
float[][] mCuts; |
|
27 | 29 |
final int[] mSize; |
28 | 30 |
final float mDist2D; |
29 | 31 |
|
... | ... | |
32 | 34 |
|
33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 36 |
|
35 |
BandagedObject(DistortedScreen screen, int numRotAxis)
|
|
37 |
BandagedObject(DistortedScreen screen) |
|
36 | 38 |
{ |
37 | 39 |
mScreen = screen; |
38 |
mSize = new int[numRotAxis]; |
|
40 |
mRotAxis = getRotAxis(); |
|
41 |
mSize = new int[mRotAxis.length]; |
|
39 | 42 |
mDist2D = getDist2D(); |
40 | 43 |
Static3D[] axis = getFaceAxis(); |
41 | 44 |
int numAxis = axis.length; |
... | ... | |
45 | 48 |
|
46 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 50 |
|
51 |
abstract float[][] getRotAxis(); |
|
48 | 52 |
abstract float getDist2D(); |
49 | 53 |
abstract int[] getColors(); |
50 | 54 |
abstract float[][][] getPositions(); |
... | ... | |
59 | 63 |
public abstract Static3D[] getFaceAxis(); |
60 | 64 |
public abstract float getScreenRatio(); |
61 | 65 |
|
66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
67 |
|
|
68 |
private float getRotRow(int ax, float d) |
|
69 |
{ |
|
70 |
float[] cuts = mCuts[ax]; |
|
71 |
int numCuts = cuts.length; |
|
72 |
for(int c=0; c<numCuts; c++) if( d<=cuts[c] ) return c; |
|
73 |
return numCuts; |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
float[][] getRotRows(float[] pos) |
|
79 |
{ |
|
80 |
int num = pos.length/3; |
|
81 |
int numAx = mRotAxis.length; |
|
82 |
float[][] ret = new float[num][numAx]; |
|
83 |
|
|
84 |
for(int p=0; p<num; p++) |
|
85 |
for(int a=0; a<numAx; a++) |
|
86 |
{ |
|
87 |
float[] ax = mRotAxis[a]; |
|
88 |
float x = pos[3*p]; |
|
89 |
float y = pos[3*p+1]; |
|
90 |
float z = pos[3*p+2]; |
|
91 |
float d = ax[0]*x + ax[1]*y + ax[2]*z; |
|
92 |
ret[p][a] = getRotRow(a,d); |
|
93 |
} |
|
94 |
|
|
95 |
return ret; |
|
96 |
} |
|
97 |
|
|
62 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 99 |
|
64 | 100 |
public void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
... | ... | |
69 | 105 |
|
70 | 106 |
for(float[][] po : pos) |
71 | 107 |
for(float[] p : po) |
72 |
mCubits[c++]=new BandagedCubit(this, p, quatT, quatA, scale, false);
|
|
108 |
mCubits[c++] = new BandagedCubit(this, p, quatT, quatA, scale, false);
|
|
73 | 109 |
} |
74 | 110 |
|
75 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
238 | 274 |
float y = point3D[1]*mMax; |
239 | 275 |
float z = point3D[2]*mMax; |
240 | 276 |
|
241 |
int minIndex = -1; |
|
242 |
float minDist = Float.MAX_VALUE; |
|
277 |
int numAxis = mRotAxis.length; |
|
278 |
float[] rotRow = new float[numAxis]; |
|
279 |
|
|
280 |
for(int a=0; a<numAxis; a++) |
|
281 |
{ |
|
282 |
float[] ax = mRotAxis[a]; |
|
283 |
float d = ax[0]*x + ax[1]*y + ax[2]*z; |
|
284 |
rotRow[a] = getRotRow(a,d); |
|
285 |
} |
|
286 |
|
|
287 |
int diff = Integer.MAX_VALUE; |
|
288 |
int currBest = -1; |
|
243 | 289 |
|
244 | 290 |
for(int c=0; c<mNumCubits; c++) |
245 | 291 |
if( mCubits[c].isAttached() ) |
246 | 292 |
{ |
247 |
float[] pos = mCubits[c].getPosition(); |
|
248 |
int len = pos.length/3; |
|
293 |
float[][] cubitRotRow = mCubits[c].getRotRow(); |
|
249 | 294 |
|
250 |
for(int p=0; p<len; p++)
|
|
295 |
for(float[] row : cubitRotRow)
|
|
251 | 296 |
{ |
252 |
float dx = pos[3*p ]-x; |
|
253 |
float dy = pos[3*p+1]-y; |
|
254 |
float dz = pos[3*p+2]-z; |
|
255 |
float dist = dx*dx + dy*dy + dz*dz; |
|
297 |
int currDiff = 0; |
|
298 |
|
|
299 |
for(int a=0; a<numAxis; a++) |
|
300 |
{ |
|
301 |
float d = rotRow[a]-row[a]; |
|
302 |
currDiff += d*d; |
|
303 |
} |
|
256 | 304 |
|
257 |
if( dist<minDist )
|
|
305 |
if( currDiff<diff )
|
|
258 | 306 |
{ |
259 |
minDist = dist;
|
|
260 |
minIndex = c;
|
|
307 |
diff = currDiff;
|
|
308 |
currBest = c;
|
|
261 | 309 |
} |
262 | 310 |
} |
263 | 311 |
} |
264 | 312 |
|
265 |
return minIndex;
|
|
313 |
return currBest;
|
|
266 | 314 |
} |
267 | 315 |
|
268 | 316 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
progress with TwistyBandagedMegaminx.