Project

General

Profile

« Previous | Next » 

Revision 5d7e316e

Added by Leszek Koltunski over 4 years ago

Convert SurfaceView to stretchless API.

View differences:

src/main/java/org/distorted/examples/surfaceview/RenderThread.java
70 70
  private SurfaceView mView;
71 71
  private static boolean resourcesCreated = false;
72 72
  private Static3D mScale;
73
  private float mBmpRatio;
73 74

  
74 75
///////////////////////////////////////////////////////////////////////////////////////////////////
75 76

  
......
78 79
    mSurfaceHolder = holder;
79 80
    mView = view;
80 81

  
81
    Static3D pLeft = new Static3D( 90-320/2, 108-366/2,0);
82
    Static3D pRight= new Static3D(176-320/2, 111-366/2,0);
82
    Static3D pLeft = new Static3D( ( 90-320*0.5f)/320.0f, (108-366*0.5f)/366.0f, 0);
83
    Static3D pRight= new Static3D( (176-320*0.5f)/320.0f, (111-366*0.5f)/366.0f, 0);
83 84

  
84
    Static4D rLeft = new Static4D(-10, 10, 0,25);
85
    Static4D rRight= new Static4D( 10,  5, 0,25);
85
    Static4D rLeft = new Static4D( -10/320.0f, 10/366.0f, 0, 25/320.0f);
86
    Static4D rRight= new Static4D(  10/320.0f,  5/366.0f, 0, 25/320.0f);
86 87

  
87 88
    Dynamic3D dLeft = new Dynamic3D(1000,0.0f);
88 89
    Dynamic3D dRight= new Dynamic3D(1000,0.0f);
89 90

  
90
    dLeft.add( new Static3D(  0,  0, 0) );
91
    dLeft.add( new Static3D(-20, 20, 0) );
91
    dLeft.add( new Static3D(         0,         0, 0) );
92
    dLeft.add( new Static3D(-20/320.0f, 20/366.0f, 0) );
92 93

  
93
    dRight.add( new Static3D(  0,  0, 0) );
94
    dRight.add( new Static3D( 20, 10, 0) );
94
    dRight.add( new Static3D(         0,         0, 0) );
95
    dRight.add( new Static3D( 20/320.0f, 10/366.0f, 0) );
95 96

  
96 97
    mEffects = new DistortedEffects();
97 98
    mEffects.apply( new VertexEffectDistort(dLeft , pLeft , rLeft ) );
......
213 214
    {
214 215
    Log.d(TAG, "surfaceChanged " + width + "x" + height);
215 216

  
216
    float horiRatio = (float)width / mMesh.getStretchX();
217
    float vertRatio = (float)height/ mMesh.getStretchY();
218
    float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
217
    if( width<height ) mScale.set( width,   width*mBmpRatio, 1 );
218
    else               mScale.set( height/mBmpRatio, height, 1 );
219 219

  
220
    mScale.set( factor,factor,factor );
221 220
    mScreen.resize(width, height);
222 221
    }
223 222

  
......
243 242
      catch(IOException io) {}
244 243
      }
245 244

  
246
    int bmpHeight = bmp.getHeight();
247
    int bmpWidth  = bmp.getWidth();
245
    mBmpRatio = (float)bmp.getHeight()/bmp.getWidth();
248 246

  
249 247
    if( mTexture==null ) mTexture = new DistortedTexture();
250 248
    mTexture.setTexture(bmp);
251 249

  
252
    if( mMesh==null )
253
      {
254
      mMesh = new MeshRectangles(9,9*bmpHeight/bmpWidth);
255
      mMesh.setStretch(bmpWidth,bmpHeight,0);
256
      }
250
    if( mMesh==null ) mMesh = new MeshRectangles(9,(int)(9*mBmpRatio));
257 251

  
258 252
    mScreen.detachAll();
259 253
    mScreen.attach(mTexture,mEffects,mMesh);

Also available in: Unified diff