Project

General

Profile

« Previous | Next » 

Revision 51554e47

Added by Leszek Koltunski over 7 years ago

Convert a few more APPs to the new resolution-independent Matrix Effects.

View differences:

src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES30;
25 24
import android.opengl.GLSurfaceView;
26 25

  
27 26
import org.distorted.examples.R;
......
49 48
   private DistortedTexture mTexture;
50 49
   private DistortedScreen mScreen;
51 50
   private AroundTheWorldEffectsManager mManager;
52
   private int mObjWidth, mObjHeight;
51
   private int bmpWidth, bmpHeight;
53 52

  
54 53
///////////////////////////////////////////////////////////////////////////////////////////////////
55 54

  
......
84 83
    
85 84
   public void onSurfaceChanged(GL10 glUnused, int width, int height) 
86 85
      {
87
      mEffects.abortEffects(EffectTypes.MATRIX);
86
      float qx = (float)width /bmpWidth;
87
      float qy = (float)height/bmpHeight;
88 88

  
89
      if( (float)mObjHeight/mObjWidth > (float)height/width )
90
        {
91
        int w = (height*mObjWidth)/mObjHeight;
92
        float factor = (float)height/mObjHeight;
93
        mEffects.move( new Static3D((width-w)/2,0,0) );
94
        mEffects.scale(factor);
95
        }
96
      else
97
        {
98
        int h = (width*mObjHeight)/mObjWidth;
99
        float factor = (float)width/mObjWidth;
100
        mEffects.move( new Static3D(0,(height-h)/2,0) );
101
        mEffects.scale(factor);
102
        }
89
      mEffects.abortEffects(EffectTypes.MATRIX);
90
      mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
103 91

  
104 92
      mScreen.resize(width,height);
105 93
      }
......
124 112
        catch(IOException e) { }
125 113
        }
126 114

  
127
      mObjWidth = bitmap.getWidth();
128
      mObjHeight= bitmap.getHeight();
115
      bmpWidth = bitmap.getWidth();
116
      bmpHeight= bitmap.getHeight();
129 117

  
130
      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
118
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
131 119
      mTexture.setTexture(bitmap);
132 120

  
133 121
      mScreen.detachAll();
134
      mScreen.attach(mTexture, mEffects, new MeshFlat(30,30*mObjHeight/mObjWidth));
122
      mScreen.attach(mTexture, mEffects, new MeshFlat(30,30*bmpHeight/bmpWidth));
135 123

  
136 124
      DistortedEffects.enableEffect(EffectNames.DISTORT);
137 125
      DistortedEffects.enableEffect(EffectNames.SINK);
src/main/java/org/distorted/examples/blur/BlurRenderer.java
91 91

  
92 92
///////////////////////////////////////////////////////////////////////////////////////////////////
93 93
    
94
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
95
      { 
96
      mEffects.abortEffects(EffectTypes.MATRIX);
97
      
98
      if( (float)bmpHeight/bmpWidth > (float)height/width )
99
        {
100
        int w = (height*bmpWidth)/bmpHeight;
101
        float factor = (float)height/bmpHeight;
102

  
103
        mEffects.move( new Static3D((width-w)/2,0,0) );
104
        mEffects.scale(factor);
105
        }
106
      else
107
        {
108
        int h = (width*bmpHeight)/bmpWidth;
109
        float factor = (float)width/bmpWidth;
110

  
111
        mEffects.move( new Static3D(0,(height-h)/2,0) );
112
        mEffects.scale(factor);
113
        }
94
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
95
     {
96
     float qx = (float)width /bmpWidth;
97
     float qy = (float)height/bmpHeight;
98

  
99
     mEffects.abortEffects(EffectTypes.MATRIX);
100
     mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
114 101
      
115
      mScreen.resize(width, height);
116
      }
102
     mScreen.resize(width, height);
103
     }
117 104

  
118 105
///////////////////////////////////////////////////////////////////////////////////////////////////
119 106
    
