Project

General

Profile

« Previous | Next » 

Revision e8bf2663

Added by Leszek Koltunski over 4 years ago

Convert Save to stretchless API.

View differences:

src/main/java/org/distorted/examples/save/SaveRenderer.java
31 31
import org.distorted.examples.R;
32 32

  
33 33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectScale;
34 35
import org.distorted.library.effect.VertexEffectSink;
35 36
import org.distorted.library.main.DistortedLibrary;
36 37
import org.distorted.library.main.DistortedEffects;
......
60 61
  private MeshRectangles mMesh;
61 62
  private DistortedScreen mScreen;
62 63
  private Static1D s0;
63
  private Static3D mScaleFactor, mScaleMain;
64
  private Static3D mScaleFactor, mScaleMain, mScaleVertex;
64 65

  
65 66
  private float mScale;
66 67
  private int bmpHeight, bmpWidth;
......
89 90

  
90 91
    mScale = 1.0f;
91 92
    mScaleFactor = new Static3D(mScale,mScale,1.0f);
92
    mScaleMain = new Static3D(1,1,1);
93
    mScaleMain   = new Static3D(1,1,1);
94
    mScaleVertex = new Static3D(1,1,1);
93 95

  
94 96
    mEffects = new DistortedEffects();
97
    mEffects.apply( new VertexEffectScale(mScaleVertex));
95 98
    mEffects.apply( new VertexEffectSink(diSink, pLeft , sinkRegion) );
96 99
    mEffects.apply( new VertexEffectSink(diSink, pRight, sinkRegion) );
97 100
    mEffects.apply( new MatrixEffectScale(mScaleMain));
......
190 193

  
191 194
  private void applyMatrixEffects(int width, int height)
192 195
    {
193
    float horiRatio = (float)width / mMesh.getStretchX();
194
    float vertRatio = (float)height/ mMesh.getStretchY();
195
    float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
196
    float horiRatio = (float)width / mScaleVertex.get0();
197
    float vertRatio = (float)height/ mScaleVertex.get1();
198
    float factor    = Math.min(horiRatio, vertRatio);
196 199
    mScaleMain.set(factor,factor,factor);
197 200
    }
198 201

  
......
223 226
        {
224 227
        is.close();
225 228
        }
226
      catch(IOException e) { }
229
      catch(IOException ignored) { }
227 230
      }
228 231
      
229 232
    bmpHeight = bitmap.getHeight();
230 233
    bmpWidth  = bitmap.getWidth();
231 234

  
232
    if( mMesh==null )
233
      {
234
      mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
235
      mMesh.setStretch(bmpWidth,bmpHeight,0);
236
      }
235
    mScaleVertex.set(bmpWidth,bmpHeight,0);
236

  
237
    if( mMesh   ==null ) mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
237 238
    if( mTexture==null ) mTexture = new DistortedTexture();
238 239
    mTexture.setTexture(bitmap);
239 240

  
......
245 246
    mScreen.detachAll();
246 247
    mScreen.attach(mTexture,mEffects,mMesh);
247 248

  
249
    VertexEffectScale.enable();
248 250
    VertexEffectSink.enable();
249 251

  
250 252
    try

Also available in: Unified diff