Revision be56193c
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/objects/TwistyIvy.java | ||
---|---|---|
26 | 26 |
import org.distorted.helpers.FactoryCubit; |
27 | 27 |
import org.distorted.helpers.FactorySticker; |
28 | 28 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
29 |
import org.distorted.library.effect.VertexEffect; |
|
30 |
import org.distorted.library.effect.VertexEffectMove; |
|
31 |
import org.distorted.library.effect.VertexEffectRotate; |
|
32 |
import org.distorted.library.effect.VertexEffectScale; |
|
29 | 33 |
import org.distorted.library.main.DistortedEffects; |
30 | 34 |
import org.distorted.library.main.DistortedTexture; |
31 | 35 |
import org.distorted.library.mesh.MeshBase; |
36 |
import org.distorted.library.mesh.MeshJoined; |
|
37 |
import org.distorted.library.mesh.MeshPolygon; |
|
32 | 38 |
import org.distorted.library.mesh.MeshSquare; |
39 |
import org.distorted.library.type.Static1D; |
|
33 | 40 |
import org.distorted.library.type.Static3D; |
34 | 41 |
import org.distorted.library.type.Static4D; |
35 | 42 |
import org.distorted.main.R; |
... | ... | |
40 | 47 |
|
41 | 48 |
public class TwistyIvy extends TwistyObject |
42 | 49 |
{ |
50 |
public static final float IVY_D = 0.003f; |
|
51 |
public static final float IVY_C = 0.59f; |
|
52 |
public static final float IVY_M = 0.35f; |
|
53 |
private static final int IVY_N = 8; |
|
54 |
|
|
43 | 55 |
private static final int FACES_PER_CUBIT =6; |
44 | 56 |
|
45 | 57 |
// the four rotation axis of a RubikIvy. Must be normalized. |
... | ... | |
198 | 210 |
return 0; |
199 | 211 |
} |
200 | 212 |
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
MeshBase createFacesIvyCorner() |
|
216 |
{ |
|
217 |
MeshBase[] meshes = new MeshBase[6]; |
|
218 |
|
|
219 |
final float angle = (float)Math.PI/(2*IVY_N); |
|
220 |
final float CORR = 1.0f - 2*IVY_D; |
|
221 |
final float DIST = -0.5f*CORR + IVY_D; |
|
222 |
float[] vertices = new float[2*(IVY_N+1)+6]; |
|
223 |
|
|
224 |
vertices[0] = (0.5f-IVY_M) * IVY_C; |
|
225 |
vertices[1] = (DIST-IVY_M) * IVY_C; |
|
226 |
vertices[2] = (0.5f-IVY_M) * IVY_C; |
|
227 |
vertices[3] = (0.5f-IVY_M) * IVY_C; |
|
228 |
vertices[4] = (DIST-IVY_M) * IVY_C; |
|
229 |
vertices[5] = (0.5f-IVY_M) * IVY_C; |
|
230 |
|
|
231 |
for(int i=0; i<=IVY_N; i++) |
|
232 |
{ |
|
233 |
float ang = (IVY_N-i)*angle; |
|
234 |
float sin = (float)Math.sin(ang); |
|
235 |
float cos = (float)Math.cos(ang); |
|
236 |
|
|
237 |
vertices[2*i+6] = (CORR*(cos-0.5f)-IVY_M)*IVY_C; |
|
238 |
vertices[2*i+7] = (CORR*(sin-0.5f)-IVY_M)*IVY_C; |
|
239 |
} |
|
240 |
|
|
241 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
242 |
float[] bands0 = factory.computeBands(+0.012f,20,0.2f,0.5f,7); |
|
243 |
float[] bands1 = factory.computeBands(-0.100f,20,0.2f,0.0f,2); |
|
244 |
|
|
245 |
meshes[0] = new MeshPolygon(vertices,bands0,1,2); |
|
246 |
meshes[0].setEffectAssociation(0,1,0); |
|
247 |
meshes[1] = meshes[0].copy(true); |
|
248 |
meshes[1].setEffectAssociation(0,2,0); |
|
249 |
meshes[2] = meshes[0].copy(true); |
|
250 |
meshes[2].setEffectAssociation(0,4,0); |
|
251 |
meshes[3] = new MeshPolygon(vertices,bands1,1,2); |
|
252 |
meshes[3].setEffectAssociation(0,8,0); |
|
253 |
meshes[4] = meshes[3].copy(true); |
|
254 |
meshes[4].setEffectAssociation(0,16,0); |
|
255 |
meshes[5] = meshes[3].copy(true); |
|
256 |
meshes[5].setEffectAssociation(0,32,0); |
|
257 |
|
|
258 |
return new MeshJoined(meshes); |
|
259 |
} |
|
260 |
|
|
261 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
262 |
|
|
263 |
private VertexEffect[] createVertexEffectsIvyCorner() |
|
264 |
{ |
|
265 |
Static3D axisX = new Static3D(1,0,0); |
|
266 |
Static3D axisY = new Static3D(0,1,0); |
|
267 |
Static1D angle1 = new Static1D(+90); |
|
268 |
Static1D angle2 = new Static1D(-90); |
|
269 |
Static3D center = new Static3D(0,0,0); |
|
270 |
Static3D move1 = new Static3D(IVY_M-0.5f,IVY_M-0.5f,0); |
|
271 |
|
|
272 |
VertexEffect[] effect = new VertexEffect[5]; |
|
273 |
|
|
274 |
effect[0] = new VertexEffectScale(1/IVY_C); |
|
275 |
effect[1] = new VertexEffectMove(move1); |
|
276 |
effect[2] = new VertexEffectScale(new Static3D(1,1,-1)); |
|
277 |
effect[3] = new VertexEffectRotate(angle1,axisX,center); |
|
278 |
effect[4] = new VertexEffectRotate(angle2,axisY,center); |
|
279 |
|
|
280 |
effect[2].setMeshAssociation(54,-1); // meshes 1,2,4,5 |
|
281 |
effect[3].setMeshAssociation(18,-1); // meshes 1,4 |
|
282 |
effect[4].setMeshAssociation(36,-1); // meshes 2,5 |
|
283 |
|
|
284 |
return effect; |
|
285 |
} |
|
286 |
|
|
287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
288 |
|
|
289 |
private MeshBase createFacesIvyFace() |
|
290 |
{ |
|
291 |
MeshBase[] meshes = new MeshBase[2]; |
|
292 |
|
|
293 |
final float angle = (float)Math.PI/(2*IVY_N); |
|
294 |
final float CORR = 1.0f - 2*IVY_D; |
|
295 |
float[] vertices = new float[4*IVY_N]; |
|
296 |
|
|
297 |
for(int i=0; i<IVY_N; i++) |
|
298 |
{ |
|
299 |
float sin = (float)Math.sin(i*angle); |
|
300 |
float cos = (float)Math.cos(i*angle); |
|
301 |
|
|
302 |
vertices[2*i ] = CORR*(0.5f-cos); |
|
303 |
vertices[2*i+1 ] = CORR*(0.5f-sin); |
|
304 |
vertices[2*i +2*IVY_N] = CORR*(cos-0.5f); |
|
305 |
vertices[2*i+1+2*IVY_N] = CORR*(sin-0.5f); |
|
306 |
} |
|
307 |
|
|
308 |
FactoryCubit factory = FactoryCubit.getInstance(); |
|
309 |
float[] bands0 = factory.computeBands(+0.03f,35,0.5f,0.5f,5); |
|
310 |
float[] bands1 = factory.computeBands(-0.10f,45,0.5f,0.0f,2); |
|
311 |
|
|
312 |
meshes[0] = new MeshPolygon(vertices,bands0,0,0); |
|
313 |
meshes[0].setEffectAssociation(0,1,0); |
|
314 |
meshes[1] = new MeshPolygon(vertices,bands1,0,0); |
|
315 |
meshes[1].setEffectAssociation(0,2,0); |
|
316 |
|
|
317 |
return new MeshJoined(meshes); |
|
318 |
} |
|
319 |
|
|
320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
321 |
|
|
322 |
private MeshBase createIvyFaceMesh() |
|
323 |
{ |
|
324 |
MeshBase mesh = createFacesIvyFace(); |
|
325 |
|
|
326 |
Static3D center = new Static3D(-0.0f,-0.0f,-0.5f); |
|
327 |
Static3D[] vertices = new Static3D[2]; |
|
328 |
vertices[0] = new Static3D(-0.5f,+0.5f,+0.0f); |
|
329 |
vertices[1] = new Static3D(+0.5f,-0.5f,+0.0f); |
|
330 |
|
|
331 |
FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.03f,0.10f); |
|
332 |
|
|
333 |
mesh.mergeEffComponents(); |
|
334 |
mesh.addEmptyTexComponent(); |
|
335 |
mesh.addEmptyTexComponent(); |
|
336 |
mesh.addEmptyTexComponent(); |
|
337 |
mesh.addEmptyTexComponent(); |
|
338 |
|
|
339 |
return mesh; |
|
340 |
} |
|
341 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
342 |
|
|
343 |
private MeshBase createIvyCornerMesh() |
|
344 |
{ |
|
345 |
MeshBase mesh = createFacesIvyCorner(); |
|
346 |
VertexEffect[] effects = createVertexEffectsIvyCorner(); |
|
347 |
for( VertexEffect effect : effects ) mesh.apply(effect); |
|
348 |
|
|
349 |
Static3D center = new Static3D(-0.5f,-0.5f,-0.5f); |
|
350 |
Static3D[] vertices = new Static3D[4]; |
|
351 |
vertices[0] = new Static3D(+0.0f,+0.0f,+0.0f); |
|
352 |
vertices[1] = new Static3D(-1.0f,+0.0f,+0.0f); |
|
353 |
vertices[2] = new Static3D(+0.0f,-1.0f,+0.0f); |
|
354 |
vertices[3] = new Static3D(+0.0f,+0.0f,-1.0f); |
|
355 |
|
|
356 |
FactoryCubit.getInstance().roundCorners(mesh,center,vertices,0.03f,0.10f); |
|
357 |
|
|
358 |
mesh.mergeEffComponents(); |
|
359 |
|
|
360 |
return mesh; |
|
361 |
} |
|
362 |
|
|
201 | 363 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
202 | 364 |
|
203 | 365 |
MeshBase createCubitMesh(int cubit, int numLayers) |
... | ... | |
206 | 368 |
|
207 | 369 |
if( cubit<4 ) |
208 | 370 |
{ |
209 |
if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createIvyCornerMesh();
|
|
371 |
if( mCornerMesh==null ) mCornerMesh = createIvyCornerMesh(); |
|
210 | 372 |
mesh = mCornerMesh.copy(true); |
211 | 373 |
} |
212 | 374 |
else |
213 | 375 |
{ |
214 |
if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createIvyFaceMesh();
|
|
376 |
if( mFaceMesh==null ) mFaceMesh = createIvyFaceMesh(); |
|
215 | 377 |
mesh = mFaceMesh.copy(true); |
216 | 378 |
} |
217 | 379 |
|
Also available in: Unified diff
Move all the special cubit-creating code out of FactoryCubit and to the Object classes, and thus hopefully finish implementing the new cubit creating engine.