120
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
121
      {
122
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
123
      Bitmap bitmap;
107
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
108
     {
109
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.dog);
110
     Bitmap bitmap;
124 111
        
125
      try 
126
        {
127
        bitmap = BitmapFactory.decodeStream(is);
128
        } 
129
      finally 
130
        {
131
        try 
132
          {
133
          is.close();
134
          } 
135
        catch(IOException e) { }
136
        }  
112
     try
113
       {
114
       bitmap = BitmapFactory.decodeStream(is);
115
       }
116
     finally
117
       {
118
       try
119
         {
120
         is.close();
121
         }
122
       catch(IOException e) { }
123
       }
137 124
      
138
      bmpHeight = bitmap.getHeight();
139
      bmpWidth  = bitmap.getWidth();
140

  
141
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
142
      mTexture.setTexture(bitmap);
143

  
144
      mScreen.detachAll();
145
      DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
146
      node.setPostprocessEffects(mPostEffects);
147
      mScreen.attach(node);
148

  
149
      DistortedEffects.enableEffect(EffectNames.BLUR);
150

  
151
      try
152
        {
153
        Distorted.onCreate(mView.getContext());
154
        }
155
      catch(Exception ex)
156
        {
157
        android.util.Log.e("Blur", ex.getMessage() );
158
        }
159
      }
125
     bmpHeight = bitmap.getHeight();
126
     bmpWidth  = bitmap.getWidth();
127

  
128
     if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
129
     mTexture.setTexture(bitmap);
130

  
131
     mScreen.detachAll();
132
     DistortedNode node = new DistortedNode(mTexture,mEffects,mMesh);
133
     node.setPostprocessEffects(mPostEffects);
134
     mScreen.attach(node);
135

  
136
     DistortedEffects.enableEffect(EffectNames.BLUR);
137

  
138
     try
139
       {
140
       Distorted.onCreate(mView.getContext());
141
       }
142
     catch(Exception ex)
143
       {
144
       android.util.Log.e("Blur", ex.getMessage() );
145
       }
146
     }
160 147
}
src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES30;
25 24
import android.opengl.GLSurfaceView;
26 25

  
27 26
import org.distorted.examples.R;
src/main/java/org/distorted/examples/girl/GirlRenderer.java
157 157

  
158 158
///////////////////////////////////////////////////////////////////////////////////////////////////
159 159
    
160
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
161
      { 
162
      float qx = (float)width /bmpWidth;
163
      float qy = (float)height/bmpHeight;
160
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
161
     {
162
     float qx = (float)width /bmpWidth;
163
     float qy = (float)height/bmpHeight;
164 164

  
165
      mEffects.abortEffects(EffectTypes.MATRIX);
166
      mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
165
     mEffects.abortEffects(EffectTypes.MATRIX);
166
     mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
167 167
      
168
      mScreen.resize(width, height);
169
      }
168
     mScreen.resize(width, height);
169
     }
170 170

  
171 171
///////////////////////////////////////////////////////////////////////////////////////////////////
172 172
    
173
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
174
      {
175
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
176
      Bitmap bitmap;
173
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
174
     {
175
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
176
     Bitmap bitmap;
177 177
        
178
      try 
179
        {
180
        bitmap = BitmapFactory.decodeStream(is);
181
        } 
182
      finally 
183
        {
184
        try 
185
          {
186
          is.close();
187
          } 
188
        catch(IOException e) { }
189
        }  
178
     try
179
       {
180
       bitmap = BitmapFactory.decodeStream(is);
181
       }
182
     finally
183
       {
184
       try
185
         {
186
         is.close();
187
         }
188
       catch(IOException e) { }
189
       }
190 190
      
191
      bmpHeight = bitmap.getHeight();
192
      bmpWidth  = bitmap.getWidth();
193

  
194
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
195
      mTexture.setTexture(bitmap);
196

  
197
      mScreen.detachAll();
198
      mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
199

  
200
      DistortedEffects.enableEffect(EffectNames.DISTORT);
201
      DistortedEffects.enableEffect(EffectNames.SINK);
202
      DistortedEffects.enableEffect(EffectNames.SWIRL);
203

  
204
      try
205
        {
206
        Distorted.onCreate(mView.getContext());
207
        }
208
      catch(Exception ex)
209
        {
210
        android.util.Log.e("Renderer", ex.getMessage() );
211
        }
212
      }
191
     bmpHeight = bitmap.getHeight();
192
     bmpWidth  = bitmap.getWidth();
193

  
194
     if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
195
     mTexture.setTexture(bitmap);
196

  
197
     mScreen.detachAll();
198
     mScreen.attach(mTexture,mEffects,new MeshFlat(30,30*bmpHeight/bmpWidth));
199

  
200
     DistortedEffects.enableEffect(EffectNames.DISTORT);
201
     DistortedEffects.enableEffect(EffectNames.SINK);
202
     DistortedEffects.enableEffect(EffectNames.SWIRL);
203

  
204
     try
205
       {
206
       Distorted.onCreate(mView.getContext());
207
       }
208
     catch(Exception ex)
209
       {
210
       android.util.Log.e("Renderer", ex.getMessage() );
211
       }
212
     }
