commit 6be7eb580f8f733301c7e58e7282d453cd525c03
Author: leszek <leszek@koltunski.pl>
Date:   Tue Dec 10 14:05:47 2024 +0100

    SingleMeshCube: add possibility to disappear individual Cubies

diff --git a/src/main/java/org/distorted/examples/glow/GlowRenderer.java b/src/main/java/org/distorted/examples/glow/GlowRenderer.java
index 6f06dea..885d654 100644
--- a/src/main/java/org/distorted/examples/glow/GlowRenderer.java
+++ b/src/main/java/org/distorted/examples/glow/GlowRenderer.java
@@ -19,9 +19,6 @@
 
 package org.distorted.examples.glow;
 
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.pm.ConfigurationInfo;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
diff --git a/src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java b/src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java
index a8c11e9..c489edc 100644
--- a/src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java
+++ b/src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java
@@ -19,9 +19,6 @@
 
 package org.distorted.examples.movingglow;
 
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.pm.ConfigurationInfo;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
diff --git a/src/main/java/org/distorted/examples/singlemesh/SingleMeshActivity.java b/src/main/java/org/distorted/examples/singlemesh/SingleMeshActivity.java
index b8efe6a..6ca2550 100644
--- a/src/main/java/org/distorted/examples/singlemesh/SingleMeshActivity.java
+++ b/src/main/java/org/distorted/examples/singlemesh/SingleMeshActivity.java
@@ -24,6 +24,7 @@ import android.opengl.GLSurfaceView;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
+import android.widget.CheckBox;
 
 import org.distorted.examples.R;
 import org.distorted.library.main.DistortedLibrary;
@@ -79,11 +80,30 @@ public class SingleMeshActivity extends Activity
       SingleMeshSurfaceView v = findViewById(R.id.singlemeshSurfaceView);
       SingleMeshRenderer r = v.getRenderer();
 
-      if( id == R.id.singlemeshButtonLX ) r.apply( (1<<4) + (0<<2) + 0, 0 );
-      if( id == R.id.singlemeshButtonRX ) r.apply( (2<<4) + (0<<2) + 0, 0 );
-      if( id == R.id.singlemeshButtonLY ) r.apply( (0<<4) + (1<<2) + 0, 1 );
-      if( id == R.id.singlemeshButtonRY ) r.apply( (0<<4) + (2<<2) + 0, 1 );
-      if( id == R.id.singlemeshButtonLZ ) r.apply( (0<<4) + (0<<2) + 1, 2 );
-      if( id == R.id.singlemeshButtonRZ ) r.apply( (0<<4) + (0<<2) + 2, 2 );
+      if( id == R.id.singlemeshButtonLX ) r.apply( 0, 0 );
+      if( id == R.id.singlemeshButtonRX ) r.apply( 1, 0 );
+      if( id == R.id.singlemeshButtonLY ) r.apply( 2, 1 );
+      if( id == R.id.singlemeshButtonRY ) r.apply( 3, 1 );
+      if( id == R.id.singlemeshButtonLZ ) r.apply( 4, 2 );
+      if( id == R.id.singlemeshButtonRZ ) r.apply( 5, 2 );
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void Disappear(View view)
+      {
+      CheckBox box = (CheckBox)view;
+      int id = box.getId();
+      SingleMeshSurfaceView v = findViewById(R.id.singlemeshSurfaceView);
+      SingleMeshRenderer r = v.getRenderer();
+
+      if( id == R.id.singlemesh0 ) r.disappear(0);
+      if( id == R.id.singlemesh1 ) r.disappear(1);
+      if( id == R.id.singlemesh2 ) r.disappear(2);
+      if( id == R.id.singlemesh3 ) r.disappear(3);
+      if( id == R.id.singlemesh4 ) r.disappear(4);
+      if( id == R.id.singlemesh5 ) r.disappear(5);
+      if( id == R.id.singlemesh6 ) r.disappear(6);
+      if( id == R.id.singlemesh7 ) r.disappear(7);
       }
 }
