Project

General

Profile

« Previous | Next » 

Revision 8feb68c2

Added by Leszek Koltunski about 2 years ago

Progress with Win effect + stars

View differences:

src/main/java/org/distorted/objects/RubikObjectList.java
151 151

  
152 152
  public static int computeNumStars(int level)
153 153
    {
154
    return level>=LEVELS_SHOWN ? 50 : level+1;
154
    return level>=LEVELS_SHOWN ? 50 : level;
155 155
    }
156 156

  
157 157
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/overlays/OverlayStars.java
12 12
import android.content.res.Resources;
13 13
import android.graphics.Bitmap;
14 14
import android.graphics.BitmapFactory;
15
import android.graphics.Canvas;
16
import android.graphics.Paint;
15 17

  
18
import org.distorted.library.effect.EffectQuality;
19
import org.distorted.library.effect.MatrixEffectMove;
20
import org.distorted.library.effect.MatrixEffectScale;
21
import org.distorted.library.effect.PostprocessEffectGlow;
16 22
import org.distorted.library.effect.VertexEffectMove;
17
import org.distorted.library.effect.VertexEffectRotate;
18 23
import org.distorted.library.effect.VertexEffectScale;
19 24
import org.distorted.library.main.DistortedEffects;
20 25
import org.distorted.library.main.DistortedNode;
......
24 29
import org.distorted.library.mesh.MeshJoined;
25 30
import org.distorted.library.mesh.MeshQuad;
26 31
import org.distorted.library.message.EffectListener;
27
import org.distorted.library.type.Dynamic1D;
32
import org.distorted.library.type.Dynamic;
33
import org.distorted.library.type.Dynamic2D;
28 34
import org.distorted.library.type.Dynamic3D;
29
import org.distorted.library.type.Static1D;
35
import org.distorted.library.type.Dynamic4D;
36
import org.distorted.library.type.Static2D;
30 37
import org.distorted.library.type.Static3D;
38
import org.distorted.library.type.Static4D;
31 39
import org.distorted.main.R;
32 40

  
33 41
import java.util.Random;
......
36 44

  
37 45
public class OverlayStars extends OverlayGeneric implements EffectListener
38 46
{
39
   private static final int DUR_ALL = 10000;
40
   private static final int DUR_MOV =  5000;
47
   private static final int DUR_MOV =  4000;
48
   private static final int DUR_GLO =  2000;
49

  
50
   private static final int[] colors = new int[] {0,0,1,  1,0,1,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, pink, red, yellow, green, white
51
   private static final int INDEX = 5;
41 52

  
42 53
   private ListenerOverlay mListener;
43
   private DistortedNode mNode;
54
   private DistortedNode mStarsNode, mCountNode;
44 55
   private DistortedScreen mScreen;
45
   private final Static3D mPointE = new Static3D(0,0,2);
56
   private DistortedTexture mStarsTexture, mCountTexture;
57
   private Bitmap mCountBitmap;
58
   private Canvas mCountCanvas;
59
   private Paint mPaint;
60
   private int mBmpW, mBmpH;
46 61
   private float mWidth, mHeight;
47 62
   private Random mRandom;
63
   private long mMoveID, mGlowID;
64
   private int mTotalStars, mNewStars;
48 65

  
49 66
///////////////////////////////////////////////////////////////////////////////////////////////////
50 67

  
51 68
   private Dynamic3D createRandomMove()
52 69
      {
53 70
      Dynamic3D move = new Dynamic3D();
71
      move.setMode(Dynamic.MODE_PATH);
54 72
      move.setDuration(DUR_MOV);
55 73
      move.setCount(0.5f);
56 74

  
57
      float widthS = (mRandom.nextFloat()-0.5f)*mWidth;
75
      float widthS = (mRandom.nextFloat()-0.5f)*mWidth*1.10f;
58 76
      float widthM = widthS + (mRandom.nextFloat()-0.5f)*mWidth*0.2f;
77
      float heighS = mRandom.nextFloat()*mHeight*0.2f;
78
      float heighM = (mRandom.nextFloat()-0.5f)*mHeight*0.2f;
59 79

  
60
      Static3D pointS = new Static3D(widthS,mHeight/2,2);
61
      Static3D pointM = new Static3D(widthM,mHeight/4,2);
80
      Static3D pointS = new Static3D(widthS,mHeight*0.55f+heighS,0);
81
      Static3D pointM = new Static3D(widthM,mHeight*0.25f+heighM,0);
82
      Static3D pointE = new Static3D(0,0,0);
62 83

  
63 84
      move.add(pointS);
64 85
      move.add(pointM);
65
      move.add(mPointE);
86
      move.add(pointE);
66 87

  
67 88
      return move;
68 89
      }
69 90

  
70 91
///////////////////////////////////////////////////////////////////////////////////////////////////
71 92

  
72
   private DistortedNode createNode(Resources res, int totS, int newS)
93
   private DistortedNode createStarsNode(Resources res)
73 94
      {
74 95
      // texture /////////////////////////////////////////////////////
75
      Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.star);
76
      DistortedTexture texture = new DistortedTexture();
77
      texture.setTexture(bmp);
96
      if( mStarsTexture==null )
97
         {
98
         mStarsTexture = new DistortedTexture();
99
         Bitmap star = BitmapFactory.decodeResource(res, R.drawable.star);
100
         mBmpW = star.getWidth();
101
         mBmpH = star.getHeight();
102
         mStarsTexture.setTexture(star);
103
         }
78 104

  
79 105
      // mesh ////////////////////////////////////////////////////////
106
      MeshQuad[] mesh = new MeshQuad[mNewStars+1];
80 107

  
81
      MeshQuad[] mesh = new MeshQuad[newS+1];
82

  
83
      for(int i=0; i<newS+1; i++)
108
      for(int i=0; i<mNewStars+1; i++)
84 109
         {
85 110
         mesh[i] = new MeshQuad();
86
         mesh[i].setEffectAssociation(0,(i==0?0:1),i);
111
         mesh[i].setEffectAssociation(0,(i>=mNewStars?2:1),i);
87 112
         }
88 113

  
89 114
      MeshJoined wholeMesh = new MeshJoined(mesh);
......
91 116
      // effects: main ///////////////////////////////////////////////
92 117
      DistortedEffects effects = new DistortedEffects();
93 118

  
94
      float scaleM = mWidth*0.3f;
95
      float scaleP = mWidth*0.1f;
96

  
97
      Static3D moveM    = new Static3D(0,0,1);
98
      Static1D point0   = new Static1D(0);
99
      Static1D point360 = new Static1D(360);
100
      Dynamic1D angle   = new Dynamic1D();
101
      angle.add(point0);
102
      angle.add(point360);
103
      angle.setCount(0.5f);
104
      angle.setDuration(DUR_ALL);
105
      Static3D axis = new Static3D(0,0,1);
106
      Static3D center = new Static3D(0,0,0);
119
      float scaleM  = mWidth*0.40f;
120
      float scaleP  = mWidth*0.15f;
121
      Static3D moveM= new Static3D(0,0,1);
107 122

  
108 123
      VertexEffectMove mainMove     = new VertexEffectMove(moveM);
109 124
      VertexEffectScale mainScale   = new VertexEffectScale(scaleM);
110
      VertexEffectRotate mainRotate = new VertexEffectRotate(angle,axis,center);
111
      mainMove.setMeshAssociation(2,0);
112
      mainScale.setMeshAssociation(2,0);
113
      mainRotate.setMeshAssociation(2,0);
114
      mainRotate.notifyWhenFinished(this);
125
      mainMove.setMeshAssociation(2,-1);
126
      mainScale.setMeshAssociation(2,-1);
115 127

  
116 128
      // effects: moving stars ///////////////////////////////////////
117 129
      VertexEffectScale scaleE = new VertexEffectScale(scaleP);
118 130
      scaleE.setMeshAssociation(1,-1);
119 131
      effects.apply(scaleE);
120 132

  
121
      for(int i=1; i<newS+1; i++)
133
      for(int i=0; i<mNewStars; i++)
122 134
        {
123 135
        Dynamic3D moveP = createRandomMove();
124 136
        VertexEffectMove moveE= new VertexEffectMove(moveP);
125
        moveE.setMeshAssociation(2,i);
137
        moveE.setMeshAssociation(0,i);
126 138
        effects.apply(moveE);
139

  
140
        if( i==0 )
141
           {
142
           mMoveID = moveE.getID();
143
           moveE.notifyWhenFinished(this);
144
           }
127 145
        }
128 146

  
129 147
      // main effect queue ///////////////////////////////////////////
130 148
      effects.apply(mainMove);
131 149
      effects.apply(mainScale);
132
      effects.apply(mainRotate);
133 150

  
134
      return new DistortedNode(texture,effects,wholeMesh);
151
      return new DistortedNode(mStarsTexture,effects,wholeMesh);
152
      }
153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

  
156
   private void renderStars(int numStars)
157
      {
158
      String txt = ""+numStars;
159
      mCountCanvas.drawText(txt,mBmpW*0.5f,mBmpH*0.64f,mPaint);
160
      mCountTexture.setTexture(mCountBitmap);
161
      }
162

  
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

  
165
   private DistortedNode createCountNode()
166
      {
167
      // texture /////////////////////////////////////////////////////
168
      if( mCountTexture==null )
169
         {
170
         mCountTexture = new DistortedTexture();
171

  
172
         mCountBitmap = Bitmap.createBitmap(mBmpW,mBmpH,Bitmap.Config.ARGB_8888);
173
         mCountCanvas = new Canvas(mCountBitmap);
174
         mPaint = new Paint();
175
         mPaint.setColor(0xff000000);
176
         mPaint.setTextSize(mBmpH*0.28f);
177
         mPaint.setAntiAlias(true);
178
         mPaint.setTextAlign(Paint.Align.CENTER);
179
         renderStars(mTotalStars);
180
         }
181

  
182
      // mesh ////////////////////////////////////////////////////////
183
      MeshQuad mesh = new MeshQuad();
184

  
185
      // effects: main ///////////////////////////////////////////////
186
      DistortedEffects effects = new DistortedEffects();
187

  
188
      float scaleM  = mWidth*0.40f;
189
      Static3D moveM= new Static3D(0,0,1);
190

  
191
      MatrixEffectMove mainMove  = new MatrixEffectMove(moveM);
192
      MatrixEffectScale mainScale= new MatrixEffectScale(scaleM);
193

  
194
      // main effect queue ///////////////////////////////////////////
195
      effects.apply(mainMove);
196
      effects.apply(mainScale);
197

  
198
      return new DistortedNode(mCountTexture,effects,mesh);
135 199
      }
136 200

  
137 201
///////////////////////////////////////////////////////////////////////////////////////////////////
......
143 207
      mScreen = screen;
144 208
      mListener= listener;
145 209
      DataStars stars = (DataStars)data;
146
      int totS = stars.getTotal();
147
      int newS = stars.getNew();
210
      mTotalStars = stars.getTotal();
211
      mNewStars   = stars.getNew();
148 212
      Resources res = stars.getResources();
149 213

  
150 214
      mWidth = mScreen.getWidth();
151 215
      mHeight= mScreen.getHeight();
152 216

  
153
      mNode = createNode(res,totS,newS);
154
      mNode.glDepthMask(false);
155
      mNode.glStencilMask(0);
156
      mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
157
      mScreen.attach(mNode);
217
      mStarsNode = createStarsNode(res);
218
      mStarsNode.glDepthMask(false);
219
      mStarsNode.glStencilMask(0);
220
      mStarsNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
221
      mScreen.attach(mStarsNode);
222

  
223
      mCountNode = createCountNode();
224
      mCountNode.glDepthMask(false);
225
      mCountNode.glStencilMask(0);
226
      mCountNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
227
      mScreen.attach(mCountNode);
158 228

  
159 229
      return 0;
160 230
      }
