Revision b1f2ccf5
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/helpers/FactoryCubit.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.helpers; |
21 | 21 |
|
22 |
import org.distorted.library.effect.MatrixEffectMove; |
|
23 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
|
24 |
import org.distorted.library.effect.MatrixEffectScale; |
|
22 | 25 |
import org.distorted.library.effect.VertexEffect; |
23 | 26 |
import org.distorted.library.effect.VertexEffectDeform; |
24 | 27 |
import org.distorted.library.effect.VertexEffectMove; |
... | ... | |
31 | 34 |
import org.distorted.library.type.Static3D; |
32 | 35 |
import org.distorted.library.type.Static4D; |
33 | 36 |
|
37 |
import java.util.ArrayList; |
|
38 |
|
|
34 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 40 |
|
36 | 41 |
public class FactoryCubit |
... | ... | |
63 | 68 |
public static final float DIHEDRAL2= (float)((180/Math.PI)*Math.asin((2*SIN54*SIN54-1)/COS54) - 90); |
64 | 69 |
public static final float MINX_SC = 0.5f; |
65 | 70 |
|
71 |
|
|
72 |
private static final double[] mBuffer = new double[3]; |
|
73 |
private static final double[] mQuat1 = new double[4]; |
|
74 |
private static final double[] mQuat2 = new double[4]; |
|
75 |
private static final double[] mQuat3 = new double[4]; |
|
76 |
private static final double[] mQuat4 = new double[4]; |
|
77 |
|
|
78 |
private static class StickerCoords |
|
79 |
{ |
|
80 |
double[] vertices; |
|
81 |
} |
|
82 |
|
|
83 |
private static class FaceTransform |
|
84 |
{ |
|
85 |
int sticker; |
|
86 |
double vx,vy,vz; |
|
87 |
double scale; |
|
88 |
double qx,qy,qz,qw; |
|
89 |
boolean flip; |
|
90 |
} |
|
91 |
|
|
92 |
private static final ArrayList<FaceTransform> mFaceTransform = new ArrayList<>(); |
|
93 |
private static final ArrayList<StickerCoords> mStickerCoords = new ArrayList<>(); |
|
94 |
|
|
66 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | 96 |
|
68 | 97 |
private FactoryCubit() |
... | ... | |
208 | 237 |
} |
209 | 238 |
} |
210 | 239 |
|
211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 |
|
|
213 |
MeshBase createFacesCube(int sizeIndex) |
|
214 |
{ |
|
215 |
MeshBase[] meshes = new MeshPolygon[6]; |
|
216 |
|
|
217 |
float E = 0.5f; |
|
218 |
int extraI, extraV, num; |
|
219 |
|
|
220 |
switch(sizeIndex) |
|
221 |
{ |
|
222 |
case 0 : num = 6; extraI = 2; extraV = 2; break; |
|
223 |
case 1 : num = 5; extraI = 2; extraV = 2; break; |
|
224 |
case 2 : num = 5; extraI = 1; extraV = 2; break; |
|
225 |
default: num = 4; extraI = 1; extraV = 1; break; |
|
226 |
} |
|
227 |
|
|
228 |
float[] vertices = { -E,-E, +E,-E, +E,+E, -E,+E }; |
|
229 |
float[] bands = computeBands(0.048f,35,E,0.7f,num); |
|
230 |
|
|
231 |
meshes[0] = new MeshPolygon(vertices,bands,extraI,extraV); |
|
232 |
meshes[0].setEffectAssociation(0,1,0); |
|
233 |
meshes[1] = meshes[0].copy(true); |
|
234 |
meshes[1].setEffectAssociation(0,2,0); |
|
235 |
meshes[2] = meshes[0].copy(true); |
|
236 |
meshes[2].setEffectAssociation(0,4,0); |
|
237 |
meshes[3] = meshes[0].copy(true); |
|
238 |
meshes[3].setEffectAssociation(0,8,0); |
|
239 |
meshes[4] = meshes[0].copy(true); |
|
240 |
meshes[4].setEffectAssociation(0,16,0); |
|
241 |
meshes[5] = meshes[0].copy(true); |
|
242 |
meshes[5].setEffectAssociation(0,32,0); |
|
243 |
|
|
244 |
return new MeshJoined(meshes); |
|
245 |
} |
|
246 |
|
|
247 | 240 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
248 | 241 |
|
249 | 242 |
MeshBase createFacesSkewbCorner() |
... | ... | |
902 | 895 |
// EFFECTS |
903 | 896 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
904 | 897 |
|
905 |
VertexEffect[] createVertexEffectsCube() |
|
906 |
{ |
|
907 |
Static3D axisY = new Static3D(0,1,0); |
|
908 |
Static3D axisX = new Static3D(1,0,0); |
|
909 |
Static3D center = new Static3D(0,0,0); |
|
910 |
Static1D angle90 = new Static1D(90); |
|
911 |
Static1D angle180= new Static1D(180); |
|
912 |
Static1D angle270= new Static1D(270); |
|
913 |
|
|
914 |
VertexEffect[] effect = new VertexEffect[6]; |
|
915 |
|
|
916 |
effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f)); |
|
917 |
effect[1] = new VertexEffectRotate( angle180, axisX, center ); |
|
918 |
effect[2] = new VertexEffectRotate( angle90 , axisX, center ); |
|
919 |
effect[3] = new VertexEffectRotate( angle270, axisX, center ); |
|
920 |
effect[4] = new VertexEffectRotate( angle270, axisY, center ); |
|
921 |
effect[5] = new VertexEffectRotate( angle90 , axisY, center ); |
|
922 |
|
|
923 |
effect[0].setMeshAssociation(63,-1); // all 6 sides |
|
924 |
effect[1].setMeshAssociation(32,-1); // back |
|
925 |
effect[2].setMeshAssociation( 8,-1); // bottom |
|
926 |
effect[3].setMeshAssociation( 4,-1); // top |
|
927 |
effect[4].setMeshAssociation( 2,-1); // left |
|
928 |
effect[5].setMeshAssociation( 1,-1); // right |
|
929 |
|
|
930 |
return effect; |
|
931 |
} |
|
932 |
|
|
933 | 898 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
934 | 899 |
|
935 | 900 |
VertexEffect[] createVertexEffectsSkewbCorner() |
... | ... | |
1691 | 1656 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1692 | 1657 |
// OBJECTS |
1693 | 1658 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1694 |
// CUBE |
|
1695 |
|
|
1696 |
public MeshBase createCubeMesh(int index) |
|
1697 |
{ |
|
1698 |
MeshBase mesh = createFacesCube(index); |
|
1699 |
VertexEffect[] effects = createVertexEffectsCube(); |
|
1700 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1701 |
|
|
1702 |
Static3D roundingCenter = new Static3D(0,0,0); |
|
1703 |
Static3D[] vertices = new Static3D[8]; |
|
1704 |
vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f); |
|
1705 |
vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f); |
|
1706 |
vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f); |
|
1707 |
vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f); |
|
1708 |
vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f); |
|
1709 |
vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f); |
|
1710 |
vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f); |
|
1711 |
vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f); |
|
1712 |
|
|
1713 |
roundCorners(mesh,roundingCenter,vertices,0.06f,0.12f); |
|
1714 |
|
|
1715 |
mesh.mergeEffComponents(); |
|
1716 | 1659 |
|
1717 |
return mesh; |
|
1718 |
} |
|
1719 | 1660 |
|
1720 | 1661 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1721 | 1662 |
// SKEWB |
... | ... | |
2204 | 2145 |
|
2205 | 2146 |
return mesh; |
2206 | 2147 |
} |
2148 |
|
|
2149 |
|
|
2150 |
|
|
2151 |
|
|
2152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2153 |
|
|
2154 |
private boolean areColinear(double[][] vertices, int index1, int index2, int index3) |
|
2155 |
{ |
|
2156 |
double x1 = vertices[index1][0]; |
|
2157 |
double y1 = vertices[index1][1]; |
|
2158 |
double z1 = vertices[index1][2]; |
|
2159 |
double x2 = vertices[index2][0]; |
|
2160 |
double y2 = vertices[index2][1]; |
|
2161 |
double z2 = vertices[index2][2]; |
|
2162 |
double x3 = vertices[index3][0]; |
|
2163 |
double y3 = vertices[index3][1]; |
|
2164 |
double z3 = vertices[index3][2]; |
|
2165 |
|
|
2166 |
double v1x = x2-x1; |
|
2167 |
double v1y = y2-y1; |
|
2168 |
double v1z = z2-z1; |
|
2169 |
double v2x = x3-x1; |
|
2170 |
double v2y = y3-y1; |
|
2171 |
double v2z = z3-z1; |
|
2172 |
|
|
2173 |
double A = Math.sqrt( (v1x*v1x+v1y*v1y+v1z*v1z) / (v2x*v2x+v2y*v2y+v2z*v2z) ); |
|
2174 |
|
|
2175 |
return (v1x==A*v2x && v1y==A*v2y && v1z==A*v2z); |
|
2176 |
} |
|
2177 |
|
|
2178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2179 |
|
|
2180 |
private void computeNormalVector(double[][] vertices, int index1, int index2, int index3) |
|
2181 |
{ |
|
2182 |
double x1 = vertices[index1][0]; |
|
2183 |
double y1 = vertices[index1][1]; |
|
2184 |
double z1 = vertices[index1][2]; |
|
2185 |
double x2 = vertices[index2][0]; |
|
2186 |
double y2 = vertices[index2][1]; |
|
2187 |
double z2 = vertices[index2][2]; |
|
2188 |
double x3 = vertices[index3][0]; |
|
2189 |
double y3 = vertices[index3][1]; |
|
2190 |
double z3 = vertices[index3][2]; |
|
2191 |
|
|
2192 |
double v1x = x2-x1; |
|
2193 |
double v1y = y2-y1; |
|
2194 |
double v1z = z2-z1; |
|
2195 |
double v2x = x3-x1; |
|
2196 |
double v2y = y3-y1; |
|
2197 |
double v2z = z3-z1; |
|
2198 |
|
|
2199 |
mBuffer[0] = v1y*v2z - v2y*v1z; |
|
2200 |
mBuffer[1] = v1z*v2x - v2z*v1x; |
|
2201 |
mBuffer[2] = v1x*v2y - v2x*v1y; |
|
2202 |
|
|
2203 |
double len = mBuffer[0]*mBuffer[0] + mBuffer[1]*mBuffer[1] + mBuffer[2]*mBuffer[2]; |
|
2204 |
len = Math.sqrt(len); |
|
2205 |
mBuffer[0] /= len; |
|
2206 |
mBuffer[1] /= len; |
|
2207 |
mBuffer[2] /= len; |
|
2208 |
} |
|
2209 |
|
|
2210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2211 |
// return quat1*quat2 |
|
2212 |
|
|
2213 |
private static void quatMultiply( double[] quat1, double[] quat2, double[] result ) |
|
2214 |
{ |
|
2215 |
double qx = quat1[0]; |
|
2216 |
double qy = quat1[1]; |
|
2217 |
double qz = quat1[2]; |
|
2218 |
double qw = quat1[3]; |
|
2219 |
|
|
2220 |
double rx = quat2[0]; |
|
2221 |
double ry = quat2[1]; |
|
2222 |
double rz = quat2[2]; |
|
2223 |
double rw = quat2[3]; |
|
2224 |
|
|
2225 |
result[0] = rw*qx - rz*qy + ry*qz + rx*qw; |
|
2226 |
result[1] = rw*qy + rz*qx + ry*qw - rx*qz; |
|
2227 |
result[2] = rw*qz + rz*qw - ry*qx + rx*qy; |
|
2228 |
result[3] = rw*qw - rz*qz - ry*qy - rx*qx; |
|
2229 |
} |
|
2230 |
|
|
2231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2232 |
|
|
2233 |
private void fitInSquare(FaceTransform info, double[][] vert3D) |
|
2234 |
{ |
|
2235 |
double minX = Double.MAX_VALUE; |
|
2236 |
double maxX =-Double.MAX_VALUE; |
|
2237 |
double minY = Double.MAX_VALUE; |
|
2238 |
double maxY =-Double.MAX_VALUE; |
|
2239 |
|
|
2240 |
for (double[] vert : vert3D) |
|
2241 |
{ |
|
2242 |
double x = vert[0]; |
|
2243 |
double y = vert[1]; |
|
2244 |
|
|
2245 |
if (x > maxX) maxX = x; |
|
2246 |
if (x < minX) minX = x; |
|
2247 |
if (y > maxY) maxY = y; |
|
2248 |
if (y < minY) minY = y; |
|
2249 |
} |
|
2250 |
|
|
2251 |
minX = minX<0 ? -minX:minX; |
|
2252 |
maxX = maxX<0 ? -maxX:maxX; |
|
2253 |
minY = minY<0 ? -minY:minY; |
|
2254 |
maxY = maxY<0 ? -maxY:maxY; |
|
2255 |
|
|
2256 |
double max1 = Math.max(minX,minY); |
|
2257 |
double max2 = Math.max(maxX,maxY); |
|
2258 |
double max3 = Math.max(max1,max2); |
|
2259 |
|
|
2260 |
info.scale = max3/0.5; |
|
2261 |
|
|
2262 |
int len = vert3D.length; |
|
2263 |
StickerCoords sInfo = new StickerCoords(); |
|
2264 |
sInfo.vertices = new double[2*len]; |
|
2265 |
|
|
2266 |
for( int vertex=0; vertex<len; vertex++ ) |
|
2267 |
{ |
|
2268 |
sInfo.vertices[2*vertex ] = vert3D[vertex][0] / info.scale; |
|
2269 |
sInfo.vertices[2*vertex+1] = vert3D[vertex][1] / info.scale; |
|
2270 |
} |
|
2271 |
|
|
2272 |
mStickerCoords.add(sInfo); |
|
2273 |
|
|
2274 |
info.sticker = mStickerCoords.size() -1; |
|
2275 |
info.flip = false; |
|
2276 |
} |
|
2277 |
|
|
2278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2279 |
|
|
2280 |
private void constructNew(FaceTransform info, final double[][] vert3D) |
|
2281 |
{ |
|
2282 |
// compute center of gravity |
|
2283 |
info.vx = 0.0f; |
|
2284 |
info.vy = 0.0f; |
|
2285 |
info.vz = 0.0f; |
|
2286 |
int len = vert3D.length; |
|
2287 |
|
|
2288 |
for (double[] vert : vert3D) |
|
2289 |
{ |
|
2290 |
info.vx += vert[0]; |
|
2291 |
info.vy += vert[1]; |
|
2292 |
info.vz += vert[2]; |
|
2293 |
} |
|
2294 |
|
|
2295 |
info.vx /= len; |
|
2296 |
info.vy /= len; |
|
2297 |
info.vz /= len; |
|
2298 |
|
|
2299 |
// move all vertices so that their center of gravity is at (0,0,0) |
|
2300 |
for (int i=0; i<len; i++) |
|
2301 |
{ |
|
2302 |
vert3D[i][0] -= info.vx; |
|
2303 |
vert3D[i][1] -= info.vy; |
|
2304 |
vert3D[i][2] -= info.vz; |
|
2305 |
} |
|
2306 |
|
|
2307 |
// find 3 non-colinear vertices |
|
2308 |
int foundIndex = -1; |
|
2309 |
|
|
2310 |
for(int vertex=2; vertex<len; vertex++) |
|
2311 |
{ |
|
2312 |
if( !areColinear(vert3D,0,1,vertex) ) |
|
2313 |
{ |
|
2314 |
foundIndex = vertex; |
|
2315 |
break; |
|
2316 |
} |
|
2317 |
} |
|
2318 |
|
|
2319 |
// compute the normal vector |
|
2320 |
if( foundIndex==-1 ) |
|
2321 |
{ |
|
2322 |
throw new RuntimeException("all vertices colinear"); |
|
2323 |
} |
|
2324 |
|
|
2325 |
computeNormalVector(vert3D,0,1,foundIndex); |
|
2326 |
|
|
2327 |
// rotate so that the normal vector becomes (0,0,1) |
|
2328 |
double axisX, axisY, axisZ; |
|
2329 |
|
|
2330 |
if( mBuffer[0]!=0.0f || mBuffer[1]!=0.0f ) |
|
2331 |
{ |
|
2332 |
axisX = -mBuffer[1]; |
|
2333 |
axisY = mBuffer[0]; |
|
2334 |
axisZ = 0.0f; |
|
2335 |
|
|
2336 |
double axiLen = axisX*axisX + axisY*axisY; |
|
2337 |
axiLen = Math.sqrt(axiLen); |
|
2338 |
axisX /= axiLen; |
|
2339 |
axisY /= axiLen; |
|
2340 |
axisZ /= axiLen; |
|
2341 |
} |
|
2342 |
else |
|
2343 |
{ |
|
2344 |
axisX = 0.0f; |
|
2345 |
axisY = 1.0f; |
|
2346 |
axisZ = 0.0f; |
|
2347 |
} |
|
2348 |
|
|
2349 |
double cosTheta = mBuffer[2]; |
|
2350 |
double sinTheta = Math.sqrt(1-cosTheta*cosTheta); |
|
2351 |
double sinHalfTheta = computeSinHalf(cosTheta); |
|
2352 |
double cosHalfTheta = computeCosHalf(sinTheta,cosTheta); |
|
2353 |
|
|
2354 |
mQuat1[0] = axisX*sinHalfTheta; |
|
2355 |
mQuat1[1] = axisY*sinHalfTheta; |
|
2356 |
mQuat1[2] = axisZ*sinHalfTheta; |
|
2357 |
mQuat1[3] = cosHalfTheta; |
|
2358 |
mQuat2[0] =-axisX*sinHalfTheta; |
|
2359 |
mQuat2[1] =-axisY*sinHalfTheta; |
|
2360 |
mQuat2[2] =-axisZ*sinHalfTheta; |
|
2361 |
mQuat2[3] = cosHalfTheta; |
|
2362 |
|
|
2363 |
for (double[] vert : vert3D) |
|
2364 |
{ |
|
2365 |
quatMultiply(mQuat1, vert , mQuat3); |
|
2366 |
quatMultiply(mQuat3, mQuat2, vert ); |
|
2367 |
} |
|
2368 |
|
|
2369 |
// fit the whole thing in a square and remember the scale & 2D vertices |
|
2370 |
fitInSquare(info, vert3D); |
|
2371 |
|
|
2372 |
// remember the rotation |
|
2373 |
info.qx =-mQuat1[0]; |
|
2374 |
info.qy =-mQuat1[1]; |
|
2375 |
info.qz =-mQuat1[2]; |
|
2376 |
info.qw = mQuat1[3]; |
|
2377 |
} |
|
2378 |
|
|
2379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2380 |
|
|
2381 |
private double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2) |
|
2382 |
{ |
|
2383 |
double ret= (oldX*newX+oldY*newY) / (len1*len2); |
|
2384 |
if( ret<-1.0 ) return -1.0; |
|
2385 |
if( ret> 1.0 ) return 1.0; |
|
2386 |
|
|
2387 |
return ret; |
|
2388 |
} |
|
2389 |
|
|
2390 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2391 |
// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise! |
|
2392 |
|
|
2393 |
private double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2) |
|
2394 |
{ |
|
2395 |
double ret= (newX*oldY-oldX*newY) / (len1*len2); |
|
2396 |
if( ret<-1.0 ) return -1.0; |
|
2397 |
if( ret> 1.0 ) return 1.0; |
|
2398 |
|
|
2399 |
return ret; |
|
2400 |
} |
|
2401 |
|
|
2402 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2403 |
|
|
2404 |
private void rotateAllVertices(double[] result, int len, double[] vertices, double sin, double cos) |
|
2405 |
{ |
|
2406 |
for(int i=0; i<len; i++) |
|
2407 |
{ |
|
2408 |
result[2*i ] = vertices[2*i ]*cos - vertices[2*i+1]*sin; |
|
2409 |
result[2*i+1] = vertices[2*i ]*sin + vertices[2*i+1]*cos; |
|
2410 |
} |
|
2411 |
} |
|
2412 |
|
|
2413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2414 |
|
|
2415 |
private double computeScale(double[] v1, double[] v2) |
|
2416 |
{ |
|
2417 |
double lenSq1 = v1[0]*v1[0] + v1[1]*v1[1]; |
|
2418 |
double lenSq2 = v2[0]*v2[0] + v2[1]*v2[1]; |
|
2419 |
|
|
2420 |
return Math.sqrt(lenSq2/lenSq1); |
|
2421 |
} |
|
2422 |
|
|
2423 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2424 |
|
|
2425 |
private double computeSinHalf(double cos) |
|
2426 |
{ |
|
2427 |
return Math.sqrt((1-cos)/2); |
|
2428 |
} |
|
2429 |
|
|
2430 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2431 |
|
|
2432 |
private double computeCosHalf(double sin, double cos) |
|
2433 |
{ |
|
2434 |
double cosHalf = Math.sqrt((1+cos)/2); |
|
2435 |
return sin<0 ? -cosHalf : cosHalf; |
|
2436 |
} |
|
2437 |
|
|
2438 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2439 |
|
|
2440 |
private int computeRotatedIndex(int oldVertex, int len, int rotatedVertex, boolean inverted) |
|
2441 |
{ |
|
2442 |
int v = (rotatedVertex + (inverted? -oldVertex : oldVertex)); |
|
2443 |
if( v>=len ) v-=len; |
|
2444 |
if( v< 0 ) v+=len; |
|
2445 |
|
|
2446 |
return v; |
|
2447 |
} |
|
2448 |
|
|
2449 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2450 |
|
|
2451 |
private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len, int vertex, boolean inverted) |
|
2452 |
{ |
|
2453 |
double EPSILON = 0.001; |
|
2454 |
double scale = computeScale(newVert,oldVert); |
|
2455 |
|
|
2456 |
for(int i=1; i<len; i++) |
|
2457 |
{ |
|
2458 |
int index = computeRotatedIndex(i,len,vertex,inverted); |
|
2459 |
|
|
2460 |
double horz = oldVert[2*i ] - scale*newVert[2*index ]; |
|
2461 |
double vert = oldVert[2*i+1] - scale*newVert[2*index+1]; |
|
2462 |
|
|
2463 |
if( horz>EPSILON || horz<-EPSILON || vert>EPSILON || vert<-EPSILON ) return false; |
|
2464 |
} |
|
2465 |
|
|
2466 |
return true; |
|
2467 |
} |
|
2468 |
|
|
2469 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2470 |
|
|
2471 |
private void mirrorAllVertices(double[] output, int len, double[] input) |
|
2472 |
{ |
|
2473 |
for(int vertex=0; vertex<len; vertex++) |
|
2474 |
{ |
|
2475 |
output[2*vertex ] = input[2*vertex ]; |
|
2476 |
output[2*vertex+1] =-input[2*vertex+1]; |
|
2477 |
} |
|
2478 |
} |
|
2479 |
|
|
2480 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2481 |
|
|
2482 |
private void correctInfo(FaceTransform info, double scale, double sin, double cos, int oldSticker, boolean flip) |
|
2483 |
{ |
|
2484 |
mStickerCoords.remove(info.sticker); |
|
2485 |
|
|
2486 |
info.flip = flip; |
|
2487 |
info.sticker = oldSticker; |
|
2488 |
info.scale *= scale; |
|
2489 |
|
|
2490 |
mQuat1[0] = info.qx; |
|
2491 |
mQuat1[1] = info.qy; |
|
2492 |
mQuat1[2] = info.qz; |
|
2493 |
mQuat1[3] = info.qw; |
|
2494 |
|
|
2495 |
double sinHalf = computeSinHalf(cos); |
|
2496 |
double cosHalf = computeCosHalf(sin,cos); |
|
2497 |
|
|
2498 |
if( flip ) |
|
2499 |
{ |
|
2500 |
mQuat3[0] = 0.0f; |
|
2501 |
mQuat3[1] = 0.0f; |
|
2502 |
mQuat3[2] = sinHalf; |
|
2503 |
mQuat3[3] = cosHalf; |
|
2504 |
|
|
2505 |
mQuat4[0] = 1.0; |
|
2506 |
mQuat4[1] = 0.0; |
|
2507 |
mQuat4[2] = 0.0; |
|
2508 |
mQuat4[3] = 0.0; |
|
2509 |
|
|
2510 |
quatMultiply( mQuat3, mQuat4, mQuat2 ); |
|
2511 |
} |
|
2512 |
else |
|
2513 |
{ |
|
2514 |
mQuat2[0] = 0.0f; |
|
2515 |
mQuat2[1] = 0.0f; |
|
2516 |
mQuat2[2] = sinHalf; |
|
2517 |
mQuat2[3] = cosHalf; |
|
2518 |
} |
|
2519 |
|
|
2520 |
quatMultiply( mQuat1, mQuat2, mQuat3 ); |
|
2521 |
|
|
2522 |
info.qx = mQuat3[0]; |
|
2523 |
info.qy = mQuat3[1]; |
|
2524 |
info.qz = mQuat3[2]; |
|
2525 |
info.qw = mQuat3[3]; |
|
2526 |
} |
|
2527 |
|
|
2528 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2529 |
|
|
2530 |
private void printVert(double[] buffer) |
|
2531 |
{ |
|
2532 |
int len = buffer.length/2; |
|
2533 |
String str = ""; |
|
2534 |
|
|
2535 |
for(int i=0; i<len; i++) |
|
2536 |
{ |
|
2537 |
str += (" ("+buffer[2*i]+" , "+buffer[2*i+1]+" ) "); |
|
2538 |
} |
|
2539 |
|
|
2540 |
android.util.Log.d("D", str); |
|
2541 |
} |
|
2542 |
|
|
2543 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2544 |
|
|
2545 |
private boolean foundVertex(FaceTransform info, double[] buffer, int len, double[] newVert, |
|
2546 |
double[] oldVert, double lenFirstOld, int oldSticker, boolean inverted) |
|
2547 |
{ |
|
2548 |
for(int vertex=0; vertex<len; vertex++) |
|
2549 |
{ |
|
2550 |
double newX = newVert[2*vertex ]; |
|
2551 |
double newY = newVert[2*vertex+1]; |
|
2552 |
double lenIthNew = Math.sqrt(newX*newX + newY*newY); |
|
2553 |
double cos = computeCos( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld); |
|
2554 |
double sin = computeSin( oldVert[0], oldVert[1], newX, newY, lenIthNew, lenFirstOld); |
|
2555 |
|
|
2556 |
rotateAllVertices(buffer,len,newVert,sin,cos); |
|
2557 |
|
|
2558 |
if( isScaledVersionOf(buffer,oldVert,len,vertex,inverted) ) |
|
2559 |
{ |
|
2560 |
double scale = computeScale(oldVert,newVert); |
|
2561 |
correctInfo(info,scale,sin,cos,oldSticker,inverted); |
|
2562 |
return true; |
|
2563 |
} |
|
2564 |
} |
|
2565 |
|
|
2566 |
return false; |
|
2567 |
} |
|
2568 |
|
|
2569 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2570 |
|
|
2571 |
private boolean successfullyCollapsedStickers(final FaceTransform newInfo, final FaceTransform oldInfo) |
|
2572 |
{ |
|
2573 |
StickerCoords sNewInfo = mStickerCoords.get(newInfo.sticker); |
|
2574 |
StickerCoords sOldInfo = mStickerCoords.get(oldInfo.sticker); |
|
2575 |
double[] newVert = sNewInfo.vertices; |
|
2576 |
double[] oldVert = sOldInfo.vertices; |
|
2577 |
int oldLen = oldVert.length; |
|
2578 |
int newLen = newVert.length; |
|
2579 |
|
|
2580 |
if( oldLen == newLen ) |
|
2581 |
{ |
|
2582 |
int oldSticker = oldInfo.sticker; |
|
2583 |
double[] buffer1 = new double[oldLen]; |
|
2584 |
double lenFirstOld = Math.sqrt(oldVert[0]*oldVert[0] + oldVert[1]*oldVert[1]); |
|
2585 |
if( foundVertex(newInfo, buffer1, oldLen/2, newVert, oldVert, lenFirstOld, oldSticker, false) ) return true; |
|
2586 |
double[] buffer2 = new double[oldLen]; |
|
2587 |
mirrorAllVertices(buffer2, newLen/2, newVert); |
|
2588 |
if( foundVertex(newInfo, buffer1, oldLen/2, buffer2, oldVert, lenFirstOld, oldSticker, true ) ) return true; |
|
2589 |
} |
|
2590 |
|
|
2591 |
return false; |
|
2592 |
} |
|
2593 |
|
|
2594 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2595 |
|
|
2596 |
private double[][] constructVert(double[][] vertices, int[] index) |
|
2597 |
{ |
|
2598 |
int len = index.length; |
|
2599 |
double[][] ret = new double[len][4]; |
|
2600 |
|
|
2601 |
for(int i=0; i<len; i++) |
|
2602 |
{ |
|
2603 |
ret[i][0] = vertices[index[i]][0]; |
|
2604 |
ret[i][1] = vertices[index[i]][1]; |
|
2605 |
ret[i][2] = vertices[index[i]][2]; |
|
2606 |
ret[i][3] = 1.0f; |
|
2607 |
} |
|
2608 |
|
|
2609 |
return ret; |
|
2610 |
} |
|
2611 |
|
|
2612 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2613 |
|
|
2614 |
private void prepareAndRoundCorners(MeshBase mesh, double[][] vertices, int[][] vertIndexes, |
|
2615 |
float[][] corners, int[] cornerIndexes ) |
|
2616 |
{ |
|
2617 |
int numNeig, lenFV; |
|
2618 |
int lenV = vertices.length; |
|
2619 |
int[] verts = new int[2*(lenV-1)]; |
|
2620 |
Static3D[] staticVert = new Static3D[1]; |
|
2621 |
Static3D center = new Static3D(0,0,0); |
|
2622 |
double cx, cy, cz; |
|
2623 |
double[] singleV; |
|
2624 |
|
|
2625 |
for(int v=0; v<lenV; v++) |
|
2626 |
{ |
|
2627 |
// prepare verts[] |
|
2628 |
numNeig = 0; |
|
2629 |
|
|
2630 |
for (int[] vertIndex : vertIndexes) |
|
2631 |
{ |
|
2632 |
lenFV = vertIndex.length; |
|
2633 |
|
|
2634 |
for (int fv = 0; fv < lenFV; fv++) |
|
2635 |
if (vertIndex[fv] == v) |
|
2636 |
{ |
|
2637 |
int prev = fv > 0 ? fv - 1 : lenFV - 1; |
|
2638 |
int next = fv < lenFV - 1 ? fv + 1 : 0; |
|
2639 |
|
|
2640 |
verts[numNeig++] = vertIndex[prev]; |
|
2641 |
verts[numNeig++] = vertIndex[next]; |
|
2642 |
} |
|
2643 |
} |
|
2644 |
|
|
2645 |
cx=cy=cz=0.0f; |
|
2646 |
|
|
2647 |
// from verts[] prepare center |
|
2648 |
for(int n=0; n<numNeig; n++) |
|
2649 |
{ |
|
2650 |
singleV = vertices[verts[n]]; |
|
2651 |
|
|
2652 |
cx += singleV[0]; |
|
2653 |
cy += singleV[1]; |
|
2654 |
cz += singleV[2]; |
|
2655 |
} |
|
2656 |
center.set( (float)(cx/numNeig - vertices[v][0]), |
|
2657 |
(float)(cy/numNeig - vertices[v][1]), |
|
2658 |
(float)(cz/numNeig - vertices[v][2])); |
|
2659 |
|
|
2660 |
android.util.Log.e("D", "vertex: "+v+" CENTER: "+center.get0()+" "+center.get1()+" "+center.get2()); |
|
2661 |
|
|
2662 |
// round Corners |
|
2663 |
staticVert[0] = new Static3D( (float)vertices[v][0], (float)vertices[v][1], (float)vertices[v][2]); |
|
2664 |
|
|
2665 |
int corn = cornerIndexes[v]; |
|
2666 |
float strength = corners[corn][0]; |
|
2667 |
float radius = corners[corn][1]; |
|
2668 |
|
|
2669 |
roundCorners(mesh, center, staticVert, strength, radius); |
|
2670 |
} |
|
2671 |
} |
|
2672 |
|
|
2673 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2674 |
|
|
2675 |
private void correctComponents(MeshBase mesh, int numComponents) |
|
2676 |
{ |
|
2677 |
int numTexToBeAdded = numComponents-mesh.getNumTexComponents(); |
|
2678 |
|
|
2679 |
mesh.mergeEffComponents(); |
|
2680 |
|
|
2681 |
for(int i=0; i<numTexToBeAdded; i++ ) mesh.addEmptyTexComponent(); |
|
2682 |
} |
|
2683 |
|
|
2684 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2685 |
// PUBLIC |
|
2686 |
|
|
2687 |
public void printStickerCoords() |
|
2688 |
{ |
|
2689 |
int stickers = mStickerCoords.size(); |
|
2690 |
|
|
2691 |
android.util.Log.d("D", "---- STICKER COORDS ----"); |
|
2692 |
|
|
2693 |
for(int s=0; s<stickers; s++) |
|
2694 |
{ |
|
2695 |
String ver = "{ "; |
|
2696 |
StickerCoords info = mStickerCoords.get(s); |
|
2697 |
int len = info.vertices.length/2; |
|
2698 |
|
|
2699 |
for(int i =0; i<len; i++) |
|
2700 |
{ |
|
2701 |
if( i!=0 ) ver += ", "; |
|
2702 |
ver += ( (float)info.vertices[2*i]+"f, "+(float)info.vertices[2*i+1]+"f"); |
|
2703 |
} |
|
2704 |
|
|
2705 |
ver += " }"; |
|
2706 |
android.util.Log.d("D", ver); |
|
2707 |
} |
|
2708 |
|
|
2709 |
android.util.Log.d("D", "---- END STICKER COORDS ----"); |
|
2710 |
} |
|
2711 |
|
|
2712 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2713 |
|
|
2714 |
public void printFaceTransform() |
|
2715 |
{ |
|
2716 |
android.util.Log.d("D", "---- FACE TRANSFORM ---"); |
|
2717 |
|
|
2718 |
int faces = mFaceTransform.size(); |
|
2719 |
|
|
2720 |
for(int f=0; f<faces; f++) |
|
2721 |
{ |
|
2722 |
FaceTransform info = mFaceTransform.get(f); |
|
2723 |
|
|
2724 |
android.util.Log.e("D", "q=("+info.qx+", "+info.qy+", "+info.qz+", "+info.qw+") v=(" |
|
2725 |
+info.vx+", "+info.vy+", "+info.vz+") scale="+info.scale+" sticker="+info.sticker); |
|
2726 |
} |
|
2727 |
} |
|
2728 |
|
|
2729 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2730 |
|
|
2731 |
public void clear() |
|
2732 |
{ |
|
2733 |
mStickerCoords.clear(); |
|
2734 |
mFaceTransform.clear(); |
|
2735 |
} |
|
2736 |
|
|
2737 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2738 |
|
|
2739 |
public void createNewFaceTransform( final double[][] vertices, final int[][] indexes) |
|
2740 |
{ |
|
2741 |
mFaceTransform.clear(); |
|
2742 |
|
|
2743 |
int numFaces = indexes.length; |
|
2744 |
FaceTransform oldInfo; |
|
2745 |
|
|
2746 |
for(int face=0; face<numFaces; face++) |
|
2747 |
{ |
|
2748 |
FaceTransform newInfo = new FaceTransform(); |
|
2749 |
int[] index = indexes[face]; |
|
2750 |
double[][] vert = constructVert(vertices,index); |
|
2751 |
constructNew(newInfo,vert); |
|
2752 |
|
|
2753 |
for(int previous=0; previous<face; previous++) |
|
2754 |
{ |
|
2755 |
oldInfo = mFaceTransform.get(previous); |
|
2756 |
if( successfullyCollapsedStickers(newInfo,oldInfo) ) break; |
|
2757 |
} |
|
2758 |
|
|
2759 |
mFaceTransform.add(newInfo); |
|
2760 |
} |
|
2761 |
} |
|
2762 |
|
|
2763 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2764 |
|
|
2765 |
public MeshBase createRoundedSolid(final double[][] vertices, final int[][] vertIndexes, |
|
2766 |
final float[][] bands , final int[] bandIndexes, |
|
2767 |
final float[][] corners , final int[] cornerIndexes, |
|
2768 |
final int numComponents ) |
|
2769 |
{ |
|
2770 |
int numFaces = vertIndexes.length; |
|
2771 |
float[] band, bandsComputed; |
|
2772 |
MeshBase[] meshes = new MeshBase[numFaces]; |
|
2773 |
FaceTransform fInfo; |
|
2774 |
StickerCoords sInfo; |
|
2775 |
|
|
2776 |
for(int face=0; face<numFaces; face++) |
|
2777 |
{ |
|
2778 |
fInfo = mFaceTransform.get(face); |
|
2779 |
sInfo = mStickerCoords.get(fInfo.sticker); |
|
2780 |
|
|
2781 |
double[] verts = sInfo.vertices; |
|
2782 |
int lenVerts = verts.length; |
|
2783 |
float[] vertsFloat = new float[lenVerts]; |
|
2784 |
for(int i=0; i<lenVerts; i++) vertsFloat[i] = (float)verts[i]; |
|
2785 |
|
|
2786 |
band = bands[bandIndexes[face]]; |
|
2787 |
bandsComputed = computeBands( band[0], (int)band[1], band[2], band[3], (int)band[4]); |
|
2788 |
meshes[face] = new MeshPolygon(vertsFloat,bandsComputed,(int)band[5],(int)band[6]); |
|
2789 |
meshes[face].setEffectAssociation(0,(1<<face),0); |
|
2790 |
} |
|
2791 |
|
|
2792 |
MeshBase mesh = new MeshJoined(meshes); |
|
2793 |
Static3D center = new Static3D(0,0,0); |
|
2794 |
|
|
2795 |
for(int face=0; face<numFaces; face++) |
|
2796 |
{ |
|
2797 |
int assoc = (1<<face); |
|
2798 |
fInfo = mFaceTransform.get(face); |
|
2799 |
|
|
2800 |
float vx = (float)fInfo.vx; |
|
2801 |
float vy = (float)fInfo.vy; |
|
2802 |
float vz = (float)fInfo.vz; |
|
2803 |
float sc = (float)fInfo.scale; |
|
2804 |
float qx = (float)fInfo.qx; |
|
2805 |
float qy = (float)fInfo.qy; |
|
2806 |
float qz = (float)fInfo.qz; |
|
2807 |
float qw = (float)fInfo.qw; |
|
2808 |
|
|
2809 |
Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc); |
|
2810 |
Static3D move3D= new Static3D(vx,vy,vz); |
|
2811 |
Static4D quat = new Static4D(qx,qy,qz,qw); |
|
2812 |
|
|
2813 |
mesh.apply(new MatrixEffectScale(scale) ,assoc,-1); |
|
2814 |
mesh.apply(new MatrixEffectQuaternion(quat,center),assoc,-1); |
|
2815 |
mesh.apply(new MatrixEffectMove(move3D) ,assoc,-1); |
|
2816 |
} |
|
2817 |
|
|
2818 |
prepareAndRoundCorners(mesh, vertices, vertIndexes, corners, cornerIndexes); |
|
2819 |
|
|
2820 |
correctComponents(mesh,numComponents); |
|
2821 |
|
|
2822 |
return mesh; |
|
2823 |
} |
|
2207 | 2824 |
} |
src/main/java/org/distorted/objects/TwistyBandaged2Bar.java | ||
---|---|---|
59 | 59 |
{ 0.0f, -1.0f, -1.0f} |
60 | 60 |
}; |
61 | 61 |
|
62 |
private final double[][] VERTICES_SMALL = new double[][] |
|
63 |
{ |
|
64 |
{ 0.5, 0.5, 0.5 }, |
|
65 |
{ 0.5, 0.5,-0.5 }, |
|
66 |
{ 0.5,-0.5, 0.5 }, |
|
67 |
{ 0.5,-0.5,-0.5 }, |
|
68 |
{-0.5, 0.5, 0.5 }, |
|
69 |
{-0.5, 0.5,-0.5 }, |
|
70 |
{-0.5,-0.5, 0.5 }, |
|
71 |
{-0.5,-0.5,-0.5 }, |
|
72 |
}; |
|
73 |
|
|
74 |
private final double[][] VERTICES_BIG = new double[][] |
|
75 |
{ |
|
76 |
// TODO |
|
77 |
}; |
|
78 |
|
|
79 |
private final int[][] VERT_INDEXES = new int[][] |
|
80 |
{ |
|
81 |
{2,3,1,0}, // counterclockwise! |
|
82 |
{7,6,4,5}, |
|
83 |
{4,0,1,5}, |
|
84 |
{7,3,2,6}, |
|
85 |
{6,2,0,4}, |
|
86 |
{3,7,5,1} |
|
87 |
}; |
|
88 |
|
|
62 | 89 |
private static final int[] QUAT_INDICES = new int[] { 2 }; |
63 | 90 |
|
64 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
69 | 96 |
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN2, res, scrWidth); |
70 | 97 |
} |
71 | 98 |
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
double[][] getVertices(int cubitType) |
|
102 |
{ |
|
103 |
if( cubitType==0 ) // Small cubit |
|
104 |
{ |
|
105 |
return VERTICES_SMALL; |
|
106 |
} |
|
107 |
if( cubitType==1 ) // Big cubit |
|
108 |
{ |
|
109 |
return VERTICES_BIG; |
|
110 |
} |
|
111 |
|
|
112 |
return null; |
|
113 |
} |
|
114 |
|
|
115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
|
117 |
int[][] getVertIndexes(int cubitType) |
|
118 |
{ |
|
119 |
return VERT_INDEXES; |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
int getNumCubitTypes(int numLayers) |
|
125 |
{ |
|
126 |
return 2; |
|
127 |
} |
|
128 |
|
|
72 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 130 |
|
74 | 131 |
float[][] getPositions() |
src/main/java/org/distorted/objects/TwistyBandaged3Plate.java | ||
---|---|---|
95 | 95 |
{ 0.0f, 0.0f, -1.0f} |
96 | 96 |
}; |
97 | 97 |
|
98 |
private final double[][] VERTICES_SMALL = new double[][] |
|
99 |
{ |
|
100 |
{ 0.5, 0.5, 0.5 }, |
|
101 |
{ 0.5, 0.5,-0.5 }, |
|
102 |
{ 0.5,-0.5, 0.5 }, |
|
103 |
{ 0.5,-0.5,-0.5 }, |
|
104 |
{-0.5, 0.5, 0.5 }, |
|
105 |
{-0.5, 0.5,-0.5 }, |
|
106 |
{-0.5,-0.5, 0.5 }, |
|
107 |
{-0.5,-0.5,-0.5 }, |
|
108 |
}; |
|
109 |
|
|
110 |
private final double[][] VERTICES_BIG = new double[][] |
|
111 |
{ |
|
112 |
// TODO |
|
113 |
}; |
|
114 |
|
|
115 |
private final int[][] VERT_INDEXES = new int[][] |
|
116 |
{ |
|
117 |
{2,3,1,0}, // counterclockwise! |
|
118 |
{7,6,4,5}, |
|
119 |
{4,0,1,5}, |
|
120 |
{7,3,2,6}, |
|
121 |
{6,2,0,4}, |
|
122 |
{3,7,5,1} |
|
123 |
}; |
|
124 |
|
|
98 | 125 |
private static final int[] QUAT_INDICES = new int[] { 1, 3 }; |
99 | 126 |
|
100 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
105 | 132 |
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN3, res, scrWidth); |
106 | 133 |
} |
107 | 134 |
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
|
|
137 |
double[][] getVertices(int cubitType) |
|
138 |
{ |
|
139 |
if( cubitType==0 ) // Small cubit |
|
140 |
{ |
|
141 |
return VERTICES_SMALL; |
|
142 |
} |
|
143 |
if( cubitType==1 ) // Big cubit |
|
144 |
{ |
|
145 |
return VERTICES_BIG; |
|
146 |
} |
|
147 |
|
|
148 |
return null; |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
int[][] getVertIndexes(int cubitType) |
|
154 |
{ |
|
155 |
return VERT_INDEXES; |
|
156 |
} |
|
157 |
|
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
|
|
160 |
int getNumCubitTypes(int numLayers) |
|
161 |
{ |
|
162 |
return 2; |
|
163 |
} |
|
164 |
|
|
108 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 166 |
|
110 | 167 |
float[][] getPositions() |
src/main/java/org/distorted/objects/TwistyBandagedEvil.java | ||
---|---|---|
209 | 209 |
{ 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, -1.0f} |
210 | 210 |
}; |
211 | 211 |
|
212 |
private final double[][] VERTICES_SMALL = new double[][] |
|
213 |
{ |
|
214 |
{ 0.5, 0.5, 0.5 }, |
|
215 |
{ 0.5, 0.5,-0.5 }, |
|
216 |
{ 0.5,-0.5, 0.5 }, |
|
217 |
{ 0.5,-0.5,-0.5 }, |
|
218 |
{-0.5, 0.5, 0.5 }, |
|
219 |
{-0.5, 0.5,-0.5 }, |
|
220 |
{-0.5,-0.5, 0.5 }, |
|
221 |
{-0.5,-0.5,-0.5 }, |
|
222 |
}; |
|
223 |
|
|
224 |
private final double[][] VERTICES_MEDIUM = new double[][] |
|
225 |
{ |
|
226 |
// TODO |
|
227 |
}; |
|
228 |
|
|
229 |
private final double[][] VERTICES_BIG = new double[][] |
|
230 |
{ |
|
231 |
// TODO |
|
232 |
}; |
|
233 |
|
|
234 |
private final int[][] VERT_INDEXES = new int[][] |
|
235 |
{ |
|
236 |
{2,3,1,0}, // counterclockwise! |
|
237 |
{7,6,4,5}, |
|
238 |
{4,0,1,5}, |
|
239 |
{7,3,2,6}, |
|
240 |
{6,2,0,4}, |
|
241 |
{3,7,5,1} |
|
242 |
}; |
|
243 |
|
|
212 | 244 |
private static final int[] QUAT_INDICES = new int[] |
213 | 245 |
{ 0, 1, 0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 3 }; |
214 | 246 |
|
... | ... | |
220 | 252 |
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN4, res, scrWidth); |
221 | 253 |
} |
222 | 254 |
|
255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
256 |
|
|
257 |
double[][] getVertices(int cubitType) |
|
258 |
{ |
|
259 |
if( cubitType==0 ) // Small cubit |
|
260 |
{ |
|
261 |
return VERTICES_SMALL; |
|
262 |
} |
|
263 |
if( cubitType==1 ) // Medium cubit |
|
264 |
{ |
|
265 |
return VERTICES_MEDIUM; |
|
266 |
} |
|
267 |
if( cubitType==2 ) // Big cubit |
|
268 |
{ |
|
269 |
return VERTICES_BIG; |
|
270 |
} |
|
271 |
|
|
272 |
return null; |
|
273 |
} |
|
274 |
|
|
275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
276 |
|
|
277 |
int[][] getVertIndexes(int cubitType) |
|
278 |
{ |
|
279 |
return VERT_INDEXES; |
|
280 |
} |
|
281 |
|
|
282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
283 |
|
|
284 |
int getNumCubitTypes(int numLayers) |
|
285 |
{ |
|
286 |
return 3; |
|
287 |
} |
|
288 |
|
|
223 | 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
224 | 290 |
|
225 | 291 |
float[][] getPositions() |
src/main/java/org/distorted/objects/TwistyBandagedFused.java | ||
---|---|---|
64 | 64 |
{ 0.0f, 0.0f, -1.0f} |
65 | 65 |
}; |
66 | 66 |
|
67 |
private final double[][] VERTICES_SMALL = new double[][] |
|
68 |
{ |
|
69 |
{ 0.5, 0.5, 0.5 }, |
|
70 |
{ 0.5, 0.5,-0.5 }, |
|
71 |
{ 0.5,-0.5, 0.5 }, |
|
72 |
{ 0.5,-0.5,-0.5 }, |
|
73 |
{-0.5, 0.5, 0.5 }, |
|
74 |
{-0.5, 0.5,-0.5 }, |
|
75 |
{-0.5,-0.5, 0.5 }, |
|
76 |
{-0.5,-0.5,-0.5 }, |
|
77 |
}; |
|
78 |
|
|
79 |
private final double[][] VERTICES_BIG = new double[][] |
|
80 |
{ |
|
81 |
// TODO |
|
82 |
}; |
|
83 |
|
|
84 |
private final int[][] VERT_INDEXES = new int[][] |
|
85 |
{ |
|
86 |
{2,3,1,0}, // counterclockwise! |
|
87 |
{7,6,4,5}, |
|
88 |
{4,0,1,5}, |
|
89 |
{7,3,2,6}, |
|
90 |
{6,2,0,4}, |
|
91 |
{3,7,5,1} |
|
92 |
}; |
|
93 |
|
|
67 | 94 |
private static final int[] QUAT_INDICES = new int[] { 0 }; |
68 | 95 |
|
69 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
74 | 101 |
super(size, quat, texture, mesh, effects, moves, ObjectList.BAN1, res, scrWidth); |
75 | 102 |
} |
76 | 103 |
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
double[][] getVertices(int cubitType) |
|
107 |
{ |
|
108 |
if( cubitType==0 ) // Small cubit |
|
109 |
{ |
|
110 |
return VERTICES_SMALL; |
|
111 |
} |
|
112 |
if( cubitType==1 ) // Big cubit |
|
113 |
{ |
|
114 |
return VERTICES_BIG; |
|
115 |
} |
|
116 |
|
|
117 |
return null; |
|
118 |
} |
|
119 |
|
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
int[][] getVertIndexes(int cubitType) |
|
123 |
{ |
|
124 |
return VERT_INDEXES; |
|
125 |
} |
|
126 |
|
|
127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
128 |
|
|
129 |
int getNumCubitTypes(int numLayers) |
|
130 |
{ |
|
131 |
return 2; |
|
132 |
} |
|
133 |
|
|
77 | 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
78 | 135 |
|
79 | 136 |
float[][] getPositions() |
src/main/java/org/distorted/objects/TwistyCube.java | ||
---|---|---|
91 | 91 |
new Static4D( -0.5f, 0.5f, 0.5f, 0.5f) |
92 | 92 |
}; |
93 | 93 |
|
94 |
private static final double[][] VERTICES = new double[][] |
|
95 |
{ |
|
96 |
{ 0.5, 0.5, 0.5 }, |
|
97 |
{ 0.5, 0.5,-0.5 }, |
|
98 |
{ 0.5,-0.5, 0.5 }, |
|
99 |
{ 0.5,-0.5,-0.5 }, |
|
100 |
{-0.5, 0.5, 0.5 }, |
|
101 |
{-0.5, 0.5,-0.5 }, |
|
102 |
{-0.5,-0.5, 0.5 }, |
|
103 |
{-0.5,-0.5,-0.5 }, |
|
104 |
}; |
|
105 |
|
|
106 |
private static final int[][] VERT_INDEXES = new int[][] |
|
107 |
{ |
|
108 |
{2,3,1,0}, // counterclockwise! |
|
109 |
{7,6,4,5}, |
|
110 |
{4,0,1,5}, |
|
111 |
{7,3,2,6}, |
|
112 |
{6,2,0,4}, |
|
113 |
{3,7,5,1} |
|
114 |
}; |
|
115 |
|
|
116 |
private static final float[][] STICKERS = new float[][] |
|
117 |
{ |
|
118 |
{ -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f } |
|
119 |
}; |
|
120 |
|
|
94 | 121 |
private static MeshBase[] mMeshes; |
95 | 122 |
|
96 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
101 | 128 |
super(size, size, quat, texture, mesh, effects, moves, ObjectList.CUBE, res, scrWidth); |
102 | 129 |
} |
103 | 130 |
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
double[][] getVertices(int cubitType) |
|
134 |
{ |
|
135 |
return VERTICES; |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
int[][] getVertIndexes(int cubitType) |
|
141 |
{ |
|
142 |
return VERT_INDEXES; |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
// in the sense of shape, there's always only 1 cubit type. |
|
147 |
|
|
148 |
int getNumCubitTypes(int numLayers) |
|
149 |
{ |
|
150 |
return 1; |
|
151 |
} |
|
152 |
|
|
104 | 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
105 | 154 |
|
106 | 155 |
MeshBase createCubitMesh(int cubit, int numLayers) |
107 | 156 |
{ |
108 | 157 |
if( mMeshes==null ) |
109 | 158 |
{ |
159 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
160 |
factory.clear(); |
|
110 | 161 |
mMeshes = new MeshBase[ObjectList.CUBE.getNumVariants()]; |
111 | 162 |
} |
112 | 163 |
|
... | ... | |
115 | 166 |
|
116 | 167 |
if( mMeshes[index]==null ) |
117 | 168 |
{ |
118 |
mMeshes[index] = FactoryCubit.getInstance().createCubeMesh(index); |
|
169 |
int extraI, extraV, num; |
|
170 |
|
|
171 |
switch(numLayers) |
|
172 |
{ |
|
173 |
case 2 : num = 6; extraI = 2; extraV = 2; break; |
|
174 |
case 3 : num = 5; extraI = 2; extraV = 2; break; |
|
175 |
case 4 : num = 5; extraI = 1; extraV = 2; break; |
|
176 |
default: num = 5; extraI = 1; extraV = 0; break; |
|
177 |
} |
|
178 |
|
|
179 |
float[][] bands = new float[][] { {0.038f,35,0.5f,0.7f,num,extraI,extraV} }; |
|
180 |
int[] bandIndexes = new int[] { 0,0,0,0,0,0}; |
|
181 |
float[][] corners = new float[][] { {0.036f,0.12f} }; |
|
182 |
int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 }; |
|
183 |
|
|
184 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
185 |
|
|
186 |
factory.createNewFaceTransform(VERTICES,VERT_INDEXES); |
|
187 |
mMeshes[index] = factory.createRoundedSolid(VERTICES, VERT_INDEXES, |
|
188 |
bands, bandIndexes, |
|
189 |
corners, cornerIndexes, |
|
190 |
getNumCubitFaces() ); |
|
119 | 191 |
} |
120 | 192 |
|
121 | 193 |
return mMeshes[index].copy(true); |
... | ... | |
125 | 197 |
|
126 | 198 |
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top) |
127 | 199 |
{ |
128 |
float F = 0.5f; |
|
129 | 200 |
float R = 0.10f; |
130 | 201 |
float S = 0.08f; |
131 |
float[] vertices = { -F,-F, +F,-F, +F,+F, -F,+F}; |
|
132 | 202 |
|
133 | 203 |
FactorySticker factory = FactorySticker.getInstance(); |
134 |
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
|
|
204 |
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
|
135 | 205 |
} |
136 | 206 |
|
137 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
138 | 208 |
|
139 |
float[][] getCubitPositions(int size)
|
|
209 |
float[][] getCubitPositions(int numLayers)
|
|
140 | 210 |
{ |
141 |
int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1;
|
|
211 |
int numCubits = numLayers>1 ? 6*numLayers*numLayers - 12*numLayers + 8 : 1;
|
|
142 | 212 |
float[][] tmp = new float[numCubits][]; |
143 | 213 |
|
144 |
float diff = 0.5f*(size-1);
|
|
214 |
float diff = 0.5f*(numLayers-1);
|
|
145 | 215 |
int currentPosition = 0; |
146 | 216 |
|
147 |
for(int x = 0; x<size; x++)
|
|
148 |
for(int y = 0; y<size; y++)
|
|
149 |
for(int z = 0; z<size; z++)
|
|
150 |
if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 )
|
|
217 |
for(int x = 0; x<numLayers; x++)
|
|
218 |
for(int y = 0; y<numLayers; y++)
|
|
219 |
for(int z = 0; z<numLayers; z++)
|
|
220 |
if( x==0 || x==numLayers-1 || y==0 || y==numLayers-1 || z==0 || z==numLayers-1 )
|
|
151 | 221 |
{ |
152 | 222 |
tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff}; |
153 | 223 |
} |
... | ... | |
194 | 264 |
|
195 | 265 |
int getNumStickerTypes(int numLayers) |
196 | 266 |
{ |
197 |
return 1;
|
|
267 |
return STICKERS.length;
|
|
198 | 268 |
} |
199 | 269 |
|
200 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
94 | 94 |
|
95 | 95 |
private static final int[] mTetraToFaceMap = new int[] {1,2,3,0,5,6,7,4}; |
96 | 96 |
|
97 |
private final double[][] VERTICES_TETRA = new double[][] |
|
98 |
{ |
|
99 |
{-0.5, SQ2/4, 0.0}, |
|
100 |
{ 0.5, SQ2/4, 0.0}, |
|
101 |
{ 0.0,-SQ2/4, 0.5}, |
|
102 |
{ 0.0,-SQ2/4,-0.5} |
|
103 |
}; |
|
104 |
|
|
105 |
private final int[][] VERT_INDEXES_TETRA = new int[][] |
|
106 |
{ |
|
107 |
{2,1,0}, // counterclockwise! |
|
108 |
{2,3,1}, |
|
109 |
{3,2,0}, |
|
110 |
{3,0,1} |
|
111 |
}; |
|
112 |
|
|
113 |
private final double[][] VERTICES_OCTA = new double[][] |
|
114 |
{ |
|
115 |
{ 0.5, 0.0, 0.5}, |
|
116 |
{ 0.5, 0.0,-0.5}, |
|
117 |
{-0.5, 0.0,-0.5}, |
|
118 |
{-0.5, 0.0, 0.5}, |
|
119 |
{ 0.0, SQ2/2, 0.0}, |
|
120 |
{ 0.0,-SQ2/2, 0.0} |
|
121 |
}; |
|
122 |
|
|
123 |
private final int[][] VERT_INDEXES_OCTA = new int[][] |
|
124 |
{ |
|
125 |
{3,0,4}, // counterclockwise! |
|
126 |
{0,1,4}, |
|
127 |
{1,2,4}, |
|
128 |
{2,3,4}, |
|
129 |
{5,0,3}, |
|
130 |
{5,1,0}, |
|
131 |
{5,2,1}, |
|
132 |
{5,3,2} |
|
133 |
}; |
|
134 |
|
|
97 | 135 |
private static MeshBase mOctaMesh, mTetraMesh; |
98 | 136 |
|
99 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
104 | 142 |
super(size, size, quat, texture, mesh, effects, moves, ObjectList.DIAM, res, scrWidth); |
105 | 143 |
} |
106 | 144 |
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
double[][] getVertices(int cubitType) |
|
148 |
{ |
|
149 |
if( cubitType==0 ) // Tetrahedron |
|
150 |
{ |
|
151 |
return VERTICES_TETRA; |
|
152 |
} |
|
153 |
if( cubitType==1 ) // Octahedron |
|
154 |
{ |
|
155 |
return VERTICES_OCTA; |
|
156 |
} |
|
157 |
|
|
158 |
return null; |
|
159 |
} |
|
160 |
|
|
161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
|
|
163 |
int[][] getVertIndexes(int cubitType) |
|
164 |
{ |
|
165 |
if( cubitType==0 ) // Tetrahedron |
|
166 |
{ |
|
167 |
return VERT_INDEXES_TETRA; |
|
168 |
} |
|
169 |
if( cubitType==1 ) // Octahedron |
|
170 |
{ |
|
171 |
return VERT_INDEXES_OCTA; |
|
172 |
} |
|
173 |
|
|
174 |
return null; |
|
175 |
} |
|
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
|
|
179 |
int getNumCubitTypes(int numLayers) |
|
180 |
{ |
|
181 |
return 2; |
|
182 |
} |
|
183 |
|
|
107 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
108 | 185 |
|
109 | 186 |
float getScreenRatio() |
src/main/java/org/distorted/objects/TwistyDino.java | ||
---|---|---|
88 | 88 |
{-1.5f, 0.0f,-1.5f } |
89 | 89 |
}; |
90 | 90 |
|
91 |
private final double[][] VERTICES = new double[][] |
|
92 |
{ |
|
93 |
{-0.5, 0.0, 0.0}, |
|
94 |
{ 0.5, 0.0, 0.0}, |
|
95 |
{ 0.0,-0.5, 0.0}, |
|
96 |
{ 0.0, 0.0,-0.5} |
|
97 |
}; |
|
98 |
|
|
99 |
private final int[][] VERT_INDEXES = new int[][] |
|
100 |
{ |
|
101 |
{2,1,0}, // counterclockwise! |
|
102 |
{2,3,1}, |
|
103 |
{3,2,0}, |
|
104 |
{3,0,1} |
|
105 |
}; |
|
106 |
|
|
91 | 107 |
private static MeshBase mMesh; |
92 | 108 |
|
93 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
98 | 114 |
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth); |
99 | 115 |
} |
100 | 116 |
|
117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
double[][] getVertices(int cubitType) |
|
120 |
{ |
|
121 |
return VERTICES; |
|
122 |
} |
|
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
int[][] getVertIndexes(int cubitType) |
|
127 |
{ |
|
128 |
return VERT_INDEXES; |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
int getNumCubitTypes(int numLayers) |
|
134 |
{ |
|
135 |
return 1; |
|
136 |
} |
|
137 |
|
|
101 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 139 |
|
103 | 140 |
int mulQuat(int q1, int q2) |
src/main/java/org/distorted/objects/TwistyHelicopter.java | ||
---|---|---|
185 | 185 |
private static final int[] QUAT_INDICES = |
186 | 186 |
{ 0,13,14,1,12,2,3,7,20,6,13,17,7,23,18,12,22,10,8,16,11,21,19,9,3,15,14,0,5,2,1,4 }; |
187 | 187 |
|
188 |
private final double[][] VERTICES_CORNER = new double[][] |
|
189 |
{ |
|
190 |
// TODO |
|
191 |
}; |
|
192 |
|
|
193 |
private final int[][] VERT_INDEXES_CORNER = new int[][] |
|
194 |
{ |
|
195 |
// TODO |
|
196 |
}; |
|
197 |
|
|
198 |
private final double[][] VERTICES_FACE = new double[][] |
|
199 |
{ |
|
200 |
// TODO |
|
201 |
}; |
|
202 |
|
|
203 |
private final int[][] VERT_INDEXES_FACE = new int[][] |
|
204 |
{ |
|
205 |
// TODO |
|
206 |
}; |
|
207 |
|
|
188 | 208 |
private static MeshBase mCornerMesh, mFaceMesh; |
189 | 209 |
|
190 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
195 | 215 |
super(size, size, quat, texture, mesh, effects, moves, ObjectList.HELI, res, scrWidth); |
196 | 216 |
} |
197 | 217 |
|
218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 |
|
|
220 |
double[][] getVertices(int cubitType) |
|
221 |
{ |
Also available in: Unified diff
Convert the first object, the Cube, to the new Cubit-creating engine.