Project

General

Profile

« Previous | Next » 

Revision 28cb1607

Added by Leszek Koltunski over 2 years ago

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

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
41 41
public class BandagedCreatorActivity extends AppCompatActivity
42 42
{
43 43
    private static final int ACTIVITY_NUMBER = 3;
44
    static final float RATIO_BAR   = 0.10f;
45
    static final float RATIO_SCROLL= 0.30f;
44
    private static final float RATIO_BAR   = 0.10f;
45
    private static final float RATIO_SCROLL= 0.30f;
46 46

  
47 47
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
48 48
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
......
90 90
      {
91 91
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
92 92
      int viewHeight   = (int)(mScreenHeight*RATIO_SCROLL);
93
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL));
93
      int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL-RATIO_BAR));
94 94
      mHeightBar = barHeight;
95 95

  
96 96
      LinearLayout layout = findViewById(R.id.lowerBar);
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
38 38
   private final BandagedCreatorView mView;
39 39
   private final DistortedScreen mScreen;
40 40
   private final Static3D mScale;
41
   private final Static3D mMoveY;
42 41
   private final BandagedCubit[] mCubits;
43 42
   private float mScaleValue;
44 43

  
......
95 94
     mScreen = new DistortedScreen();
96 95
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
97 96
     mScale = new Static3D(1,1,1);
98
     mMoveY = new Static3D(0,0,0);
99 97
     mCubits= createCubits();
100 98
     }
101 99

  
......
108 106

  
109 107
     for(int c=0; c<len; c++)
110 108
       {
111
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mMoveY,mScale,COLOR_DEFAULT);
109
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,mScale,COLOR_DEFAULT);
112 110
       }
113 111

  
114 112
     return cubits;
......
135 133
      int len = POSITIONS.length;
136 134

  
137 135
      for(int i=0; i<len; i++)
138
        {
139
        mCubits[i].scaleMove(mScaleValue);
140
        mCubits[i].setTexture(COLOR_DEFAULT);
141
        DistortedNode node = mCubits[i].getNode();
142
        mScreen.attach(node);
143
        }
144

  
145
      float RB = BandagedCreatorActivity.RATIO_BAR;
146
      float RS = BandagedCreatorActivity.RATIO_SCROLL;
147
      float yOffset = (0.5f*RB/(1-RS))*height;
148
      mMoveY.set1(yOffset);
136
        if( mCubits[i].isAttached() )
137
          {
138
          mCubits[i].scaleMove(mScaleValue);
139
          mCubits[i].setTexture(COLOR_DEFAULT);
140
          DistortedNode node = mCubits[i].getNode();
141
          mScreen.attach(node);
142
          }
149 143

  
150 144
      mScale.set( mScaleValue,mScaleValue,mScaleValue );
151 145
      mScreenMin = Math.min(width, height);
152
      mView.setScreenSize(width,height, (int)yOffset);
146
      mView.setScreenSize(width,height);
153 147
      mScreen.resize(width,height);
154 148
      }
155 149

  
......
213 207

  
214 208
       if( isAdjacent(pos1,pos2) )
215 209
         {
216
         mCubits[index2].prepareJoin(pos1);
217

  
210
         mCubits[index2].join(pos1,mScaleValue);
218 211
         mCubits[index1].detach();
219
         DistortedNode node1 = mCubits[index1].getNode();
220
         mScreen.detach(node1);
221
         DistortedNode node2 = mCubits[index2].getNode();
222
         mScreen.detach(node2);
223
         mCubits[index2].swapNodes(mScaleValue);
224
         DistortedNode node3 = mCubits[index2].getNode();
225
         mScreen.attach(node3);
212
         mScreen.detach(mCubits[index1].getNode());
226 213
         }
227 214
       }
228 215
     }
src/main/java/org/distorted/bandaged/BandagedCreatorView.java
41 41
    private BandagedCreatorRenderer mRenderer;
42 42
    private BandagedTouchControl mTouchControl;
43 43
    private int mScreenWidth, mScreenHeight;
44
    private int mYoffset;
45 44

  
46 45
///////////////////////////////////////////////////////////////////////////////////////////////////
47 46
// PUBLIC API
......
118 117

  
119 118
///////////////////////////////////////////////////////////////////////////////////////////////////
120 119

  
121
    public void setScreenSize(int width, int height, int yOffset)
120
    public void setScreenSize(int width, int height)
122 121
      {
123 122
      mScreenWidth = width;
124 123
      mScreenHeight= height;
125
      mYoffset     = yOffset;
126 124
      }