213 213
}
src/main/java/org/distorted/examples/olimpic/OlimpicRenderer.java
56 56
   private DistortedTexture mLeaf;
57 57
   private DistortedScreen mScreen;
58 58
   private MeshFlat mMesh;
59
   private int mScreenW, mScreenH;
59
   private int mRootW, mRootH;
60 60
   private int mPrevRendered, mCurrRendered;
61 61

  
62 62
   private DistortedNode[] mCircleNode = new DistortedNode[NUM_CIRCLES];
......
95 95
      mMesh = new MeshFlat(1,1);
96 96
      DistortedEffects effects = new DistortedEffects();
97 97

  
98
      mScreenW = 9*LEAF_SIZE;
99
      mScreenH = 9*LEAF_SIZE;
100
      mRoot = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), effects, mMesh);
98
      mRootW = 9*LEAF_SIZE;
99
      mRootH = 9*LEAF_SIZE;
100
      mRoot = new DistortedNode(new DistortedTexture(mRootW,mRootH), effects, mMesh);
101 101
     
102 102
      Dynamic1D rot = new Dynamic1D(5000,0.0f);
103 103
      rot.setMode(Dynamic1D.MODE_JUMP);
104 104
      rot.add(new Static1D(  0));
105 105
      rot.add(new Static1D(360));
106 106

  
107
      int[] colors    = new int[] {0,0,1,  0,0,0,  1,0,0,  1,1,0,  0,1,0}; // blue, black, red, yellow, green  
108
      int[] positions = new int[] {0,2*LEAF_SIZE,  3*LEAF_SIZE,2*LEAF_SIZE,  6*LEAF_SIZE,2*LEAF_SIZE,  3*LEAF_SIZE/2,9*LEAF_SIZE/2,  9*LEAF_SIZE/2,9*LEAF_SIZE/2};
107
      int[]   colors    = new int[] {0,0,1,  0,0,0,  1,0,0,  1,1,0,  0,1,0}; // blue, black, red, yellow, green
108
      float[] positions = new float[] { -0.333f, -0.12f,    0.0f,-0.12f,    +0.333f,-0.12f,
109
                                               -0.166f,+0.166f,     +0.166f,+0.166f };
109 110
      
110
      Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
111
      Static3D center = new Static3D(0,0,0);
111 112
      Static3D axis   = new Static3D(0,0,1);
112
      Static3D moveVector = new Static3D(0,LEAF_SIZE,0);
113
      Static3D move   = new Static3D(-0.33f,0.0f,0.0f);
114
      Static3D scale  = new Static3D(0.333f,0.333f,0.333f);
113 115

  
114 116
      for(int j=0; j<NUM_LEAVES; j++)
115 117
        {
116 118
        mEffects[j] = new DistortedEffects();
117
        mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
118
        mEffects[j].move(moveVector);
119
        mEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center);
120
        mEffects[j].move(move);
121
        mEffects[j].scale(scale);
119 122
        }
120 123

  
121 124
      for(int i=0; i<NUM_CIRCLES; i++)
......
123 126
        effects = new DistortedEffects();
124 127
        effects.move( new Static3D(positions[2*i], positions[2*i+1], 0) );
125 128
        effects.rotate( rot, axis, center );
129
        effects.scale( scale );
126 130
        effects.chroma( new Static1D(0.5f), new Static3D(colors[3*i],colors[3*i+1], colors[3*i+2]) );
127 131

  
128 132
        mCircleNode[i] = new DistortedNode( surface, effects, mMesh);
......
137 141

  
138 142
///////////////////////////////////////////////////////////////////////////////////////////////////
139 143
   
140
    public void onDrawFrame(GL10 glUnused) 
