Project

General

Profile

« Previous | Next » 

Revision 64975793

Added by Leszek Koltunski almost 5 years ago

RubikCube: renamed RubikSettingsEnum to BaseEffect and moved it to the 'effect' package.

View differences:

src/main/java/org/distorted/effect/BaseEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import java.lang.reflect.Method;
23
import android.content.SharedPreferences;
24

  
25
import org.distorted.effect.scramble.ScrambleEffect;
26
import org.distorted.effect.sizechange.SizeChangeEffect;
27
import org.distorted.effect.solve.SolveEffect;
28
import org.distorted.magic.R;
29
import org.distorted.magic.RubikRenderer;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
public class BaseEffect
34
  {
35
  public enum Type
36
    {
37
    SIZECHANGE  ( 20, 1, R.string.sizechange_effect , SizeChangeEffect.class),
38
    SOLVE       ( 20, 1, R.string.solve_effect      , SolveEffect.class     ),
39
    SCRAMBLE    ( 20, 1, R.string.scramble_effect   , ScrambleEffect.class  ),
40
    ;
41

  
42
    private final int mDefaultPos, mDefaultType;
43
    private final Class mClass;
44
    private int mCurrentPos, mCurrentType;
45
    private int mText;
46

  
47
    Type(int dPos, int dType, int text, Class clazz )
48
      {
49
      mDefaultPos  = mCurrentPos = dPos;
50
      mDefaultType = mCurrentType= dType;
51
      mText        = text;
52
      mClass       = clazz;
53
      }
54

  
55
    public static final int LENGTH = Type.values().length;
56
    private static final Type[] types;  // copy the values() to a local variable so that we
57
                                        // don't have to keep recreating the array every time
58
    static
59
      {
60
      int i=0;
61

  
62
      types= new Type[LENGTH];
63

  
64
      for(Type type: Type.values())
65
        {
66
        types[i] = type;
67
        i++;
68
        }
69
      }
70

  
71
  ////////////////////////////////////////////////////////////////////////////////
72

  
73
    public int getText()
74
      {
75
      return mText;
76
      }
77

  
78
  ////////////////////////////////////////////////////////////////////////////////
79

  
80
    public int getCurrentPos()
81
      {
82
      return mCurrentPos;
83
      }
84

  
85
  ////////////////////////////////////////////////////////////////////////////////
86

  
87
    public int getCurrentType()
88
      {
89
      return mCurrentType;
90
      }
91

  
92
  ////////////////////////////////////////////////////////////////////////////////
93

  
94
    public void setCurrentPos(int pos)
95
      {
96
      mCurrentPos = pos;
97
      }
98

  
99
  ////////////////////////////////////////////////////////////////////////////////
100

  
101
    public void setCurrentType(int type)
102
      {
103
      mCurrentType = type;
104
      }
105

  
106
  ////////////////////////////////////////////////////////////////////////////////
107

  
108
    public void savePreferences(SharedPreferences.Editor editor)
109
      {
110
      String name = name();
111

  
112
      editor.putInt(name+"_Pos" , mCurrentPos );
113
      editor.putInt(name+"_Type", mCurrentType);
114
      }
115

  
116
  ////////////////////////////////////////////////////////////////////////////////
117

  
118
    public void restorePreferences(SharedPreferences preferences)
119
      {
120
      String name = name();
121

  
122
      mCurrentPos  = preferences.getInt(name+"_Pos" , mDefaultPos );
123
      mCurrentType = preferences.getInt(name+"_Type", mDefaultType);
124
      }
125

  
126
  ////////////////////////////////////////////////////////////////////////////////
127

  
128
    public String[] getNames()
129
      {
130
      Method method;
131

  
132
      try
133
        {
134
        method = mClass.getDeclaredMethod("getNames");
135
        }
136
      catch(NoSuchMethodException ex)
137
        {
138
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
139
        method = null;
140
        }
141

  
142
      try
143
        {
144
        if( method!=null )
145
          {
146
          Object value = method.invoke(null);
147
          return (String[]) value;
148
          }
149
        }
150
      catch(Exception ex)
151
        {
152
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
153
        }
154

  
155
      return null;
156
      }
157

  
158
  ////////////////////////////////////////////////////////////////////////////////
159

  
160
    public static Type getType(int ordinal)
161
      {
162
      return types[ordinal];
163
      }
164

  
165
  ////////////////////////////////////////////////////////////////////////////////
166

  
167
    public static void enableEffects()
168
      {
169
      Method method;
170

  
171
      for(Type type: values())
172
        {
173
        try
174
          {
175
          method = type.mClass.getDeclaredMethod("enableEffects");
176
          }
177
        catch(NoSuchMethodException ex)
178
          {
179
          android.util.Log.e("BaseEffect", type.mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
180
          method = null;
181
          }
182

  
183
        try
184
          {
185
          if( method!=null ) method.invoke(null);
186
          }
187
        catch(Exception ex)
188
          {
189
          android.util.Log.e("BaseEffect", type.mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
190
          }
191
        }
192
      }
193

  
194
  ////////////////////////////////////////////////////////////////////////////////
195

  
196
    public long startEffect(RubikRenderer renderer)
197
      {
198
      Method method1, method2;
199
      BaseEffect baseEffect=null;
200

  
201
      try
202
        {
203
        method1 = mClass.getDeclaredMethod("create", int.class);
204
        }
205
      catch(NoSuchMethodException ex)
206
        {
207
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": 1 exception getting method: "+ex.getMessage());
208
        return -1;
209
        }
210

  
211
      try
212
        {
213
        if( method1!=null )
214
          {
215
          Object value = method1.invoke(null,mCurrentType);
216
          baseEffect = (BaseEffect)value;
217
          }
218
        }
219
      catch(Exception ex)
220
        {
221
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": 1 exception invoking method: "+ex.getMessage());
222
        return -2;
223
        }
224

  
225
      try
226
        {
227
        method2 = mClass.getDeclaredMethod("start", int.class, RubikRenderer.class);
228
        }
229
      catch(NoSuchMethodException ex)
230
        {
231
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": 2 exception getting method: "+ex.getMessage());
232
        return -3;
233
        }
234

  
235
      try
236
        {
237
        if( method2!=null )
238
          {
239
          Integer translated = translatePos(mCurrentPos)+1;
240
          Object value = method2.invoke(baseEffect,translated,renderer);
241
          return (Long)value;
242
          }
243
        }
244
      catch(Exception ex)
245
        {
246
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": 2 exception invoking method: "+ex.getMessage());
247
        }
248

  
249
      return -4;
250
      }
