commit 28cb1607b2076ec53f946227aef0b08f5ed624ef
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Mar 24 22:02:46 2022 +0100

    Further progress with Bandaged 3x3.
    This requires a new API in DistortedNode to change the Mesh there.

diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java b/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
index 2d5fefea..651adfab 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
@@ -41,8 +41,8 @@ import org.distorted.main.RubikActivity;
 public class BandagedCreatorActivity extends AppCompatActivity
 {
     private static final int ACTIVITY_NUMBER = 3;
-    static final float RATIO_BAR   = 0.10f;
-    static final float RATIO_SCROLL= 0.30f;
+    private static final float RATIO_BAR   = 0.10f;
+    private static final float RATIO_SCROLL= 0.30f;
 
     public static final float DIALOG_BUTTON_SIZE  = 0.06f;
     public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
@@ -90,7 +90,7 @@ public class BandagedCreatorActivity extends AppCompatActivity
       {
       int barHeight    = (int)(mScreenHeight*RATIO_BAR);
       int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
-      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL));
+      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL-RATIO_BAR));
       mHeightBar = barHeight;
 
       LinearLayout layout = findViewById(R.id.lowerBar);
diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
index ad2cbee7..77f85342 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
@@ -38,7 +38,6 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
    private final BandagedCreatorView mView;
    private final DistortedScreen mScreen;
    private final Static3D mScale;
-   private final Static3D mMoveY;
    private final BandagedCubit[] mCubits;
    private float mScaleValue;
 
@@ -95,7 +94,6 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
      mScreen = new DistortedScreen();
      mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
      mScale = new Static3D(1,1,1);
-     mMoveY = new Static3D(0,0,0);
      mCubits= createCubits();
      }
 
@@ -108,7 +106,7 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
 
      for(int c=0; c<len; c++)
        {
-       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mMoveY,mScale,COLOR_DEFAULT);
+       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mScale,COLOR_DEFAULT);
        }
 
      return cubits;
@@ -135,21 +133,17 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
       int len = POSITIONS.length;
 
       for(int i=0; i<len; i++)
-        {
-        mCubits[i].scaleMove(mScaleValue);
-        mCubits[i].setTexture(COLOR_DEFAULT);
-        DistortedNode node = mCubits[i].getNode();
-        mScreen.attach(node);
-        }
-
-      float RB = BandagedCreatorActivity.RATIO_BAR;
-      float RS = BandagedCreatorActivity.RATIO_SCROLL;
-      float yOffset = (0.5f*RB/(1-RS))*height;
-      mMoveY.set1(yOffset);
+        if( mCubits[i].isAttached() )
+          {
+          mCubits[i].scaleMove(mScaleValue);
+          mCubits[i].setTexture(COLOR_DEFAULT);
+          DistortedNode node = mCubits[i].getNode();
+          mScreen.attach(node);
+          }
 
       mScale.set( mScaleValue,mScaleValue,mScaleValue );
       mScreenMin = Math.min(width, height);
-      mView.setScreenSize(width,height, (int)yOffset);
+      mView.setScreenSize(width,height);
       mScreen.resize(width,height);
       }
 
@@ -213,16 +207,9 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
 
        if( isAdjacent(pos1,pos2) )
          {
-         mCubits[index2].prepareJoin(pos1);
-
+         mCubits[index2].join(pos1,mScaleValue);
          mCubits[index1].detach();
-         DistortedNode node1 = mCubits[index1].getNode();
-         mScreen.detach(node1);
-         DistortedNode node2 = mCubits[index2].getNode();
-         mScreen.detach(node2);
-         mCubits[index2].swapNodes(mScaleValue);
-         DistortedNode node3 = mCubits[index2].getNode();
-         mScreen.attach(node3);
+         mScreen.detach(mCubits[index1].getNode());
          }
        }
      }
diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
index b79087c6..8a90ff7f 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
@@ -41,7 +41,6 @@ public class BandagedCreatorView extends GLSurfaceView
     private BandagedCreatorRenderer mRenderer;
     private BandagedTouchControl mTouchControl;
     private int mScreenWidth, mScreenHeight;
