Project

General

Profile

« Previous | Next » 

Revision 6be7eb58

Added by Leszek Koltunski about 1 month ago

SingleMeshCube: add possibility to disappear individual Cubies

View differences:

src/main/java/org/distorted/examples/glow/GlowRenderer.java
19 19

  
20 20
package org.distorted.examples.glow;
21 21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25 22
import android.content.res.Resources;
26 23
import android.graphics.Bitmap;
27 24
import android.graphics.BitmapFactory;
src/main/java/org/distorted/examples/movingglow/MovingGlowRenderer.java
19 19

  
20 20
package org.distorted.examples.movingglow;
21 21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25 22
import android.content.res.Resources;
26 23
import android.graphics.Bitmap;
27 24
import android.graphics.BitmapFactory;
src/main/java/org/distorted/examples/singlemesh/SingleMeshActivity.java
24 24
import android.os.Bundle;
25 25
import android.view.View;
26 26
import android.widget.Button;
27
import android.widget.CheckBox;
27 28

  
28 29
import org.distorted.examples.R;
29 30
import org.distorted.library.main.DistortedLibrary;
......
79 80
      SingleMeshSurfaceView v = findViewById(R.id.singlemeshSurfaceView);
80 81
      SingleMeshRenderer r = v.getRenderer();
81 82

  
82
      if( id == R.id.singlemeshButtonLX ) r.apply( (1<<4) + (0<<2) + 0, 0 );
83
      if( id == R.id.singlemeshButtonRX ) r.apply( (2<<4) + (0<<2) + 0, 0 );
84
      if( id == R.id.singlemeshButtonLY ) r.apply( (0<<4) + (1<<2) + 0, 1 );
85
      if( id == R.id.singlemeshButtonRY ) r.apply( (0<<4) + (2<<2) + 0, 1 );
86
      if( id == R.id.singlemeshButtonLZ ) r.apply( (0<<4) + (0<<2) + 1, 2 );
87
      if( id == R.id.singlemeshButtonRZ ) r.apply( (0<<4) + (0<<2) + 2, 2 );
83
      if( id == R.id.singlemeshButtonLX ) r.apply( 0, 0 );
84
      if( id == R.id.singlemeshButtonRX ) r.apply( 1, 0 );
85
      if( id == R.id.singlemeshButtonLY ) r.apply( 2, 1 );
86
      if( id == R.id.singlemeshButtonRY ) r.apply( 3, 1 );
87
      if( id == R.id.singlemeshButtonLZ ) r.apply( 4, 2 );
88
      if( id == R.id.singlemeshButtonRZ ) r.apply( 5, 2 );
89
      }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
    public void Disappear(View view)
94
      {
95
      CheckBox box = (CheckBox)view;
96
      int id = box.getId();
97
      SingleMeshSurfaceView v = findViewById(R.id.singlemeshSurfaceView);
98
      SingleMeshRenderer r = v.getRenderer();
99

  
100
      if( id == R.id.singlemesh0 ) r.disappear(0);
101
      if( id == R.id.singlemesh1 ) r.disappear(1);
102
      if( id == R.id.singlemesh2 ) r.disappear(2);
103
      if( id == R.id.singlemesh3 ) r.disappear(3);
104
      if( id == R.id.singlemesh4 ) r.disappear(4);
105
      if( id == R.id.singlemesh5 ) r.disappear(5);
106
      if( id == R.id.singlemesh6 ) r.disappear(6);
107
      if( id == R.id.singlemesh7 ) r.disappear(7);
88 108
      }
89 109
}
src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
19 19

  
20 20
package org.distorted.examples.singlemesh;
21 21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25 22
import android.content.res.Resources;
26 23
import android.graphics.Bitmap;
27 24
import android.graphics.Canvas;
......
32 29
import org.distorted.library.effect.MatrixEffectQuaternion;
33 30
import org.distorted.library.effect.MatrixEffectScale;
34 31
import org.distorted.library.effect.VertexEffectDeform;
32
import org.distorted.library.effect.VertexEffectDisappear;
35 33
import org.distorted.library.effect.VertexEffectMove;
36 34
import org.distorted.library.effect.VertexEffectRotate;
37 35
import org.distorted.library.effect.VertexEffectSink;
......
112 110
    private final DistortedEffects mEffects;
113 111
    private final Static3D mScale;
114 112
    private final VertexEffectRotate mRotate;
113
    private final VertexEffectDisappear mDisappear;
115 114
    private final Dynamic1D mAngleDyn;
116 115
    private final Static1D mAngle;
117 116
    private final Static3D mAxis;
117
    private final boolean[] mInvisible;
118 118

  
119
    private int mDisappearAssociation;
119 120
    private DistortedTexture mTexture;
120 121
    private MeshBase mMesh;