127 125

  
128 126
///////////////////////////////////////////////////////////////////////////////////////////////////
......
132 130
      {
133 131
      int action = event.getAction();
134 132
      int x = (int)event.getX();
135
      int y = (int)event.getY() + mYoffset;
133
      int y = (int)event.getY();
136 134

  
137 135
      switch(action)
138 136
         {
......
156 154
                                           mTouchedIndex1 = index;
157 155
                                           mTouchControl.markCubit(mTouchedIndex1, BandagedCreatorRenderer.COLOR_MARKED);
158 156
                                           }
159
                                         else if( mTouchedIndex1 != index )
157
                                         else
160 158
                                           {
161 159
                                           mTouchedIndex2 = index;
162
                                           mTouchControl.markCubit(mTouchedIndex2, BandagedCreatorRenderer.COLOR_MARKED);
160

  
161
                                           if( mTouchedIndex1 != index )
162
                                             {
163
                                             mTouchControl.markCubit(mTouchedIndex2, BandagedCreatorRenderer.COLOR_MARKED);
164
                                             }
163 165
                                           }
164 166
                                         }
165 167

  
src/main/java/org/distorted/bandaged/BandagedCubit.java
36 36
{
37 37
    private static final Static3D CENTER = new Static3D(0,0,0);
38 38

  
39
    private DistortedNode mNode, mNewNode;
39
    private final DistortedNode mNode;
40 40
    private final DistortedTexture mTexture;
41 41
    private final DistortedEffects mEffects;
42 42
    private final Static3D mMove;
43 43

  
44 44
    private float mUnscaledX, mUnscaledY, mUnscaledZ;
45
    private float[] mPosition, mNewPosition;
45
    private float[] mPosition;
46 46
    private boolean mIsAttached;
47 47

  
48 48
///////////////////////////////////////////////////////////////////////////////////////////////////
......
70 70
// PUBLIC API
71 71
///////////////////////////////////////////////////////////////////////////////////////////////////
72 72

  
73
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D moveY, Static3D scale, int color)
73
    public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale, int color)
74 74
      {
75 75
      mPosition = position;
76 76
      mIsAttached = true;
......
87 87
      MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
88 88
      MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat1, CENTER);
89 89
      MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat2, CENTER);
90
      MatrixEffectMove moveSEffect = new MatrixEffectMove(mMove);
91
      MatrixEffectMove moveYEffect = new MatrixEffectMove(moveY);
90
      MatrixEffectMove moveEffect = new MatrixEffectMove(mMove);
92 91

  
93 92
      mEffects = new DistortedEffects();
94 93
      mEffects.apply(scaleEffect);
95
      mEffects.apply(moveSEffect);
94
      mEffects.apply(moveEffect);
96 95
      mEffects.apply(quat2Effect);
97 96
      mEffects.apply(quat1Effect);
98
      mEffects.apply(moveYEffect);
99 97

  
100 98
      mNode = new DistortedNode(mTexture,mEffects,mesh);
101 99
      }
102 100

  
103 101
///////////////////////////////////////////////////////////////////////////////////////////////////
104 102

  
105
    public void prepareJoin(float[] position)
103
    public void join(float[] position, float scale)
106 104
      {
107 105
      int len1 = mPosition.length;
108 106
      int len2 = position.length;
109 107

  
110
      mNewPosition = new float[len1+len2];
108
      float[] tmpPosition = new float[len1+len2];
111 109

  
112
      System.arraycopy(mPosition, 0, mNewPosition,    0, len1);
113
      System.arraycopy(position , 0, mNewPosition, len1, len2);
110
      System.arraycopy(mPosition, 0, tmpPosition,    0, len1);
111
      System.arraycopy(position , 0, tmpPosition, len1, len2);
114 112

  
115
/*
116
int l= mPosition.length/3;
117
String s="";
118
for(int i=0; i<l; i++) s += (mPosition[3*i]+" "+mPosition[3*i+1]+" "+mPosition[3*i+2]+"\n");
119
android.util.Log.e("D", "pos after joining: \n"+s);
120
*/
121
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
122
      MeshBase mesh = factory.createMesh(mNewPosition);
123
      mNewNode = new DistortedNode(mTexture,mEffects,mesh);
124

  
125
      computeMove(mNewPosition);
126
      }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
113
      computeMove(tmpPosition);
114
      mPosition = tmpPosition;
129 115

  
130
    public void swapNodes(float scale)
131
      {
132
      mPosition = mNewPosition;
133
      mNode = mNewNode;
116
      FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
117
      MeshBase mesh = factory.createMesh(mPosition);
118
      mNode.setMesh(mesh);
134 119
      mMove.set( scale*mUnscaledX, scale*mUnscaledY, scale*mUnscaledZ);
135 120
      }
136 121

  
src/main/res/layout/bandaged.xml
27 27

  
28 28
    <LinearLayout
29 29
        android:id="@+id/lowerBar"
30
        android:layout_below="@+id/bandagedCreatorObjectView"
30 31
        android:layout_alignParentBottom="true"
31 32
        android:layout_width="match_parent"
32 33
        android:layout_height="0dp"
33 34
        android:orientation="horizontal"
34
        android:background="@android:color/transparent">
35
        android:background="@color/light_grey">
35 36
    </LinearLayout>
36 37

  
37 38
</RelativeLayout>

Also available in: Unified diff