Revision 0919eba7
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/helpers/FactoryCubit.java | ||
---|---|---|
238 | 238 |
} |
239 | 239 |
} |
240 | 240 |
|
241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
242 |
|
|
243 |
MeshBase createFacesHelicopterCorner() |
|
244 |
{ |
|
245 |
MeshBase[] meshes = new MeshBase[6]; |
|
246 |
|
|
247 |
float E = 0.5f; |
|
248 |
float F = SQ2/4; |
|
249 |
float G = 1.0f/12; |
|
250 |
float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4}; |
|
251 |
float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7); |
|
252 |
|
|
253 |
meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3); |
|
254 |
meshes[0].setEffectAssociation(0,1,0); |
|
255 |
meshes[1] = meshes[0].copy(true); |
|
256 |
meshes[1].setEffectAssociation(0,2,0); |
|
257 |
meshes[2] = meshes[0].copy(true); |
|
258 |
meshes[2].setEffectAssociation(0,4,0); |
|
259 |
|
|
260 |
float[] vertices1 = { -F,-G, 0,-G, +F,-G, 0,2*G }; |
|
261 |
float[] bands1 = computeBands(0.00f,0,0,0.0f,3); |
|
262 |
meshes[3] = new MeshPolygon(vertices1,bands1,1,5); |
|
263 |
meshes[3].setEffectAssociation(0,8,0); |
|
264 |
meshes[4] = meshes[3].copy(true); |
|
265 |
meshes[4].setEffectAssociation(0,16,0); |
|
266 |
meshes[5] = meshes[3].copy(true); |
|
267 |
meshes[5].setEffectAssociation(0,32,0); |
|
268 |
|
|
269 |
return new MeshJoined(meshes); |
|
270 |
} |
|
271 |
|
|
272 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
273 | 242 |
|
274 | 243 |
MeshBase createFacesHelicopterFace() |
... | ... | |
753 | 722 |
|
754 | 723 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
755 | 724 |
// EFFECTS |
756 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
757 |
|
|
758 |
VertexEffect[] createVertexEffectsHelicopterCorner() |
|
759 |
{ |
|
760 |
float E = 0.5f; |
|
761 |
|
|
762 |
Static3D axisX = new Static3D(1,0,0); |
|
763 |
Static3D axisY = new Static3D(0,1,0); |
|
764 |
Static3D axis0 = new Static3D(-SQ2/2,0,SQ2/2); |
|
765 |
Static3D axis1 = new Static3D(+SQ3/3,+SQ3/3,+SQ3/3); |
|
766 |
Static1D angle1 = new Static1D(+90); |
|
767 |
Static1D angle2 = new Static1D(-90); |
|
768 |
Static1D angle3 = new Static1D(-135); |
|
769 |
Static1D angle4 = new Static1D(90); |
|
770 |
Static1D angle5 = new Static1D(120); |
|
771 |
Static1D angle6 = new Static1D(240); |
|
772 |
Static3D center1= new Static3D(0,0,0); |
|
773 |
Static3D center2= new Static3D(-0.25f,-0.25f,-0.25f); |
|
774 |
Static3D move1 = new Static3D(-E/4,-E/4,0); |
|
775 |
Static3D move2 = new Static3D(-0.25f,(-1.0f/6)-0.25f,-0.25f); |
|
776 |
|
|
777 |
VertexEffect[] effect = new VertexEffect[10]; |
|
778 |
|
|
779 |
effect[0] = new VertexEffectMove(move1); |
|
780 |
effect[1] = new VertexEffectScale(new Static3D(1,1,-1)); |
|
781 |
effect[2] = new VertexEffectRotate(angle1,axisX,center1); |
|
782 |
effect[3] = new VertexEffectRotate(angle2,axisY,center1); |
|
783 |
effect[4] = new VertexEffectMove(move2); |
|
784 |
effect[5] = new VertexEffectRotate(angle1,axisX,center2); |
|
785 |
effect[6] = new VertexEffectRotate(angle3,axisY,center2); |
|
786 |
effect[7] = new VertexEffectRotate(angle4,axis0,center2); |
|
787 |
effect[8] = new VertexEffectRotate(angle5,axis1,center2); |
|
788 |
effect[9] = new VertexEffectRotate(angle6,axis1,center2); |
|
789 |
|
|
790 |
effect[0].setMeshAssociation( 7,-1); // meshes 0,1,2 |
|
791 |
effect[1].setMeshAssociation( 6,-1); // meshes 1,2 |
|
792 |
effect[2].setMeshAssociation( 2,-1); // mesh 1 |
|
793 |
effect[3].setMeshAssociation( 4,-1); // mesh 2 |
|
794 |
effect[4].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
795 |
effect[5].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
796 |
effect[6].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
797 |
effect[7].setMeshAssociation(56,-1); // meshes 3,4,5 |
|
798 |
effect[8].setMeshAssociation(16,-1); // mesh 4 |
|
799 |
effect[9].setMeshAssociation(32,-1); // mesh 5 |
|
800 |
|
|
801 |
return effect; |
|
802 |
} |
|
803 |
|
|
804 | 725 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
805 | 726 |
|
806 | 727 |
VertexEffect[] createVertexEffectsHelicopterFace() |
... | ... | |
1329 | 1250 |
// OBJECTS |
1330 | 1251 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1331 | 1252 |
|
1332 |
|
|
1333 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1334 |
// Helicopter |
|
1335 |
|
|
1336 |
public MeshBase createHelicopterCornerMesh() |
|
1337 |
{ |
|
1338 |
MeshBase mesh = createFacesHelicopterCorner(); |
|
1339 |
VertexEffect[] effects = createVertexEffectsHelicopterCorner(); |
|
1340 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
1341 |
|
|
1342 |
float E = 0.5f; |
|
1343 |
Static3D roundingCenter = new Static3D(-E/2,-E/2,-E/2); |
|
1344 |
|
|
1345 |
Static3D[] verticesType1 = new Static3D[1]; |
|
1346 |
verticesType1[0] = new Static3D(0.0f,0.0f,0.0f); |
|
1347 |
roundCorners(mesh,roundingCenter,verticesType1,0.08f,0.15f); |
|
1348 |
|
|
1349 |
Static3D[] verticesType2 = new Static3D[3]; |
|
1350 |
verticesType2[0] = new Static3D(-E, 0, 0); |
|
1351 |
verticesType2[1] = new Static3D( 0,-E, 0); |
|
1352 |
verticesType2[2] = new Static3D( 0, 0,-E); |
|
1353 |
roundCorners(mesh,roundingCenter,verticesType2,0.08f,0.20f); |
|
1354 |
|
|
1355 |
mesh.mergeEffComponents(); |
|
1356 |
|
|
1357 |
return mesh; |
|
1358 |
} |
|
1359 |
|
|
1360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
1361 |
|
|
1362 | 1253 |
public MeshBase createHelicopterFaceMesh() |
1363 | 1254 |
{ |
1364 | 1255 |
MeshBase mesh = createFacesHelicopterFace(); |
... | ... | |
1965 | 1856 |
|
1966 | 1857 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1967 | 1858 |
|
1968 |
private double computeScale(double[] v1, double[] v2) |
|
1859 |
private double computeScale(double[] v1, double[] v2, int v1i, int v2i)
|
|
1969 | 1860 |
{ |
1970 |
double lenSq1 = v1[0]*v1[0] + v1[1]*v1[1]; |
|
1971 |
double lenSq2 = v2[0]*v2[0] + v2[1]*v2[1]; |
|
1861 |
double v1x = v1[2*v1i]; |
|
1862 |
double v1y = v1[2*v1i+1]; |
|
1863 |
double v2x = v2[2*v2i]; |
|
1864 |
double v2y = v2[2*v2i+1]; |
|
1865 |
|
|
1866 |
double lenSq1 = v1x*v1x + v1y*v1y; |
|
1867 |
double lenSq2 = v2x*v2x + v2y*v2y; |
|
1972 | 1868 |
|
1973 | 1869 |
return Math.sqrt(lenSq2/lenSq1); |
1974 | 1870 |
} |
... | ... | |
2005 | 1901 |
|
2006 | 1902 |
private boolean isScaledVersionOf(double[] newVert, double[] oldVert, int len, int vertex, boolean inverted) |
2007 | 1903 |
{ |
1904 |
int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted); |
|
2008 | 1905 |
double EPSILON = 0.001; |
2009 |
double scale = computeScale(newVert,oldVert); |
|
1906 |
double scale = computeScale(newVert,oldVert,newZeroIndex,0);
|
|
2010 | 1907 |
|
2011 | 1908 |
for(int i=1; i<len; i++) |
2012 | 1909 |
{ |
... | ... | |
2112 | 2009 |
|
2113 | 2010 |
if( isScaledVersionOf(buffer,oldVert,len,vertex,inverted) ) |
2114 | 2011 |
{ |
2115 |
double scale = computeScale(oldVert,newVert); |
|
2012 |
int newZeroIndex = computeRotatedIndex(0,len,vertex,inverted); |
|
2013 |
double scale = computeScale(oldVert,newVert,0,newZeroIndex); |
|
2116 | 2014 |
correctInfo(info,scale,sin,cos,oldSticker,inverted); |
2117 | 2015 |
return true; |
2118 | 2016 |
} |
src/main/java/org/distorted/objects/TwistyHelicopter.java | ||
---|---|---|
33 | 33 |
import org.distorted.library.type.Static3D; |
34 | 34 |
import org.distorted.library.type.Static4D; |
35 | 35 |
import org.distorted.main.R; |
36 |
import org.distorted.main.RubikSurfaceView; |
|
37 | 36 |
|
38 | 37 |
import java.util.Random; |
39 | 38 |
|
... | ... | |
185 | 184 |
private static final int[] QUAT_INDICES = |
186 | 185 |
{ 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 | 186 |
|
188 |
private final double[][] VERTICES_CORNER = new double[][] |
|
187 |
private static final double[][] VERTICES_CORNER = new double[][]
|
|
189 | 188 |
{ |
190 |
// TODO |
|
189 |
{-0.50f, 0.00f, 0.00f}, |
|
190 |
{ 0.00f,-0.50f, 0.00f}, |
|
191 |
{ 0.00f, 0.00f,-0.50f}, |
|
192 |
{-0.25f,-0.25f,-0.25f}, |
|
193 |
{ 0.00f, 0.00f, 0.00f} |
|
191 | 194 |
}; |
192 | 195 |
|
193 |
private final int[][] VERT_INDEXES_CORNER = new int[][] |
|
196 |
private static final int[][] VERT_INDEXES_CORNER = new int[][]
|
|
194 | 197 |
{ |
195 |
// TODO |
|
198 |
{0,1,4}, |
|
199 |
{2,0,4}, |
|
200 |
{1,2,4}, |
|
201 |
{3,1,0}, |
|
202 |
{3,2,1}, |
|
203 |
{3,0,2} |
|
196 | 204 |
}; |
197 | 205 |
|
198 |
private final double[][] VERTICES_FACE = new double[][] |
|
206 |
private static final float E = 0.1666666f; |
|
207 |
|
|
208 |
private static final double[][] VERTICES_FACE = new double[][] |
|
209 |
{ |
|
210 |
{ 0.00f +E, 0.00f +E, 0.00f }, |
|
211 |
{ 0.50f +E, 0.00f +E, 0.00f }, |
|
212 |
{ 0.00f +E, 0.50f +E, 0.00f }, |
|
213 |
{ 0.25f +E, 0.25f +E,-0.25f }, |
|
214 |
}; |
|
215 |
|
|
216 |
private static final int[][] VERT_INDEXES_FACE = new int[][] |
|
199 | 217 |
{ |
200 |
// TODO |
|
218 |
{ 0,1,2 }, |
|
219 |
{ 2,1,3 }, |
|
220 |
{ 0,1,3 }, |
|
221 |
{ 2,0,3 } |
|
201 | 222 |
}; |
202 | 223 |
|
203 |
private final int[][] VERT_INDEXES_FACE = new int[][]
|
|
224 |
private static final float[][] STICKERS = new float[][]
|
|
204 | 225 |
{ |
205 |
// TODO
|
|
226 |
{ -0.5f, 0.25f, 0.25f, -0.5f, 0.25f, 0.25f }
|
|
206 | 227 |
}; |
207 | 228 |
|
208 |
private static MeshBase mCornerMesh, mFaceMesh;
|
|
229 |
private static MeshBase[] mMeshes;
|
|
209 | 230 |
|
210 | 231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
211 | 232 |
|
... | ... | |
219 | 240 |
|
220 | 241 |
double[][] getVertices(int cubitType) |
221 | 242 |
{ |
222 |
if( cubitType==0 ) // Corner |
|
223 |
{ |
|
224 |
return VERTICES_CORNER; |
|
225 |
} |
|
226 |
if( cubitType==1 ) // Face |
|
227 |
{ |
|
228 |
return VERTICES_FACE; |
|
229 |
} |
|
230 |
|
|
243 |
if( cubitType==0 ) return VERTICES_CORNER; |
|
244 |
if( cubitType==1 ) return VERTICES_FACE; |
|
231 | 245 |
return null; |
232 | 246 |
} |
233 | 247 |
|
... | ... | |
235 | 249 |
|
236 | 250 |
int[][] getVertIndexes(int cubitType) |
237 | 251 |
{ |
238 |
if( cubitType==0 ) // Corner |
|
239 |
{ |
|
240 |
return VERT_INDEXES_CORNER; |
|
241 |
} |
|
242 |
if( cubitType==1 ) // Face |
|
243 |
{ |
|
244 |
return VERT_INDEXES_FACE; |
|
245 |
} |
|
246 |
|
|
252 |
if( cubitType==0 ) return VERT_INDEXES_CORNER; |
|
253 |
if( cubitType==1 ) return VERT_INDEXES_FACE; |
|
247 | 254 |
return null; |
248 | 255 |
} |
249 | 256 |
|
... | ... | |
251 | 258 |
|
252 | 259 |
int getNumCubitTypes(int numLayers) |
253 | 260 |
{ |
254 |
return 1;
|
|
261 |
return 2;
|
|
255 | 262 |
} |
256 | 263 |
|
257 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
319 | 326 |
|
320 | 327 |
MeshBase createCubitMesh(int cubit, int numLayers) |
321 | 328 |
{ |
329 |
if( mMeshes==null ) |
|
330 |
{ |
|
331 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
332 |
factory.clear(); |
|
333 |
mMeshes = new MeshBase[2]; |
|
334 |
} |
|
335 |
|
|
322 | 336 |
MeshBase mesh; |
323 | 337 |
|
324 | 338 |
if( cubit<8 ) |
325 | 339 |
{ |
326 |
if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createHelicopterCornerMesh(); |
|
327 |
mesh = mCornerMesh.copy(true); |
|
340 |
if( mMeshes[0]==null ) |
|
341 |
{ |
|
342 |
float[][] bands= new float[][] |
|
343 |
{ |
|
344 |
{0.028f,35,0.16f,0.7f,7,3,3}, |
|
345 |
{0.000f, 0,1.00f,0.0f,3,1,5} |
|
346 |
}; |
|
347 |
int[] bandIndexes = new int[] { 0,0,0,1,1,1 }; |
|
348 |
float[][] corners = new float[][] { {0.08f,0.15f}, {0.08f,0.20f} }; |
|
349 |
int[] cornerIndexes = new int[] { 1,1,1,0,0 }; |
|
350 |
float[][] centers = new float[][] { {-0.25f, -0.25f, -0.25f} }; |
|
351 |
int[] centerIndexes = new int[] { 0,0,0,-1,0 }; |
|
352 |
|
|
353 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
354 |
factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER); |
|
355 |
mMeshes[0] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER, |
|
356 |
bands, bandIndexes, |
|
357 |
corners, cornerIndexes, |
|
358 |
centers, centerIndexes, |
|
359 |
getNumCubitFaces() ); |
|
360 |
} |
|
361 |
mesh = mMeshes[0].copy(true); |
|
328 | 362 |
} |
329 | 363 |
else |
330 | 364 |
{ |
331 |
if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createHelicopterFaceMesh(); |
|
332 |
mesh = mFaceMesh.copy(true); |
|
365 |
if( mMeshes[1]==null ) mMeshes[1] = FactoryCubit.getInstance().createHelicopterFaceMesh(); |
|
366 |
/* |
|
367 |
{ |
|
368 |
float[][] bands= new float[][] |
|
369 |
{ |
|
370 |
{0.028f,35,0.16f,0.7f,7,3,3}, |
|
371 |
{0.000f, 0,1.00f,0.0f,3,1,3} |
|
372 |
}; |
|
373 |
int[] bandIndexes = new int[] { 0,1,1,1 }; |
|
374 |
float[][] corners = new float[][] { {0.06f,0.15f}, {0.06f,0.20f} }; |
|
375 |
int[] cornerIndexes = new int[] { 0,1,1,-1 }; |
|
376 |
float[][] centers = new float[][] { {-1.0f/12, -1.0f/12, -1.0f/4} }; |
|
377 |
int[] centerIndexes = new int[] { 0,0,0,-1 }; |
|
378 |
|
|
379 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
380 |
factory.createNewFaceTransform(VERTICES_FACE,VERT_INDEXES_FACE); |
|
381 |
mMeshes[1] = factory.createRoundedSolid(VERTICES_FACE, VERT_INDEXES_FACE, |
|
382 |
bands, bandIndexes, |
|
383 |
corners, cornerIndexes, |
|
384 |
centers, centerIndexes, |
|
385 |
getNumCubitFaces() ); |
|
386 |
} |
|
387 |
|
|
388 |
*/ |
|
389 |
mesh = mMeshes[1].copy(true); |
|
333 | 390 |
} |
334 | 391 |
|
335 | 392 |
int index = QUAT_INDICES[cubit]; |
src/main/java/org/distorted/objects/TwistySkewb.java | ||
---|---|---|
521 | 521 |
corners, cornerIndexes, |
522 | 522 |
centers, centerIndexes, |
523 | 523 |
getNumCubitFaces() ); |
524 |
//mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh(); |
|
525 | 524 |
} |
526 | 525 |
mesh = mMeshes[0].copy(true); |
527 | 526 |
} |
Also available in: Unified diff
Correct still one bug with collapsing stickers in teh new Cubit engine.
Convert the Helicopter corner cubits to the new engine.