121 122

  
......
126 127

  
127 128
    SingleMeshRenderer(GLSurfaceView v)
128 129
      {
130
      mInvisible = new boolean[CUBIT_MOVES.length];
129 131
      mResources = v.getResources();
130 132

  
131 133
      mScreen = new DistortedScreen();
......
149 151
      mAngleDyn.add( mAngle );
150 152

  
151 153
      mRotate = new VertexEffectRotate( mAngleDyn, mAxis, new Static3D(0,0,0) );
154
      mDisappear = new VertexEffectDisappear();
155
      mDisappear.setMeshAssociation(0,-1);
152 156

  
153 157
      mEffects = new DistortedEffects();
154 158
      mEffects.apply( mRotate );
159
      mEffects.apply( mDisappear );
155 160
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
156 161
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
157 162
      mEffects.apply( new MatrixEffectScale(mScale));
......
190 195
      mScreen.attach(mTexture,mEffects,mMesh);
191 196

  
192 197
      VertexEffectRotate.enable();
198
      VertexEffectDisappear.enable();
193 199

  
194 200
      DistortedLibrary.onSurfaceCreated(this);
195 201
      }
196 202

  
197 203
///////////////////////////////////////////////////////////////////////////////////////////////////
204
// rotation: LX 0, RX 1, LY 2, RY 3, LZ 4, RZ 5
198 205

  
199
    void apply(int andAssoc, int axisIndex)
206
    void apply(int rotation, int axisIndex)
200 207
      {
201
      mRotate.setMeshAssociation(andAssoc,-1);
208
      int andAssoc = 0;
202 209

  
210
      switch(rotation)
211
        {
212
        case 0: andAssoc=addAssociation(0,andAssoc);
213
                andAssoc=addAssociation(1,andAssoc);
214
                andAssoc=addAssociation(2,andAssoc);
215
                andAssoc=addAssociation(3,andAssoc);
216
                break;
217
        case 1: andAssoc=addAssociation(4,andAssoc);
218
                andAssoc=addAssociation(5,andAssoc);
219
                andAssoc=addAssociation(6,andAssoc);
220
                andAssoc=addAssociation(7,andAssoc);
221
                break;
222
        case 2: andAssoc=addAssociation(0,andAssoc);
223
                andAssoc=addAssociation(1,andAssoc);
224
                andAssoc=addAssociation(4,andAssoc);
225
                andAssoc=addAssociation(5,andAssoc);
226
                break;
227
        case 3: andAssoc=addAssociation(2,andAssoc);
228
                andAssoc=addAssociation(3,andAssoc);
229
                andAssoc=addAssociation(6,andAssoc);
230
                andAssoc=addAssociation(7,andAssoc);
231
                break;
232
        case 4: andAssoc=addAssociation(0,andAssoc);
233
                andAssoc=addAssociation(2,andAssoc);
234
                andAssoc=addAssociation(4,andAssoc);
235
                andAssoc=addAssociation(6,andAssoc);
236
                break;
237
        case 5: andAssoc=addAssociation(1,andAssoc);
238
                andAssoc=addAssociation(3,andAssoc);
239
                andAssoc=addAssociation(5,andAssoc);
240
                andAssoc=addAssociation(7,andAssoc);
241
                break;
242
        }
243

  
244
      mRotate.setMeshAssociation(andAssoc,-1);
203 245
      mAngle.set(360);
246
      mAxis.set(AXIS[axisIndex]);
247
      mAngleDyn.resetToBeginning();
248
      }
204 249

  
205
      mAxis.set0(AXIS[axisIndex].get0());
206
      mAxis.set1(AXIS[axisIndex].get1());
207
      mAxis.set2(AXIS[axisIndex].get2());
250
///////////////////////////////////////////////////////////////////////////////////////////////////
208 251

  
209
      mAngleDyn.resetToBeginning();
252
    void disappear(int cubit)
253
      {
254
      mInvisible[cubit] = !mInvisible[cubit];
255

  
256
      if( mInvisible[cubit] ) mDisappearAssociation = addAssociation(cubit,mDisappearAssociation);
257
      else                    mDisappearAssociation = remAssociation(cubit,mDisappearAssociation);
258

  
259
      mDisappear.setMeshAssociation(mDisappearAssociation,-1);
210 260
      }
211 261

  
262
///////////////////////////////////////////////////////////////////////////////////////////////////
263

  
264
    int addAssociation(int cubit, int assoc) { return (assoc |  (1<<cubit)); }
265
    int remAssociation(int cubit, int assoc) { return (assoc & ~(1<<cubit)); }
266

  
212 267
///////////////////////////////////////////////////////////////////////////////////////////////////
213 268

  
214 269
    private Bitmap createTexture()
......
244 299

  
245 300
     MeshBase createCubitMesh()
