Project

General

Profile

« Previous | Next » 

Revision 5c3b92c4

Added by Leszek Koltunski almost 4 years ago

Convert DifferentBitmaps to stretchless API.

View differences:

src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
30 30
import org.distorted.library.effect.MatrixEffectMove;
31 31
import org.distorted.library.effect.MatrixEffectScale;
32 32
import org.distorted.library.effect.VertexEffectDistort;
33
import org.distorted.library.effect.VertexEffectScale;
33 34
import org.distorted.library.effect.VertexEffectSink;
34 35
import org.distorted.library.main.DistortedLibrary;
35 36
import org.distorted.library.main.DistortedScreen;
......
57 58
   private DistortedTexture[] mTexture;
58 59
   private MeshRectangles mMesh;
59 60
   private DistortedScreen mScreen;
60
   private Static3D mScale;
61
   private Static3D mScaleMatrix, mScaleVertex;
61 62
   private Static3D[] mMove;
62 63

  
63 64
///////////////////////////////////////////////////////////////////////////////////////////////////
......
72 73
      Static3D point = new Static3D(0,-60,0);
73 74
      Static4D region= new Static4D(0,0,0,300);
74 75

  
76
      mScaleMatrix = new Static3D(1,1,1);
77
      mScaleVertex = new Static3D(1,1,1);
78

  
75 79
      mEffects = new DistortedEffects[NUM];
76 80
      mEffects[0] = new DistortedEffects();
77 81
      for(int i=1; i<NUM; i++)
......
79 83

  
80 84
      // Add the effects only to the first queue - all VERTEX and FRAGMENT effects are shared!
81 85
      // (Matrix effect cannot be shared as we have to display each Texture in a different location)
82
      VertexEffectSink sink = new VertexEffectSink(new Static1D(8), point, new Static4D(0,0,0,80));
86
      VertexEffectScale scale     = new VertexEffectScale(mScaleVertex);
87
      VertexEffectSink sink       = new VertexEffectSink(new Static1D(8), point, new Static4D(0,0,0,80));
83 88
      VertexEffectDistort distort = new VertexEffectDistort(dDistort,point,region);
89
      mEffects[0].apply(scale);   // scale the whole thing (so far by 1, but mScaleVertex will be reset once we know the size of the bitmap)
84 90
      mEffects[0].apply(sink);    // enlarge the nose
85 91
      mEffects[0].apply(distort); // keep moving the whole bitmap left and right.
86 92

  
87 93
      // Now the Matrix effects
88
      mScale = new Static3D(1,1,1);
89
      MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
94

  
95
      MatrixEffectScale scaleEffect = new MatrixEffectScale(mScaleMatrix);
90 96
      mMove  = new Static3D[NUM];
91 97
      MatrixEffectMove[] moveEffect = new MatrixEffectMove[NUM];
92 98

  
......
113 119
    
114 120
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
115 121
     {
116
     float horiRatio = (float)width / (NUM*mMesh.getStretchX());
117
     float vertRatio = (float)height/ (    mMesh.getStretchY());
118
     float factor    = horiRatio > vertRatio ? vertRatio : horiRatio;
122
     float horiRatio = (float)width / (NUM*mScaleVertex.get0());
123
     float vertRatio = (float)height/ (    mScaleVertex.get1());
124
     float factor    = Math.min(horiRatio, vertRatio);
119 125

  
120
     mScale.set( factor,factor,factor );
126
     mScaleMatrix.set( factor,factor,factor );
121 127

  
122
     for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*(width/NUM), 0, 0);
128
     for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*width/NUM, 0, 0);
123 129

  
124 130
     mScreen.resize(width, height);
125 131
     }
......
138 144
     int bmpHeight = bmp[0].getHeight();
139 145
     int bmpWidth  = bmp[0].getWidth();
140 146

  
147
     mScaleVertex.set(bmpWidth,bmpHeight,0);
148

  
141 149
     if( mTexture==null )
142 150
       {
143 151
       mTexture = new DistortedTexture[NUM];
......
151 159
       mTexture[i].setTexture(bmp[i]);
152 160
       }
153 161

  
154
     if( mMesh==null )
155
       {
156
       mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
157
       mMesh.setStretch(bmpWidth,bmpHeight,0);
158
       }
162
     if( mMesh==null ) mMesh = new MeshRectangles(30,30*bmpHeight/bmpWidth);
159 163

  
160 164
     mScreen.detachAll();
161 165
     for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mMesh);
162 166

  
167
     VertexEffectScale.enable();
163 168
     VertexEffectSink.enable();
164 169
     VertexEffectDistort.enable();
165 170

  

Also available in: Unified diff