251

  
252
  ////////////////////////////////////////////////////////////////////////////////
253

  
254
    public static int translatePos(int pos)
255
      {
256
      return (pos/2)*100;
257
      }
258
    }
259
  }
src/main/java/org/distorted/effect/ScrambleEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.main.DistortedEffects;
24
import org.distorted.library.message.EffectListener;
25
import org.distorted.magic.RubikCube;
26

  
27
import java.lang.reflect.Method;
28
import java.util.Random;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public abstract class ScrambleEffect implements EffectListener
33
{
34
  public enum Type
35
    {
36
    NONE         (ScrambleEffectNone.class        ),
37
    ROTATIONS    (ScrambleEffectRotations.class   ),
38
    ;
39

  
40
    final Class<? extends ScrambleEffect> effect;
41

  
42
    Type(Class<? extends ScrambleEffect> effect)
43
      {
44
      this.effect= effect;
45
      }
46
    }
47

  
48
  private static int NUM_EFFECTS = Type.values().length;
49
  private static final int FAKE_EFFECT_ID  = -3;
50
  private static final Type[] types;
51

  
52
  static
53
    {
54
    int i=0;
55
    types = new Type[NUM_EFFECTS];
56

  
57
    for(Type type: Type.values())
58
      {
59
      types[i++] = type;
60
      }
61
    }
62

  
63
  private EffectListener mListener;
64
  private int mEffectReturned;
65
  private long mCurrentBaseEffectID;
66
  private int mNumDoubleScramblesLeft, mNumScramblesLeft;
67
  private int mLastVector;
68
  private long mDurationSingleTurn;
69
  private Random mRnd;
70
  private RubikCube mCube;
71

  
72
  Effect[] mNodeEffects;
73
  int[] mNodeEffectPosition;
74
  Effect[] mCubeEffects;
75
  int[] mCubeEffectPosition;
76
  int mCubeEffectNumber, mNodeEffectNumber;
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  ScrambleEffect()
81
    {
82
    mRnd = new Random( System.currentTimeMillis() );
83
    mLastVector = -1;
84
    }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
  public static String[] getNames()
89
    {
90
    String[] names = new String[NUM_EFFECTS];
91

  
92
    for( int i=0; i<NUM_EFFECTS; i++)
93
      {
94
      names[i] = types[i].name();
95
      }
96

  
97
    return names;
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  public static ScrambleEffect create(int ordinal) throws InstantiationException, IllegalAccessException
103
    {
104
    return types[ordinal].effect.newInstance();
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
  abstract void createEffects(int duration);
110
  abstract void effectFinishedPlugin(final long effectID);
111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
  private void createBaseEffects(int duration, int numScrambles)
115
    {
116
    mNumScramblesLeft = numScrambles;
117

  
118
    // compute how many out of 'numScrambles' are double turns.
119
    mNumDoubleScramblesLeft=0;
120

  
121
    for(int i=0; i<numScrambles; i++)
122
      {
123
      if( (mRnd.nextInt() % 3) == 0 )
124
        {
125
        mNumDoubleScramblesLeft++;
126
        }
127
      }
128

  
129
    mDurationSingleTurn = duration/(mNumScramblesLeft+mNumDoubleScramblesLeft);
130

  
131
    addNewScramble();
132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  private void addNewScramble()
137
    {
138
    if( mNumScramblesLeft>0 )
139
      {
140
      if( mLastVector == -1 )
141
        {
142
        switch(mRnd.nextInt(3))
143
          {
144
          case 0: mLastVector = RubikCube.VECTX; break;
145
          case 1: mLastVector = RubikCube.VECTY; break;
146
          case 2: mLastVector = RubikCube.VECTZ; break;
147
          }
148
        }
149
      else
150
        {
151
        int newVector = mRnd.nextInt(2);
152

  
153
        switch(mLastVector)
154
          {
155
          case RubikCube.VECTX: mLastVector = (newVector==0 ? RubikCube.VECTY: RubikCube.VECTZ); break;
156
          case RubikCube.VECTY: mLastVector = (newVector==0 ? RubikCube.VECTX: RubikCube.VECTZ); break;
157
          case RubikCube.VECTZ: mLastVector = (newVector==0 ? RubikCube.VECTX: RubikCube.VECTY); break;
158
          }
159
        }
160

  
161
      int row  = mRnd.nextInt(mCube.getSize());
162
      int angle= randomizeAngle();
163
      int absAngle = (angle<0 ? -angle : angle);
164
      long durationMillis =  absAngle*mDurationSingleTurn;
165

  
166
      mNumScramblesLeft--;
167
      if( absAngle==2 ) mNumDoubleScramblesLeft--;
168

  
169
      if( mNumScramblesLeft==0 && mNumDoubleScramblesLeft!=0 )
170
        {
171
        android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft);
172
        }
173

  
174
      mCurrentBaseEffectID = mCube.addNewRotation(mLastVector, row, angle*90, durationMillis, this );
175
      }
176
    else
177
      {
178
      mLastVector = -1;
179

  
180
      if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
181
        {
182
        mListener.effectFinished(FAKE_EFFECT_ID);
183
        }
184
      }
185
    }
186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

  
189
  private int randomizeAngle()
190
    {
191
    int random = mRnd.nextInt(mNumScramblesLeft);
192
    int result = random<mNumDoubleScramblesLeft ? 2:1;
193
    int sign   = mRnd.nextInt(2);
194

  
195
    return sign==0 ? result : -result;
196
    }
197

  
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

  
200
  public void effectFinished(final long effectID)
201
    {
202
    if( effectID == mCurrentBaseEffectID )
203
      {
204
      mCube.removeRotationNow();
205
      addNewScramble();
206
      return;
207
      }
208

  
209
    for(int i=0; i<mCubeEffectNumber; i++)
210
      {
211
      long id = mCubeEffects[i].getID();
212

  
213
      if( effectID == id )
214
        {
215
        mEffectReturned++;
216
        effectFinishedPlugin(effectID);
217

  
218
        if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
219
          {
220
          disassignEffects();
221

  
222
          if( mNumScramblesLeft==0 )
223
            {
224
            mListener.effectFinished(FAKE_EFFECT_ID);
225
            }
226
          }
227

  
228
        return;
229
        }
230
      }
231

  
232
    for(int i=0; i<mNodeEffectNumber; i++)
233
      {
234
      long id = mNodeEffects[i].getID();
235

  
236
      if( effectID == id )
237
        {
238
        mEffectReturned++;
239
        effectFinishedPlugin(effectID);
240

  
241
        if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
242
          {
243
          disassignEffects();
244

  
245
          if( mNumScramblesLeft==0 )
246
            {
247
            mListener.effectFinished(FAKE_EFFECT_ID);
248
            }
249
          }
250

  
251
        return;
252
        }
253
      }
254
    }
255

  
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
  public long start(int duration, RubikCube cube, int numScrambles, EffectListener listener)
259
    {
260
    mCube     = cube;
261
    mListener = listener;
262

  
263
    createBaseEffects(duration, numScrambles);
264
    createEffects(duration);
265

  
266
    if( mCubeEffectNumber==0 && mNodeEffectNumber==0 )
267
      {
268
      throw new RuntimeException("Cube and Node Plugin Effects not created!");
269
      }
270

  
271
    assignEffects();
272

  
273
    return FAKE_EFFECT_ID;
274
    }
275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
  private void assignEffects()
279
    {
280
    for(int i=0; i<mCubeEffectNumber; i++)
281
      {
282
      mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]);
283
      mCubeEffects[i].notifyWhenFinished(this);
284
      }
285

  
286
    DistortedEffects nodeEffects = mCube.getEffects();
287

  
288
    for(int i=0; i<mNodeEffectNumber; i++)
289
      {
290
      nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]);
291
      mNodeEffects[i].notifyWhenFinished(this);
292
      }