246 301
      {
247
      final int MESHES=6;
302
      final int MESHES= 6;
248 303
      int association = 1;
249 304
      MeshBase[] meshes = new MeshSquare[MESHES];
250 305
      meshes[0] = new MeshSquare(10,10);
......
345 400

  
346 401
      cubits[NUM_CUBITS-1] = createCubitMesh();   // NUM_CUBITS-1 (or anything non-zero!)
347 402

  
348
      for(int i=0; i<NUM_CUBITS-1; i++)
349
        {
350
        cubits[i] = cubits[NUM_CUBITS-1].copy(true);
351
        }
403
      for(int i=0; i<NUM_CUBITS-1; i++) cubits[i] = cubits[NUM_CUBITS-1].copy(true);
352 404

  
353 405
      for(int i=0; i<NUM_CUBITS; i++)
354 406
        {
......
357 409
        }
358 410

  
359 411
      MeshBase result = new MeshJoined(cubits);
360

  
361
      result.setEffectAssociation( 0, (1<<4) + (1<<2) + 1, 0);
362
      result.setEffectAssociation( 1, (1<<4) + (1<<2) + 2, 0);
363
      result.setEffectAssociation( 2, (1<<4) + (2<<2) + 1, 0);
364
      result.setEffectAssociation( 3, (1<<4) + (2<<2) + 2, 0);
365
      result.setEffectAssociation( 4, (2<<4) + (1<<2) + 1, 0);
366
      result.setEffectAssociation( 5, (2<<4) + (1<<2) + 2, 0);
367
      result.setEffectAssociation( 6, (2<<4) + (2<<2) + 1, 0);
368
      result.setEffectAssociation( 7, (2<<4) + (2<<2) + 2, 0);
412
      for(int i=0; i<CUBIT_MOVES.length; i++) result.setEffectAssociation( i, (1<<i), 0);
369 413

  
370 414
      return result;
371 415
      }
src/main/res/layout/singlemeshlayout.xml
60 60

  
61 61
    </LinearLayout>
62 62

  
63
    <LinearLayout
64
        android:orientation="horizontal"
65
        android:layout_width="match_parent"
66
        android:layout_height="wrap_content">
67

  
68
        <CheckBox
69
            android:id="@+id/singlemesh0"
70
            android:layout_width="wrap_content"
71
            android:layout_height="match_parent"
72
            android:layout_weight="1"
73
            android:checked="false"
74
            android:onClick="Disappear"
75
            android:text="1"
76
            android:textSize="12sp"/>
77
        <CheckBox
78
            android:id="@+id/singlemesh1"
79
            android:layout_width="wrap_content"
80
            android:layout_height="match_parent"
81
            android:layout_weight="1"
82
            android:checked="false"
83
            android:onClick="Disappear"
84
            android:text="2"
85
            android:textSize="12sp"/>
86
        <CheckBox
87
            android:id="@+id/singlemesh2"
88
            android:layout_width="wrap_content"
89
            android:layout_height="match_parent"
90
            android:layout_weight="1"
91
            android:checked="false"
92
            android:onClick="Disappear"
93
            android:text="3"
94
            android:textSize="12sp"/>
95
        <CheckBox
96
            android:id="@+id/singlemesh3"
97
            android:layout_width="wrap_content"
98
            android:layout_height="match_parent"
99
            android:layout_weight="1"
100
            android:checked="false"
101
            android:onClick="Disappear"
102
            android:text="4"
103
            android:textSize="12sp"/>
104
        <CheckBox
105
            android:id="@+id/singlemesh4"
106
            android:layout_width="wrap_content"
107
            android:layout_height="match_parent"
108
            android:layout_weight="1"
109
            android:checked="false"
110
            android:onClick="Disappear"
111
            android:text="5"
112
            android:textSize="12sp"/>
113
        <CheckBox
114
            android:id="@+id/singlemesh5"
115
            android:layout_width="wrap_content"
116
            android:layout_height="match_parent"
117
            android:layout_weight="1"
118
            android:checked="false"
119
            android:onClick="Disappear"
120
            android:text="6"
121
            android:textSize="12sp"/>
122
        <CheckBox
123
            android:id="@+id/singlemesh6"
124
            android:layout_width="wrap_content"
125
            android:layout_height="match_parent"
126
            android:layout_weight="1"
127
            android:checked="false"
128
            android:onClick="Disappear"
129
            android:text="7"
130
            android:textSize="12sp"/>
131
        <CheckBox
132
            android:id="@+id/singlemesh7"
133
            android:layout_width="wrap_content"
134
            android:layout_height="match_parent"
135
            android:layout_weight="1"
136
            android:checked="false"
137
            android:onClick="Disappear"
138
            android:text="8"
139
            android:textSize="12sp"/>
140

  
141
    </LinearLayout>
142

  
63 143
</LinearLayout>

Also available in: Unified diff