Project

General

Profile

« Previous | Next » 

Revision 25eeb4d4

Added by Leszek Koltunski about 4 years ago

Port Girl to the new setStretch-less API.

View differences:

src/main/java/org/distorted/examples/girl/GirlRenderer.java
58 58
    private Static3D v0,v1,v2,v3;
59 59
    private Static1D dBegin, dMiddle, dEnd, s0;
60 60
    private Static3D mScale;
61
    private float mBmpRatio;
61 62

  
62 63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
// girl bitmap: 400x600
63 65

  
64 66
   GirlRenderer(GLSurfaceView v)
65 67
      {
66 68
      mView = v;
67 69

  
68
      Static3D pLeft = new Static3D(-68, 36, 0);
69
      Static3D pRight= new Static3D( 47, 36, 0);
70
      Static3D pLeft = new Static3D(-68/400.0f, 36/600.0f, 0);
71
      Static3D pRight= new Static3D( 47/400.0f, 36/600.0f, 0);
70 72

  
71 73
      // Size
72
      Static4D sinkRegion = new Static4D(0,0,0,60);
74
      Static4D sinkRegion = new Static4D(0,0,0,60/400.0f);
73 75
      
74 76
      s0 = new Static1D(1.0f);
75 77
      
......
77 79
      diSink.add(s0);
78 80
      
79 81
      // Upper Movement
80
      Static4D Region = new Static4D(0,0,0,45);
82
      Static4D Region = new Static4D(0,0,0,45/400.0f);
81 83
      
82 84
      Dynamic3D diL = new Dynamic3D(1000,0.0f);
83 85
      Dynamic3D diR = new Dynamic3D(1000,0.0f);
......
98 100
      diR.add(v1);
99 101
      
100 102
      // Lower Movement
101
      Static3D pHips      = new Static3D( 16,-205,0);
102
      Static4D HipsRegion = new Static4D(0,0,0,120);
103
      Static3D pHips      = new Static3D( 16/400.0f,-205/600.0f,0);
104
      Static4D HipsRegion = new Static4D(0,0,0,120/400.0f);
103 105
      Dynamic1D diHips    = new Dynamic1D(1500,0.0f);
104 106
      
105 107
      dBegin = new Static1D(0);
......
124 126
      mScale= new Static3D(1,1,1);
125 127
      mEffects.apply(new MatrixEffectScale(mScale));
126 128

  
129
      mTexture = new DistortedTexture();
127 130
      mScreen = new DistortedScreen();
128 131
      }
129 132

  
......
144 147
   
145 148
///////////////////////////////////////////////////////////////////////////////////////////////////
146 149

  
147
   void setSwing(int swing)
150
   void setSwing(float swing)
148 151
     {
149 152
     v0.set( 0, swing, 0);
150 153
     v1.set( swing, 0, 0);
......
163 166
    
164 167
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
165 168
     {
166
     float horiRatio = (float)width / mMesh.getStretchX();
167
     float vertRatio = (float)height/ mMesh.getStretchY();
168
     float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
169
     float min= width>height ? height : width;
169 170

  
170
     mScale.set( factor,factor,factor );
171
     mScale.set( min, min*mBmpRatio, min );
171 172
     mScreen.resize(width, height);
172 173
     }
173 174

  
......
191 192
       catch(IOException e) { }
192 193
       }
193 194
      
194
     int bmpHeight = bitmap.getHeight();
195
     int bmpWidth  = bitmap.getWidth();
196

  
197
     if( mTexture==null ) mTexture = new DistortedTexture();
195
     mBmpRatio = (float)bitmap.getHeight()/bitmap.getWidth();
198 196
     mTexture.setTexture(bitmap);
199 197

  
200
     if( mMesh==null )
201
       {
202
       mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
203
       mMesh.setStretch(bmpWidth,bmpHeight,0);
204
       }
198
     if( mMesh==null ) mMesh = new MeshRectangles(30, (int)(30*mBmpRatio));
205 199

  
206 200
     mScreen.detachAll();
207 201
     mScreen.attach(mTexture,mEffects,mMesh);

Also available in: Unified diff