Project

General

Profile

« Previous | Next » 

Revision a7a8f7bd

Added by Leszek Koltunski almost 5 years ago

Convert Bean to not use the depreciated MeshBase.setStretch() API.

View differences:

src/main/java/org/distorted/examples/bean/BeanRenderer.java
52 52
   private DistortedTexture mTexture;
53 53
   private MeshRectangles mMesh;
54 54
   private Static3D mScale;
55
   private float mBmpRatio;
55 56

  
56 57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// bean bitmap is 366 x 480. Initialize two dynamic Distorts of the left and right brow.
57 59

  
58 60
   BeanRenderer(GLSurfaceView v)
59 61
      {
60 62
      mView = v;
61 63
     
62
      Static3D pointLeft  = new Static3D(-85,  57, 0);
63
      Static3D pointRight = new Static3D( 50, 100, 0);
64
      Static4D regionLeft = new Static4D( -3, 33, 0, 47);
65
      Static4D regionRight= new Static4D(-14, 33, 0, 47);
64
      Static3D pointLeft  = new Static3D(-85/366.0f,  57/480.0f, 0);
65
      Static3D pointRight = new Static3D( 50/366.0f, 100/480.0f, 0);
66
      Static4D regionLeft = new Static4D( -3/366.0f,  33/480.0f, 0, 47/400.0f);
67
      Static4D regionRight= new Static4D(-14/366.0f,  33/480.0f, 0, 47/400.0f);
68

  
66 69
      Dynamic3D dynLeft   = new Dynamic3D(2000,0.0f);
67 70
      Dynamic3D dynRight  = new Dynamic3D(2000,0.0f);
68 71

  
69
      Static3D vect1 = new Static3D(  0,  0, 0);
70
      Static3D vect2 = new Static3D(-15, 30, 0);
72
      Static3D vect1 = new Static3D(         0,         0, 0);
73
      Static3D vect2 = new Static3D(-15/366.0f, 30/480.0f, 0);
71 74

  
72 75
      dynLeft.add(vect1);
73 76
      dynLeft.add(vect1);
......
104 107
    
105 108
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
106 109
     {
107
     float horiRatio = (float)width / mMesh.getStretchX();
108
     float vertRatio = (float)height/ mMesh.getStretchY();
109
     float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
110
     float min= width>height ? height : width;
110 111

  
111
     mScale.set( factor,factor,factor );
112
     mScale.set( min, min*mBmpRatio, 1 );
112 113
     mScreen.resize(width, height);
113 114
     }
114 115

  
......
132 133
       catch(IOException e) { }
133 134
       }
134 135
      
135
     int bmpHeight = bitmap.getHeight();
136
     int bmpWidth  = bitmap.getWidth();
136
     mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
137 137

  
138 138
     if( mTexture==null ) mTexture = new DistortedTexture();
139 139
     mTexture.setTexture(bitmap);
140 140

  
141
     if( mMesh==null )
142
       {
143
       mMesh = new MeshRectangles(25,25*bmpHeight/bmpWidth);
144
       mMesh.setStretch(bmpWidth,bmpHeight,0);
145
       }
141
     // we need a denser Mesh lattice this time for the Distorts to look good.
142
     if( mMesh==null ) mMesh = new MeshRectangles(25, (int)(25*mBmpRatio));
146 143

  
147 144
     mScreen.detachAll();
148 145
     mScreen.attach(mTexture,mEffects,mMesh);

Also available in: Unified diff