Project

General

Profile

« Previous | Next » 

Revision d79a56d3

Added by Leszek Koltunski about 7 years ago

Major refactoring: convert the Matrix Effects to be independent of the resolution of the surface we render to.

Re-write the first 15 apps to work with this.

View differences:

src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
105 105
   
106 106
///////////////////////////////////////////////////////////////////////////////////////////////////
107 107
   
108
    public void onDrawFrame(GL10 glUnused) 
108
   public void onDrawFrame(GL10 glUnused)
109 109
      {
110 110
      mScreen.render( System.currentTimeMillis() );
111 111
      }
112 112

  
113 113
///////////////////////////////////////////////////////////////////////////////////////////////////
114 114
    
115
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
116
      {  
117
      for(int i=NUM-1; i>=0; i--) 
118
        {   
119
        mEffects[i].abortEffects(EffectTypes.MATRIX);
120
        }
115
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
116
     {
117
     for(int i=NUM-1; i>=0; i--)
118
       {
119
       mEffects[i].abortEffects(EffectTypes.MATRIX);
120
       }
121 121
      
122
      if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width )
123
        {
124
        int w = (height*bmpWidth)/bmpHeight;
125
        float factor = (float)height/bmpHeight;
126

  
127
        for(int i=NUM-1; i>=0; i--) 
128
          {
129
          mEffects[i].move( new Static3D((width-NUM*w)/2 +i*w ,0,0) );
130
          mEffects[i].scale(factor);
131
          }
132
        }
133
      else
134
        {
135
        int w = width/NUM;  
136
        int h = (width*bmpHeight)/(bmpWidth*NUM);
137
        float factor = (float)width/(bmpWidth*NUM);
138

  
139
        for(int i=NUM-1; i>=0; i--) 
140
          {
141
          mEffects[i].move( new Static3D(i*w,(height-h)/2,0) );
142
          mEffects[i].scale(factor);
143
          }
144
        }
122
     float qx = (float)width /bmpWidth;
123
     float qy = (float)height/bmpHeight;
124

  
125
     if( qx > NUM*qy )  // screen more 'horizontal' than NUM bitmaps next to each other
126
       {
127
       for(int i=0; i<NUM; i++)
128
         {
129
         mEffects[i].move( new Static3D( qy*((0.5f+i)/NUM-0.5f), 0, 0) );
130
         mEffects[i].scale( new Static3D( qy/qx, 1, 1) );
131
         }
132
       }
133
     else
134
       {
135
       for(int i=0; i<NUM; i++)
136
         {
137
         mEffects[i].move( new Static3D( (0.5f+i)/NUM-0.5f, 0, 0) );
138
         mEffects[i].scale( new Static3D( 1.0f/NUM, (qx/qy)/NUM, 1) );
139
         }
140
       }
145 141
         
146
      mScreen.resize(width, height);
147
      }
142
     mScreen.resize(width, height);
143
     }
148 144

  
149 145
///////////////////////////////////////////////////////////////////////////////////////////////////
150 146
    
151
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
152
      {
153
      Bitmap bitmap0= readBitmap(R.raw.dog);
154
      Bitmap bitmap1= readBitmap(R.raw.face);
155
      Bitmap bitmap2= readBitmap(R.raw.cat);
147
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
148
     {
149
     Bitmap bitmap0= readBitmap(R.raw.dog);
150
     Bitmap bitmap1= readBitmap(R.raw.face);
151
     Bitmap bitmap2= readBitmap(R.raw.cat);
156 152
      
157
      bmpHeight = bitmap0.getHeight();
158
      bmpWidth  = bitmap0.getWidth();
153
     bmpHeight = bitmap0.getHeight();
154
     bmpWidth  = bitmap0.getWidth();
159 155

  
160
      if( mTexture==null )
161
        {
162
        mTexture = new DistortedTexture[NUM];
156
     if( mTexture==null )
157
       {
158
       mTexture = new DistortedTexture[NUM];
163 159

  
164
        for(int i=0; i<NUM; i++)
165
          mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight);
166
        }
160
       for(int i=0; i<NUM; i++)
161
         mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight);
162
       }
167 163

  
168
      mTexture[0].setTexture(bitmap0);
169
      mTexture[1].setTexture(bitmap1);
170
      mTexture[2].setTexture(bitmap2);
164
     mTexture[0].setTexture(bitmap0);
165
     mTexture[1].setTexture(bitmap1);
166
     mTexture[2].setTexture(bitmap2);
171 167

  
172
      MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
168
     MeshFlat mesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
173 169

  
174
      mScreen.detachAll();
175
      for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh);
170
     mScreen.detachAll();
171
     for(int i=NUM-1; i>=0; i--) mScreen.attach(mTexture[i], mEffects[i], mesh);
176 172

  
177
      DistortedEffects.enableEffect(EffectNames.SINK);
178
      DistortedEffects.enableEffect(EffectNames.DISTORT);
173
     DistortedEffects.enableEffect(EffectNames.SINK);
174
     DistortedEffects.enableEffect(EffectNames.DISTORT);
179 175

  
180
      try
181
        {
182
        Distorted.onCreate(mView.getContext());
183
        }
184
      catch(Exception ex)
185
        {
186
        android.util.Log.e("Renderer", ex.getMessage() );
187
        }
188
      }
176
     try
177
       {
178
       Distorted.onCreate(mView.getContext());
179
       }
180
     catch(Exception ex)
181
       {
182
       android.util.Log.e("Renderer", ex.getMessage() );
183
       }
184
     }
189 185
}

Also available in: Unified diff