141
      {
142
      mCurrRendered = mScreen.render(System.currentTimeMillis());
144
   public void onDrawFrame(GL10 glUnused)
145
     {
146
     mCurrRendered = mScreen.render(System.currentTimeMillis());
143 147

  
144
      if( mCurrRendered!=mPrevRendered )
145
        {
146
        mPrevRendered = mCurrRendered;
148
     if( mCurrRendered!=mPrevRendered )
149
       {
150
       mPrevRendered = mCurrRendered;
147 151

  
148
        final OlimpicActivity act = (OlimpicActivity)mView.getContext();
152
       final OlimpicActivity act = (OlimpicActivity)mView.getContext();
149 153

  
150
        act.runOnUiThread(new Runnable()
154
       act.runOnUiThread(new Runnable()
151 155
          {
152 156
          public void run()
153 157
            {
154
            act.setText("rendered: "+mCurrRendered+" objects");
155
            }
158
           act.setText("rendered: "+mCurrRendered+" objects");
159
           }
156 160
          });
157
        }
158
      }
161
       }
162
     }
159 163

  
160 164
///////////////////////////////////////////////////////////////////////////////////////////////////
161 165
    
162
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
163
      {
164
      DistortedEffects effects = mRoot.getEffects();
166
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
167
     {
168
     DistortedEffects effects = mRoot.getEffects();
165 169

  
166
      effects.abortEffects(EffectTypes.MATRIX);
167
      
168
      if( (float)mScreenH/mScreenW > (float)height/width )
169
        {
170
        int w = (height*mScreenW)/mScreenH;
171
        float factor = (float)height/mScreenH;
170
     float qx = (float)width /mRootW;
171
     float qy = (float)height/mRootH;
172 172

  
173
        effects.move( new Static3D((width-w)/2 ,0, 0) );
174
        effects.scale( factor );
175
        }
176
      else
177
        {
178
        int h = (width*mScreenH)/mScreenW;
179
        float factor = (float)width/mScreenW;
173
     effects.abortEffects(EffectTypes.MATRIX);
174
     effects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
180 175

  
181
        effects.move( new Static3D(0,(height-h)/2,0) );
182
        effects.scale( factor );
183
        }
184
      
185
      mScreen.resize(width, height);
186
      }
176
     mScreen.resize(width, height);
177
     }
187 178

  
188 179
///////////////////////////////////////////////////////////////////////////////////////////////////
189 180
    
190
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
191
      {
192
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
193
      Bitmap leaf;
181
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
182
     {
183
     InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
184
     Bitmap leaf;
194 185
      
195
      try 
196
        {
197
        leaf = BitmapFactory.decodeStream(is);
198
        } 
199
      finally 
200
        {
201
        try 
202
          {
203
          is.close();
204
          } 
205
        catch(IOException e) { }
206
        }  
186
     try
187
       {
188
       leaf = BitmapFactory.decodeStream(is);
189
       }
190
     finally
191
       {
192
       try
193
         {
194
         is.close();
195
         }
196
       catch(IOException e) { }
197
       }
207 198
      
208
      mLeaf.setTexture(leaf);
199
     mLeaf.setTexture(leaf);
209 200

  
210
      DistortedEffects.enableEffect(EffectNames.CHROMA);
201
     DistortedEffects.enableEffect(EffectNames.CHROMA);
211 202

  
212
      try
213
        {
214
        Distorted.onCreate(mView.getContext());
215
        }
216
      catch(Exception ex)
217
        {
218
        android.util.Log.e("Olympic", ex.getMessage() );
219
        }
220
      }
221
 
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
    
203
     try
204
       {
205
       Distorted.onCreate(mView.getContext());
206
       }
207
     catch(Exception ex)
208
       {
209
       android.util.Log.e("Olympic", ex.getMessage() );
210
       }
211
     }
224 212
}
src/main/java/org/distorted/examples/plainmonalisa/RenderThread.java
209 209
    {
210 210
    Log.d(TAG, "surfaceChanged " + width + "x" + height);
211 211

  
212
    mEffects.abortEffects(EffectTypes.MATRIX);
213

  
214
    if( (float)bmpHeight/bmpWidth > (float)height/width )
215
      {
216
      int w = (height*bmpWidth)/bmpHeight;
217
      float factor = (float)height/bmpHeight;
218

  
219
      mEffects.move( new Static3D((width-w)/2,0,0) );
220
      mEffects.scale( factor );
221
      }
222
    else
223
      {
224
      int h = (width*bmpHeight)/bmpWidth;
225
      float factor = (float)width/bmpWidth;
212
    float qx = (float)width /bmpWidth;
213
    float qy = (float)height/bmpHeight;
226 214

  
227
      mEffects.move( new Static3D(0,(height-h)/2,0) );
228
      mEffects.scale( factor );
229
      }
215
    mEffects.abortEffects(EffectTypes.MATRIX);
216
    mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
230 217

  
231 218
    mScreen.resize(width, height);
232 219
    }