......
163 233

  
164 234
   public void effectFinished(long id)
165 235
      {
166
      mScreen.detach(mNode);
167
      mListener.overlayFinished(id);
236
      if( id==mMoveID )
237
         {
238
         Dynamic2D haloRadius = new Dynamic2D(DUR_GLO,1.0f);
239
         haloRadius.add(new Static2D( 0, 0));
240
         haloRadius.add(new Static2D(15,50));
241
         haloRadius.add(new Static2D( 0, 0));
242

  
243
         Dynamic4D color= new Dynamic4D(DUR_GLO,1.0f);
244
         Static4D P1    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
245
         Static4D P2    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
246
         color.add(P1);
247
         color.add(P2);
248
         color.add(P1);
249

  
250
         PostprocessEffectGlow glow = new PostprocessEffectGlow(haloRadius,color);
251
         glow.setQuality(EffectQuality.MEDIUM);
252
         mGlowID = glow.getID();
253
         glow.notifyWhenFinished(this);
254
         DistortedEffects effects = mStarsNode.getEffects();
255
         effects.apply(glow);
256

  
257
         renderStars(mTotalStars+mNewStars);
258
         }
259
      if( id==mGlowID )
260
         {
261
         mScreen.detach(mStarsNode);
262
         mStarsNode.markForDeletion();
263
         mStarsNode=null;
264
         mScreen.detach(mCountNode);
265
         mCountNode.markForDeletion();
266
         mCountNode=null;
267
         mListener.overlayFinished(id);
268
         }
168 269
      }
169 270

  
170 271
///////////////////////////////////////////////////////////////////////////////////////////////////
......
174 275
     {
175 276
     VertexEffectMove.enable();
176 277
     VertexEffectScale.enable();
177
     VertexEffectRotate.enable();
278
     PostprocessEffectGlow.enable();
178 279
     }
179 280
}

Also available in: Unified diff