-    private int mYoffset;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
@@ -118,11 +117,10 @@ public class BandagedCreatorView extends GLSurfaceView
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public void setScreenSize(int width, int height, int yOffset)
+    public void setScreenSize(int width, int height)
       {
       mScreenWidth = width;
       mScreenHeight= height;
-      mYoffset     = yOffset;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -132,7 +130,7 @@ public class BandagedCreatorView extends GLSurfaceView
       {
       int action = event.getAction();
       int x = (int)event.getX();
-      int y = (int)event.getY() + mYoffset;
+      int y = (int)event.getY();
 
       switch(action)
          {
@@ -156,10 +154,14 @@ public class BandagedCreatorView extends GLSurfaceView
                                            mTouchedIndex1 = index;
                                            mTouchControl.markCubit(mTouchedIndex1, BandagedCreatorRenderer.COLOR_MARKED);
                                            }
-                                         else if( mTouchedIndex1 != index )
+                                         else
                                            {
                                            mTouchedIndex2 = index;
-                                           mTouchControl.markCubit(mTouchedIndex2, BandagedCreatorRenderer.COLOR_MARKED);
+
+                                           if( mTouchedIndex1 != index )
+                                             {
+                                             mTouchControl.markCubit(mTouchedIndex2, BandagedCreatorRenderer.COLOR_MARKED);
+                                             }
                                            }
                                          }
 
diff --git a/src/main/java/org/distorted/bandaged/BandagedCubit.java b/src/main/java/org/distorted/bandaged/BandagedCubit.java
index dd931214..355132db 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCubit.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCubit.java
@@ -36,13 +36,13 @@ public class BandagedCubit
 {
     private static final Static3D CENTER = new Static3D(0,0,0);
 
-    private DistortedNode mNode, mNewNode;
+    private final DistortedNode mNode;
     private final DistortedTexture mTexture;
     private final DistortedEffects mEffects;
     private final Static3D mMove;
 
     private float mUnscaledX, mUnscaledY, mUnscaledZ;
-    private float[] mPosition, mNewPosition;
+    private float[] mPosition;
     private boolean mIsAttached;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -70,7 +70,7 @@ public class BandagedCubit
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D moveY, Static3D scale, int color)
+    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale, int color)
       {
       mPosition = position;
       mIsAttached = true;
@@ -87,50 +87,35 @@ public class BandagedCubit
       MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
       MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER);
       MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
-      MatrixEffectMove moveSEffect = new MatrixEffectMove(mMove);
-      MatrixEffectMove moveYEffect = new MatrixEffectMove(moveY);
+      MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
 
       mEffects = new DistortedEffects();
       mEffects.apply(scaleEffect);
-      mEffects.apply(moveSEffect);
+      mEffects.apply(moveEffect);
       mEffects.apply(quat2Effect);
       mEffects.apply(quat1Effect);
-      mEffects.apply(moveYEffect);
 
       mNode = new DistortedNode(mTexture,mEffects,mesh);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    public void prepareJoin(float[] position)
+    public void join(float[] position, float scale)
       {
       int len1 = mPosition.length;
       int len2 = position.length;
 
-      mNewPosition = new float[len1+len2];
+      float[] tmpPosition = new float[len1+len2];
 
-      System.arraycopy(mPosition, 0, mNewPosition,    0, len1);
-      System.arraycopy(position , 0, mNewPosition, len1, len2);
+      System.arraycopy(mPosition, 0, tmpPosition,    0, len1);
+      System.arraycopy(position , 0, tmpPosition, len1, len2);
 
-/*
-int l= mPosition.length/3;
-String s="";
-for(int i=0; i<l; i++) s += (mPosition[3*i]+" "+mPosition[3*i+1]+" "+mPosition[3*i+2]+"\n");
-android.util.Log.e("D", "pos after joining: \n"+s);
-*/
-      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
-      MeshBase mesh = factory.createMesh(mNewPosition);
-      mNewNode = new DistortedNode(mTexture,mEffects,mesh);
-
-      computeMove(mNewPosition);
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
+      computeMove(tmpPosition);
+      mPosition = tmpPosition;
 
-    public void swapNodes(float scale)
-      {
-      mPosition = mNewPosition;
-      mNode = mNewNode;
+      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
+      MeshBase mesh = factory.createMesh(mPosition);
+      mNode.setMesh(mesh);
       mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
       }
 
diff --git a/src/main/res/layout/bandaged.xml b/src/main/res/layout/bandaged.xml
index 445c2e3b..a1845ac3 100644
--- a/src/main/res/layout/bandaged.xml
+++ b/src/main/res/layout/bandaged.xml
@@ -27,11 +27,12 @@
 
     <LinearLayout
         android:id="@+id/lowerBar"
+        android:layout_below="@+id/bandagedCreatorObjectView"
         android:layout_alignParentBottom="true"
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:orientation="horizontal"
-        android:background="@android:color/transparent">
+        android:background="@color/light_grey">
     </LinearLayout>
 
 </RelativeLayout>