src/main/java/org/distorted/examples/save/SaveRenderer.java
187 187

  
188 188
  private void applyMatrixEffects(int width, int height)
189 189
    {
190
    mEffects.abortEffects(EffectTypes.MATRIX);
191

  
192
    if( (float)bmpHeight/bmpWidth > (float)height/width )
193
      {
194
      int w = (height*bmpWidth)/bmpHeight;
195
      float factor = (float)height/bmpHeight;
196

  
197
      mEffects.move( new Static3D((width-w)/2,0,0) );
198
      mEffects.scale(factor);
199
      }
200
    else
201
      {
202
      int h = (width*bmpHeight)/bmpWidth;
203
      float factor = (float)width/bmpWidth;
190
    float qx = (float)width /bmpWidth;
191
    float qy = (float)height/bmpHeight;
204 192

  
205
      mEffects.move( new Static3D(0,(height-h)/2,0) );
206
      mEffects.scale(factor);
207
      }
193
    mEffects.abortEffects(EffectTypes.MATRIX);
194
    mEffects.scale(  qx<qy ? (new Static3D(1,qx/qy,1)) : (new Static3D(qy/qx,1,1)) );
208 195

  
209 196
    mEffects.scale(mScaleDyn);
210 197
    }
src/main/java/org/distorted/examples/starwars/StarWarsRenderer.java
404 404
        int crawlH = mCrawlTexture.getHeight();
405 405
        int screenW= mScreen.getWidth();
406 406
        int screenH= mScreen.getHeight();
407
        int backW  = mCrawlBackgroundTexture.getWidth();
407 408
        int backH  = mCrawlBackgroundTexture.getHeight();
408
        float scale= (float)screenW/crawlW;
409
        float scale= ((float)backW/backH)*((float)crawlH/crawlW);
409 410

  
410
        //mCrawlBackgroundEffects.move( new Static3D(0,screenH-backH,0) );
411
        mCrawlBackgroundEffects.move( new Static3D(0, -((float)backH/screenH-1.0f)/2 ,0) );
411 412
        mCrawlBackgroundEffects.rotate( new Static1D(CRAWL_ANGLE), new Static3D(1,0,0), new Static3D(0.5f,1.0f,0.0f) );
412 413
        mCrawlBackgroundEffects.scale( new Static3D(1.0f, (float)backH/screenH,1.0f) );
413 414

  
414 415
        final int transpDist = 5;
415 416
        Static4D region = new Static4D(screenW/2,(1-transpDist)*backH,transpDist*backH,transpDist*backH);
416
        //mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist*0.6f), region, true);
417
        mCrawlBackgroundEffects.alpha(new Static1D(1-transpDist*0.6f), region, true);
417 418

  
418 419
        Dynamic3D di = new Dynamic3D(70000,0.5f);
419
        di.add(new Static3D(screenW/2,+backH       , 0));
420
        di.add(new Static3D(screenW/2,-scale*crawlH, 0));
420
        di.add(new Static3D(0,         0,0));
421
        di.add(new Static3D(0,-(1+scale),0));
422

  
423
        mCrawlEffects.move(di);
424
        mCrawlEffects.move ( new Static3D(0, (1+scale)/2,0) );
425
        mCrawlEffects.scale( new Static3D(1,    scale   ,1) );
421 426

  
422
        //mCrawlEffects.move(di);
423
        //mCrawlEffects.scale( new Static3D(scale,scale,scale) );
424
        //mCrawlEffects.move( new Static3D(-crawlW/2,0,0) );
425
        
426 427
        mBackground = mScreen.attach(mCrawlBackgroundTexture, mCrawlBackgroundEffects,mQuad);
427 428
        mBackground.attach(mCrawlTexture, mCrawlEffects,mQuad);
428 429
        mBackground.glDisable(GLES30.GL_DEPTH_TEST);

Also available in: Unified diff