diff --git a/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java b/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
index ab35301..45dd491 100644
--- a/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
+++ b/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
@@ -19,9 +19,6 @@
 
 package org.distorted.examples.singlemesh;
 
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.pm.ConfigurationInfo;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -32,6 +29,7 @@ import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.VertexEffectDeform;
+import org.distorted.library.effect.VertexEffectDisappear;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
 import org.distorted.library.effect.VertexEffectSink;
@@ -112,10 +110,13 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
     private final DistortedEffects mEffects;
     private final Static3D mScale;
     private final VertexEffectRotate mRotate;
+    private final VertexEffectDisappear mDisappear;
     private final Dynamic1D mAngleDyn;
     private final Static1D mAngle;
     private final Static3D mAxis;
+    private final boolean[] mInvisible;
 
+    private int mDisappearAssociation;
     private DistortedTexture mTexture;
     private MeshBase mMesh;
 
@@ -126,6 +127,7 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
 
     SingleMeshRenderer(GLSurfaceView v)
       {
+      mInvisible = new boolean[CUBIT_MOVES.length];
       mResources = v.getResources();
 
       mScreen = new DistortedScreen();
@@ -149,9 +151,12 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
       mAngleDyn.add( mAngle );
 
       mRotate = new VertexEffectRotate( mAngleDyn, mAxis, new Static3D(0,0,0) );
+      mDisappear = new VertexEffectDisappear();
+      mDisappear.setMeshAssociation(0,-1);
 
       mEffects = new DistortedEffects();
       mEffects.apply( mRotate );
+      mEffects.apply( mDisappear );
       mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
       mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
       mEffects.apply( new MatrixEffectScale(mScale));
@@ -190,25 +195,75 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
       mScreen.attach(mTexture,mEffects,mMesh);
 
       VertexEffectRotate.enable();
+      VertexEffectDisappear.enable();
 
       DistortedLibrary.onSurfaceCreated(this);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotation: LX 0, RX 1, LY 2, RY 3, LZ 4, RZ 5
 
-    void apply(int andAssoc, int axisIndex)
+    void apply(int rotation, int axisIndex)
       {
-      mRotate.setMeshAssociation(andAssoc,-1);
+      int andAssoc = 0;
 
+      switch(rotation)
+        {
+        case 0: andAssoc=addAssociation(0,andAssoc);
+                andAssoc=addAssociation(1,andAssoc);
+                andAssoc=addAssociation(2,andAssoc);
+                andAssoc=addAssociation(3,andAssoc);
+                break;
+        case 1: andAssoc=addAssociation(4,andAssoc);
+                andAssoc=addAssociation(5,andAssoc);
+                andAssoc=addAssociation(6,andAssoc);
+                andAssoc=addAssociation(7,andAssoc);
+                break;
+        case 2: andAssoc=addAssociation(0,andAssoc);
+                andAssoc=addAssociation(1,andAssoc);
+                andAssoc=addAssociation(4,andAssoc);
+                andAssoc=addAssociation(5,andAssoc);
+                break;
+        case 3: andAssoc=addAssociation(2,andAssoc);
+                andAssoc=addAssociation(3,andAssoc);
+                andAssoc=addAssociation(6,andAssoc);
+                andAssoc=addAssociation(7,andAssoc);
+                break;
+        case 4: andAssoc=addAssociation(0,andAssoc);
+                andAssoc=addAssociation(2,andAssoc);
+                andAssoc=addAssociation(4,andAssoc);
+                andAssoc=addAssociation(6,andAssoc);
+                break;
+        case 5: andAssoc=addAssociation(1,andAssoc);
+                andAssoc=addAssociation(3,andAssoc);
+                andAssoc=addAssociation(5,andAssoc);
+                andAssoc=addAssociation(7,andAssoc);
+                break;
+        }
+
+      mRotate.setMeshAssociation(andAssoc,-1);
       mAngle.set(360);
+      mAxis.set(AXIS[axisIndex]);
+      mAngleDyn.resetToBeginning();
+      }
 
-      mAxis.set0(AXIS[axisIndex].get0());
-      mAxis.set1(AXIS[axisIndex].get1());
-      mAxis.set2(AXIS[axisIndex].get2());
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-      mAngleDyn.resetToBeginning();
+    void disappear(int cubit)
+      {
+      mInvisible[cubit] = !mInvisible[cubit];
+
+      if( mInvisible[cubit] ) mDisappearAssociation = addAssociation(cubit,mDisappearAssociation);
+      else                    mDisappearAssociation = remAssociation(cubit,mDisappearAssociation);
+
+      mDisappear.setMeshAssociation(mDisappearAssociation,-1);
       }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    int addAssociation(int cubit, int assoc) { return (assoc |  (1<<cubit)); }
+    int remAssociation(int cubit, int assoc) { return (assoc & ~(1<<cubit)); }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     private Bitmap createTexture()
@@ -244,7 +299,7 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
 
      MeshBase createCubitMesh()
       {
-      final int MESHES=6;
+      final int MESHES= 6;
       int association = 1;
       MeshBase[] meshes = new MeshSquare[MESHES];
       meshes[0] = new MeshSquare(10,10);
@@ -345,10 +400,7 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
 
       cubits[NUM_CUBITS-1] = createCubitMesh();   // NUM_CUBITS-1 (or anything non-zero!)
 
-      for(int i=0; i<NUM_CUBITS-1; i++)
-        {
-        cubits[i] = cubits[NUM_CUBITS-1].copy(true);
-        }
+      for(int i=0; i<NUM_CUBITS-1; i++) cubits[i] = cubits[NUM_CUBITS-1].copy(true);
 
       for(int i=0; i<NUM_CUBITS; i++)
         {
@@ -357,15 +409,7 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Lib
         }
 
       MeshBase result = new MeshJoined(cubits);
-
-      result.setEffectAssociation( 0, (1<<4) + (1<<2) + 1, 0);
-      result.setEffectAssociation( 1, (1<<4) + (1<<2) + 2, 0);
-      result.setEffectAssociation( 2, (1<<4) + (2<<2) + 1, 0);
-      result.setEffectAssociation( 3, (1<<4) + (2<<2) + 2, 0);
-      result.setEffectAssociation( 4, (2<<4) + (1<<2) + 1, 0);
-      result.setEffectAssociation( 5, (2<<4) + (1<<2) + 2, 0);
-      result.setEffectAssociation( 6, (2<<4) + (2<<2) + 1, 0);
-      result.setEffectAssociation( 7, (2<<4) + (2<<2) + 2, 0);
+      for(int i=0; i<CUBIT_MOVES.length; i++) result.setEffectAssociation( i, (1<<i), 0);
 
       return result;
       }
diff --git a/src/main/res/layout/singlemeshlayout.xml b/src/main/res/layout/singlemeshlayout.xml
index 32920cc..bde3a92 100644
--- a/src/main/res/layout/singlemeshlayout.xml
+++ b/src/main/res/layout/singlemeshlayout.xml
@@ -60,4 +60,84 @@
 
     </LinearLayout>
 
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+
+        <CheckBox
+            android:id="@+id/singlemesh0"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="1"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh1"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="2"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh2"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="3"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh3"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="4"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh4"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="5"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh5"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="6"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh6"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="7"
+            android:textSize="12sp"/>
+        <CheckBox
+            android:id="@+id/singlemesh7"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:checked="false"
+            android:onClick="Disappear"
+            android:text="8"
+            android:textSize="12sp"/>
+
+    </LinearLayout>
+
 </LinearLayout>
\ No newline at end of file