293
    }
294

  
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

  
297
  private void disassignEffects()
298
    {
299
    for(int i=0; i<mCubeEffectNumber; i++)
300
      {
301
      mCube.remove(mCubeEffects[i].getID());
302
      }
303

  
304
    DistortedEffects nodeEffects = mCube.getEffects();
305

  
306
    for(int i=0; i<mNodeEffectNumber; i++)
307
      {
308
      nodeEffects.abortById(mNodeEffects[i].getID());
309
      }
310
    }
311

  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
314
  @SuppressWarnings("unused")
315
  public static void enableEffects()
316
    {
317
    Method method;
318

  
319
    for(Type type: Type.values())
320
      {
321
      try
322
        {
323
        method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod
324
        }
325
      catch(NoSuchMethodException ex)
326
        {
327
        android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
328
        method = null;
329
        }
330

  
331
      try
332
        {
333
        if( method!=null ) method.invoke(null);
334
        }
335
      catch(Exception ex)
336
        {
337
        android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
338
        }
339
      }
340
    }
341
}
src/main/java/org/distorted/effect/ScrambleEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
import org.distorted.library.effect.Effect;
25
import org.distorted.library.effect.MatrixEffectMove;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Static3D;
28

  
29
public class ScrambleEffectNone extends ScrambleEffect
30
  {
31
  public void createEffects(int duration)
32
    {
33
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
34
    d0.add(new Static3D(0,0,0));
35

  
36
    mCubeEffectNumber   = 1;
37
    mNodeEffectNumber   = 0;
38

  
39
    mCubeEffectPosition = new int[] {-1};
40
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
41
    mCubeEffects[0]     = new MatrixEffectMove(d0);
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  public void effectFinishedPlugin(final long effectID)
47
    {
48

  
49
    }
50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// Enable all effects used in this Effect. Called by reflection from the parent class.
53

  
54
  @SuppressWarnings("unused")
55
  static void enable()
56
    {
57

  
58
    }
59
  }
src/main/java/org/distorted/effect/ScrambleEffectRotations.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.effect.MatrixEffectQuaternion;
25
import org.distorted.library.type.Dynamic;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.DynamicQuat;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static4D;
30

  
31
import java.util.Random;
32

  
33
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE;
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
public class ScrambleEffectRotations extends ScrambleEffect
38
  {
39
  private Random mRnd = new Random(0);
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
  public void createEffects(int duration)
44
    {
45
    mCubeEffectNumber   = 2;
46
    mNodeEffectNumber   = 0;
47
    mCubeEffectPosition = new int[] {6,7};
48
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
49

  
50
    mRnd.setSeed(System.currentTimeMillis());
51

  
52
    DynamicQuat dq = new DynamicQuat(duration, 0.5f);
53
    dq.setMode(Dynamic.MODE_PATH);
54
    dq.add(new Static4D(0,0,0,1));
55
    dq.add(generateNewRandomPoint());
56
    dq.add(generateNewRandomPoint());
57
    dq.add(generateNewRandomPoint());
58
    dq.add(new Static4D(0,0,0,1));
59

  
60
    mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
61

  
62
    float Z = TEXTURE_SIZE/3;
63

  
64
    Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
65
    d0.setMode(Dynamic.MODE_PATH);
66
    d0.add(new Static3D( 0, 0, 0));
67
    d0.add(new Static3D( 0, 0,-Z));
68
    d0.add(new Static3D( 0, 0, 0));
69
    mCubeEffects[1] = new MatrixEffectMove(d0);
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  private Static4D generateNewRandomPoint()
75
    {
76
    float x = mRnd.nextFloat();
77
    float y = mRnd.nextFloat();
78
    float z = mRnd.nextFloat();
79
    float w = mRnd.nextFloat();
80

  
81
    float len = (float)Math.sqrt(x*x + y*y + z*z + w*w);
82

  
83
    return new Static4D( x/len, y/len, z/len, w/len);
84
    }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
  public void effectFinishedPlugin(final long effectID)
89
    {
90

  
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
// Enable all effects used in this Effect. Called by reflection from the parent class.
95

  
96
  @SuppressWarnings("unused")
97
  static void enable()
98
    {
99

  
100
    }
101
  }
src/main/java/org/distorted/effect/SizeChangeEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
import org.distorted.library.effect.Effect;
25
import org.distorted.library.main.DistortedEffects;
26
import org.distorted.library.main.DistortedScreen;
27
import org.distorted.library.message.EffectListener;
28
import org.distorted.magic.RubikCube;
29

  
30
import java.lang.reflect.Method;
31

  
32
public abstract class SizeChangeEffect implements EffectListener
33
{
34
  public enum Type
35
    {
36
    NONE         (SizeChangeEffectNone.class        ),
37
    TRANSPARENCY (SizeChangeEffectTransparency.class),
38
    MOVE         (SizeChangeEffectMove.class        ),
39
    ROUND        (SizeChangeEffectRound.class       ),
40
    SCALE        (SizeChangeEffectScale.class       ),
41
    ;
42

  
43
    final Class<? extends SizeChangeEffect> effect;
44

  
45
    Type(Class<? extends SizeChangeEffect> effect)
46
      {
47
      this.effect= effect;
48
      }
49
    }
50

  
51
  private static int NUM_EFFECTS = Type.values().length;
52
  private static final int NUM_PHASES  = 2;
53
  private static final int FAKE_EFFECT_ID  = -1;
54
  private static final Type[] types;
55

  
56
  static
57
    {
58
    int i=0;
59
    types = new Type[NUM_EFFECTS];
60

  
61
    for(Type type: Type.values())
62
      {
63
      types[i++] = type;
64
      }
65
    }
66

  
67
  private EffectListener mListener;
68
  private int mDuration;
69
  private int[] mEffectReturned;
70
  private int[] mCubeEffectNumber, mNodeEffectNumber;
71
  private int[] mEffectFinished;
72
  private boolean[] mPhaseActive;
73
  private RubikCube[] mCube;
74

  
75
  DistortedScreen mScreen;
76
  Effect[][] mCubeEffects;
77
  int[][] mCubeEffectPosition;
78
  Effect[][] mNodeEffects;
79
  int[][] mNodeEffectPosition;
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  SizeChangeEffect()
84
    {
85
    mPhaseActive        = new boolean[NUM_PHASES];
86
    mEffectReturned     = new int[NUM_PHASES];
87
    mCubeEffectNumber   = new int[NUM_PHASES];
88
    mNodeEffectNumber   = new int[NUM_PHASES];
89
    mEffectFinished     = new int[NUM_PHASES];
90
    mCubeEffectPosition = new int[NUM_PHASES][];
91
    mNodeEffectPosition = new int[NUM_PHASES][];
92
    mCubeEffects        = new Effect[NUM_PHASES][];
93
    mNodeEffects        = new Effect[NUM_PHASES][];
94
    mCube               = new RubikCube[NUM_PHASES];
95
    }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

  
99
  public static String[] getNames()
100
    {
101
    String[] names = new String[NUM_EFFECTS];
102

  
103
    for( int i=0; i<NUM_EFFECTS; i++)
104
      {
105
      names[i] = types[i].name();
106
      }
107

  
108
    return names;
109
    }
110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
  public static SizeChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException
114
    {
115
    return types[ordinal].effect.newInstance();
116
    }
117

  
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

  
120
  abstract int createEffectsPhase0(int duration);
121
  abstract int createEffectsPhase1(int duration);
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  public void effectFinished(final long effectID)
126
    {
127
    if( mPhaseActive[0] ) effectFinishedPhase(effectID,0);
128
    if( mPhaseActive[1] ) effectFinishedPhase(effectID,1);
129
    }
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
  private void effectFinishedPhase(final long effectID, int phase)
134
    {
135
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
136
      {
137
      long id = mCubeEffects[phase][i].getID();
138

  
139
      if( effectID == id )
140
        {
141
        effectReturned(phase);
142
        mCube[phase].remove(id);
143
        return;
144
        }
145
      }
146
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
147
      {
148
      long id = mNodeEffects[phase][i].getID();
149

  
150
      if( effectID == id )
151
        {
152
        effectReturned(phase);
153
        mCube[phase].getEffects().abortById(id);
154
        return;
155
        }
156
      }
157
    }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
  private void effectReturned(int phase)
162
    {
163
    mEffectReturned[phase]++;
164

  
165
    if( mEffectReturned[phase] == mEffectFinished[phase] )
166
      {
167
      switch(phase)
168
        {
169
        case 0: mPhaseActive[1] = true;
170
                mEffectFinished[1] = createEffectsPhase1(mDuration);
171
                assignEffects(1);
172
                mScreen.attach(mCube[1]);
173
                break;
174
        case 1: mListener.effectFinished(FAKE_EFFECT_ID);
175
                break;
176
        }
177
      }
178
    if( mEffectReturned[phase] == mCubeEffectNumber[phase]+mNodeEffectNumber[phase] )
179
      {
180
      switch(phase)
181
        {
182
        case 0: mPhaseActive[0] = false;
183
                mScreen.detach(mCube[0]);
184
                break;
185
        case 1: mPhaseActive[1] = false;
186
                break;
187
        }
188
      }
189
    }
190

  
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193
  public long start(int duration, DistortedScreen screen, RubikCube oldcube, RubikCube newcube, EffectListener listener)
194
    {
195
    mScreen   = screen;
196
    mCube[0]  = oldcube;
197
    mCube[1]  = newcube;
198
    mListener = listener;
199
    mDuration = duration;
200

  
201
    if( oldcube!=null )
202
      {
203
      mPhaseActive[0] = true;
204
      mEffectFinished[0] = createEffectsPhase0(mDuration);
205
      assignEffects(0);
206
      }
207
    else
208
      {
209
      mPhaseActive[1] = true;
210
      mEffectFinished[1] = createEffectsPhase1(mDuration);
211
      assignEffects(1);
212
      mScreen.attach(mCube[1]);
213
      }
214

  
215
    return FAKE_EFFECT_ID;
216
    }
217

  
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

  
220
  private void assignEffects(int phase)
221
    {
222
    mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
223
    mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
224

  
225
    if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
226
      {
227
      throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
228
      }
229

  
230
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
231
      {
232
      mCube[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
233
      mCubeEffects[phase][i].notifyWhenFinished(this);
234
      }
235

  
236
    DistortedEffects nodeEffects = mCube[phase].getEffects();
237

  
238
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
239
      {
240
      nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
241
      mNodeEffects[phase][i].notifyWhenFinished(this);
242
      }
243
    }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
  public static void enableEffects()
248
    {
249
    Method method;
250

  
251
    for(Type type: Type.values())
252
      {
253
      try
254
        {
255
        method = type.effect.getDeclaredMethod("enable");  // enable not public, thus getDeclaredMethod
256
        }
257
      catch(NoSuchMethodException ex)
258
        {
259
        android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
260
        method = null;
261
        }
262

  
263
      try
264
        {
265
        if( method!=null ) method.invoke(null);
266
        }
267
      catch(Exception ex)
268
        {
269
        android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
270
        }
271
      }
272
    }
273
}
src/main/java/org/distorted/effect/SizeChangeEffectMove.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class SizeChangeEffectMove extends SizeChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    int w = mScreen.getWidth();
34
    int h = mScreen.getHeight();
35
    int xmove = w/2 + (w<h?w:h)/2;
36

  
37
    mNodeEffectPosition[0] = new int[] {1};
38
    mNodeEffects[0]        = new Effect[mNodeEffectPosition[0].length];
39

  
40
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
41
    d0.add(new Static3D(    0,0,0));
42
    d0.add(new Static3D(xmove,0,0));
43
    mNodeEffects[0][0] = new MatrixEffectMove(d0);
44

  
45
    return 1;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  public int createEffectsPhase1(int duration)
51
    {
52
    int w = mScreen.getWidth();
53
    int h = mScreen.getHeight();
54
    int xmove = w/2 + (w<h?w:h)/2;
55

  
56
    mNodeEffectPosition[1] = new int[] {1};
57
    mNodeEffects[1]        = new Effect[mNodeEffectPosition[1].length];
58

  
59
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
60
    d0.add(new Static3D(-xmove,0,0));
61
    d0.add(new Static3D(     0,0,0));
62
    mNodeEffects[1][0] = new MatrixEffectMove(d0);
63

  
64
    return 1;
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
// Enable all effects used in this Effect. Called by reflection from the parent class.
69
// Matrix Effects do not have to be enabled.
70

  
71
  @SuppressWarnings("unused")
72
  static void enable()
73
    {
74

  
75
    }
76
  }
77

  
src/main/java/org/distorted/effect/SizeChangeEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class SizeChangeEffectNone extends SizeChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    mCubeEffectPosition[0] = new int[] {-1};
34
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
35

  
36
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
37
    d0.add(new Static3D(0,0,0));
38
    mCubeEffects[0][0] = new MatrixEffectMove(d0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  public int createEffectsPhase1(int duration)
46
    {
47
    mCubeEffectPosition[1] = new int[] {-1};
48
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
49

  
50
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
51
    d0.add(new Static3D(0,0,0));
52
    mCubeEffects[1][0] = new MatrixEffectMove(d0);
53

  
54
    return 1;
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// enable all effects used in this Effect (here: none).  Called by reflection from the parent class.
59

  
60
  @SuppressWarnings("unused")
61
  static void enable()
62
    {
63

  
64
    }
65
  }
src/main/java/org/distorted/effect/SizeChangeEffectRound.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.effect.MatrixEffectScale;
25
import org.distorted.library.type.Dynamic;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Static3D;
28

  
29
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
class SizeChangeEffectRound extends SizeChangeEffect
34
  {
35
  public int createEffectsPhase0(int duration)
36
    {
37
    float X = TEXTURE_SIZE/3;
38

  
39
    mCubeEffectPosition[0] = new int[] {6,7};
40
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
41

  
42
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
43
    d0.add(new Static3D( 1.00f, 1.00f, 1.00f));
44
    d0.add(new Static3D( 0.01f, 0.01f, 0.01f));
45
    mCubeEffects[0][0] = new MatrixEffectScale(d0);
46

  
47
    Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f);
48
    d1.setMode(Dynamic.MODE_PATH);
49
    d1.add(new Static3D( 0, 0, 0));
50
    d1.add(new Static3D(+X, 0, 0));
51
    d1.add(new Static3D( 0, 0, 0));
52
    mCubeEffects[0][1] = new MatrixEffectMove(d1);
53

  
54
    return 2;
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
  public int createEffectsPhase1(int duration)
60
    {
61
    float X = TEXTURE_SIZE/3;
62

  
63
    mCubeEffectPosition[1] = new int[] {6,7};
64
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
65

  
66
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
67
    d0.add(new Static3D( 0.01f, 0.01f, 0.01f));
68
    d0.add(new Static3D( 1.00f, 1.00f, 1.00f));
69
    mCubeEffects[1][0] = new MatrixEffectScale(d0);
70

  
71
    Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f);
72
    d1.setMode(Dynamic.MODE_PATH);
73
    d1.add(new Static3D( 0, 0, 0));
74
    d1.add(new Static3D(-X, 0, 0));
75
    d1.add(new Static3D( 0, 0, 0));
76
    mCubeEffects[1][1] = new MatrixEffectMove(d1);
77

  
78
    return 2;
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// Enable all effects used in this Effect. Called by reflection from the parent class.
83
// Matrix Effects do not have to be enabled.
84

  
85
  @SuppressWarnings("unused")
86
  static void enable()
87
    {
88

  
89
    }
90
  }
91

  
src/main/java/org/distorted/effect/SizeChangeEffectScale.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectScale;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class SizeChangeEffectScale extends SizeChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    mCubeEffectPosition[0] = new int[] {6};
34
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
35

  
36
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
37
    d0.add(new Static3D(1.00f, 1.00f, 1.00f));
38
    d0.add(new Static3D(0.01f, 0.01f, 0.01f));
39
    mCubeEffects[0][0] = new MatrixEffectScale(d0);
40

  
41
    return 1;
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  public int createEffectsPhase1(int duration)
47
    {
48
    mCubeEffectPosition[1] = new int[] {6};
49
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
50

  
51
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
52
    d0.add(new Static3D(0.01f, 0.01f, 0.01f));
53
    d0.add(new Static3D(1.00f, 1.00f, 1.00f));
54
    mCubeEffects[1][0] = new MatrixEffectScale(d0);
55

  
56
    return 1;
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// Enable all effects used in this Effect. Called by reflection from the parent class.
61
// Matrix Effects do not have to be enabled.
62

  
63
  @SuppressWarnings("unused")
64
  static void enable()
65
    {
66

  
67
    }
68
  }
69

  
src/main/java/org/distorted/effect/SizeChangeEffectTransparency.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.FragmentEffectAlpha;
24
import org.distorted.library.effect.VertexEffectWave;
25
import org.distorted.library.type.Dynamic1D;
26
import org.distorted.library.type.Dynamic5D;
27
import org.distorted.library.type.Static1D;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static5D;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
class SizeChangeEffectTransparency extends SizeChangeEffect
34
  {
35
  public int createEffectsPhase0(int duration)
36
    {
37
    mCubeEffectPosition[0] = new int[] {-1};
38
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
39

  
40
    Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f);
41
    d0.add(new Static1D(1.0f));
42
    d0.add(new Static1D(0.0f));
43
    mCubeEffects[0][0] = new FragmentEffectAlpha(d0);
44

  
45
    mNodeEffectPosition[0] = new int[] {-1};
46
    mNodeEffects[0]        = new Effect[mNodeEffectPosition[0].length];
47

  
48
    int w = mScreen.getWidth();
49
    int h = mScreen.getHeight();
50
    int min = w<h ? w:h;
51

  
52
    float init_amplitude = 0.0f;
53
    float end_amplitude  = min/15.0f;
54
    float length         = min/15.0f;
55
    float init_phase     = 360.0f;
56
    float end_phase      = 0.0f;
57
    float alpha          = 30.0f;
58
    float beta           = 90.0f;
59

  
60
    Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f);
61
    d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) );
62
    d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) );
63
    Static3D center = new Static3D(min*0.5f,min*0.5f,0);
64
    mNodeEffects[0][0] = new VertexEffectWave(d1, center, null);
65

  
66
    return 2;
67
    }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
  public int createEffectsPhase1(int duration)
72
    {
73
    mCubeEffectPosition[1] = new int[] {-1};
74
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
75

  
76
    Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f);
77
    d0.add(new Static1D(0.0f));
78
    d0.add(new Static1D(1.0f));
79
    mCubeEffects[1][0] = new FragmentEffectAlpha(d0);
80

  
81
    mNodeEffectPosition[1] = new int[] {-1};
82
    mNodeEffects[1]        = new Effect[mNodeEffectPosition[1].length];
83

  
84
    int w = mScreen.getWidth();
85
    int h = mScreen.getHeight();
86
    int min = w<h ? w:h;
87

  
88
    float init_amplitude = min/15.0f;
89
    float end_amplitude  = 0.0f;
90
    float length         = min/15.0f;
91
    float init_phase     = 0.0f;
92
    float end_phase      = 360.0f;
93
    float alpha          = 30.0f;
94
    float beta           = 90.0f;
95

  
96
    Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f);
97
    d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) );
98
    d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) );
99
    Static3D center = new Static3D(min*0.5f,min*0.5f,0);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff