Project

General

Profile

« Previous | Next » 

Revision aa8b36aa

Added by Leszek Koltunski over 5 years ago

Progress.

View differences:

src/main/java/org/distorted/effect/AppearEffect.java
100 100

  
101 101
///////////////////////////////////////////////////////////////////////////////////////////////////
102 102

  
103
  public long start(DistortedScreen screen, RubikCube cube, EffectListener listener)
103
  public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener)
104 104
    {
105 105
    mScreen   = screen;
106 106
    mCube     = cube;
107 107
    mListener = listener;
108 108

  
109
    mCubeEffectFinished = createEffects(2000);
109
    mCubeEffectFinished = createEffects(duration);
110 110

  
111 111
    if( mCubeEffects!=null )
112 112
      {
src/main/java/org/distorted/effect/DisappearEffect.java
101 101

  
102 102
///////////////////////////////////////////////////////////////////////////////////////////////////
103 103

  
104
  public long start(DistortedScreen screen, RubikCube cube, EffectListener listener)
104
  public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener)
105 105
    {
106 106
    mScreen   = screen;
107 107
    mCube     = cube;
108 108
    mListener = listener;
109 109

  
110
    mCubeEffectFinished = createEffects(2000);
110
    mCubeEffectFinished = createEffects(duration);
111 111

  
112 112
    if( mCubeEffects!=null )
113 113
      {
src/main/java/org/distorted/magic/RubikActivity.java
115 115
    public void Scramble(View v)
116 116
      {
117 117
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
118
      view.scrambleCube();
118
      view.getRenderer().scrambleCube();
119 119
      }
120 120

  
121 121
///////////////////////////////////////////////////////////////////////////////////////////////////
......
139 139
          }
140 140

  
141 141
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
142
      boolean success = view.setNewCubeSize(size);
142
      boolean success = view.getRenderer().createCube(size);
143 143

  
144 144
      if( success )
145 145
        {
src/main/java/org/distorted/magic/RubikRenderer.java
54 54
    private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated;
55 55
    private boolean mCanRotate, mCanDrag;
56 56
    private RubikCube mOldCube, mNewCube;
57

  
58 57
    private int mScreenWidth, mScreenHeight;
59

  
60 58
    private MeshQuad mMesh;
59
    private AppearEffect.Type mAppearType;
60
    private DisappearEffect.Type mDisappearType;
61
    private int mAppearDuration, mDisappearDuration;
61 62

  
62 63
///////////////////////////////////////////////////////////////////////////////////////////////////
63 64

  
......
85 86
      mCanRotate = true;
86 87
      mCanDrag   = true;
87 88

  
89
      mAppearType    = AppearEffect.Type.SCALE;
90
      mDisappearType = DisappearEffect.Type.SCALE;
91

  
92
      mAppearDuration    = 1000;
93
      mDisappearDuration = 1000;
94

  
88 95
      mMesh= new MeshQuad();
89 96
      mNextCubeSize =RubikActivity.getSize();
90 97
      }
......
93 100
// various things are done here delayed, 'after the next render' as not to be done mid-render and
94 101
// cause artifacts.
95 102

  
103
    @Override
96 104
    public void onDrawFrame(GL10 glUnused) 
97 105
      {
98 106
      mScreen.render( System.currentTimeMillis() );
......
137 145
      }
138 146

  
139 147
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// EffectListener. The library sends a message to us when it's time to call 'removeRotation'
148

  
149
   @Override
150
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
151
      {
152
      if( mNewCube!=null ) mNewCube.createTexture();
153

  
154
      float cameraDistance = CAMERA_DISTANCE*(width>height ? width:height);
155
      float fovInDegrees   = computeFOV(cameraDistance,height);
156

  
157
      mScreen.setProjection( fovInDegrees, 0.1f);
158
      mView.setScreenSize(width,height);
159
      mView.setCameraDist(cameraDistance);
160
      mScreen.resize(width, height);
161

  
162
      recomputeScaleFactor(width,height);
163

  
164
      mScreenHeight = height;
165
      mScreenWidth  = width;
166
      }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

  
170
   @Override
171
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
172
      {
173
      VertexEffectSink.enable();
174
      AppearEffect.enableEffects();
175
      DisappearEffect.enableEffects();
176

  
177
      try
178
        {
179
        DistortedLibrary.onCreate(mView.getContext());
180
        }
181
      catch(Exception ex)
182
        {
183
        android.util.Log.e("Rubik", ex.getMessage() );
184
        }
185
      }
186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
141 188

  
142 189
   public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
143 190
     {
......
162 209
     {
163 210
     try
164 211
       {
165
       DisappearEffect effect = DisappearEffect.create(DisappearEffect.Type.ROUND);
166
       mDisappearEffectID = effect.start(mScreen,mOldCube,this);
212
       DisappearEffect effect = DisappearEffect.create(mDisappearType);
213
       mDisappearEffectID = effect.start(mDisappearDuration,mScreen,mOldCube,this);
167 214
       }
168 215
     catch(Exception ex)
169 216
       {
......
177 224
     {
178 225
     try
179 226
       {
180
       AppearEffect effect = AppearEffect.create(AppearEffect.Type.ROUND);
181
       mAppearEffectID = effect.start(mScreen,mNewCube,this);
227
       AppearEffect effect = AppearEffect.create(mAppearType);
228
       mAppearEffectID = effect.start(mAppearDuration,mScreen,mNewCube,this);
182 229
       }
183 230
     catch(Exception ex)
184 231
       {
......
192 239

  
193 240
///////////////////////////////////////////////////////////////////////////////////////////////////
194 241

  
195
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
196
      {
197
      if( mNewCube!=null ) mNewCube.createTexture();
242
   private float computeFOV(float cameraDistance, int screenHeight)
243
     {
244
     double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) );
245
     return (float)(2*halfFOVInRadians*(180/Math.PI));
246
     }
198 247

  
199
      float cameraDistance = CAMERA_DISTANCE*(width>height ? width:height);
200
      float fovInDegrees   = computeFOV(cameraDistance,height);
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249
// no this will not race with onDrawFrame
201 250

  
202
      mScreen.setProjection( fovInDegrees, 0.1f);
203
      mView.setScreenSize(width,height);
204
      mView.setCameraDist(cameraDistance);
205
      mScreen.resize(width, height);
251
   void finishRotation()
252
     {
253
     mFinishRotation = true;
254
     }
206 255

  
207
      recomputeScaleFactor(width,height);
256
///////////////////////////////////////////////////////////////////////////////////////////////////
208 257

  
209
      mScreenHeight = height;
210
      mScreenWidth  = width;
211
      }
258
   void setAppearDuration(int duration)
259
     {
260
     mAppearDuration = duration;
261
     }
212 262

  
213 263
///////////////////////////////////////////////////////////////////////////////////////////////////
214
    
215
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
216
      {
217
      VertexEffectSink.enable();
218
      AppearEffect.enableEffects();
219
      DisappearEffect.enableEffects();
220 264

  
221
      try
222
        {
223
        DistortedLibrary.onCreate(mView.getContext());
224
        }
225
      catch(Exception ex)
226
        {
227
        android.util.Log.e("Rubik", ex.getMessage() );
228
        }
229
      }
265
   void setDisappearDuration(int duration)
266
     {
267
     mDisappearDuration = duration;
268
     }
230 269

  
231 270
///////////////////////////////////////////////////////////////////////////////////////////////////
232 271

  
233
   private float computeFOV(float cameraDistance, int screenHeight)
272
   void setAppearType(AppearEffect.Type type)
234 273
     {
235
     double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) );
236
     return (float)(2*halfFOVInRadians*(180/Math.PI));
274
     mAppearType = type;
237 275
     }
238 276

  
239 277
///////////////////////////////////////////////////////////////////////////////////////////////////
240
// no this will not race with onDrawFrame
241 278

  
242
   void finishRotation()
279
   void setDisappearType(DisappearEffect.Type type)
243 280
     {
244
     mFinishRotation = true;
281
     mDisappearType = type;
245 282
     }
246 283

  
247 284
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikSurfaceView.java
164 164

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

  
167
    boolean setNewCubeSize(int newCubeSize)
167
    RubikRenderer getRenderer()
168 168
      {
169
      return mRenderer.createCube(newCubeSize);
170
      }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

  
174
    void scrambleCube()
175
      {
176
      mRenderer.scrambleCube();
169
      return mRenderer;
177 170
      }
178 171

  
179 172
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff