Project

General

Profile

« Previous | Next » 

Revision f6d884d5

Added by Leszek Koltunski over 7 years ago

Complete the split DistortedObject -> (DistortedTexture,DistortedEffectQueue)

View differences:

src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java
28 28
import org.distorted.examples.R;
29 29

  
30 30
import org.distorted.library.Distorted;
31
import org.distorted.library.DistortedObject;
31
import org.distorted.library.DistortedTexture;
32
import org.distorted.library.DistortedEffectQueues;
32 33
import org.distorted.library.GridFlat;
33 34
import org.distorted.library.EffectTypes;
34 35
import org.distorted.library.type.Dynamic3D;
......
48 49
   private static final int NUM = 3;
49 50
   
50 51
   private GLSurfaceView mView;
51
   private DistortedObject[] mObj;
52
   private DistortedTexture[] mTexture;
53
   private DistortedEffectQueues[] mQueues;
52 54
   private GridFlat mGrid;
53
   private Static3D mPoint;
54
   private Dynamic3D dDistort;
55 55
   private int bmpHeight, bmpWidth;
56 56
    
57 57
///////////////////////////////////////////////////////////////////////////////////////////////////
......
60 60
      {     
61 61
      mView = v;
62 62
     
63
      // create shared effects - enlarge the nose and keep moving the whole bitmap left and right.
64
      dDistort = new Dynamic3D(3000,0.0f);
63
      Dynamic3D dDistort = new Dynamic3D(3000,0.0f);
65 64
      dDistort.add(new Static3D( 25,0,0));
66 65
      dDistort.add(new Static3D(-25,0,0));
67
      mPoint = new Static3D(305, 380, 0);
66
      Static3D mPoint = new Static3D(305, 380, 0);
67

  
68
      mQueues = new DistortedEffectQueues[NUM];
69
      mQueues[0] = new DistortedEffectQueues();
70
      for(int i=1; i<NUM; i++)
71
        mQueues[i] = new DistortedEffectQueues(mQueues[0], Distorted.CLONE_VERTEX|Distorted.CLONE_FRAGMENT);
72

  
73
      // Add the effects only to the first queue - all VERTEX and FRAGMENT effects are shared!
74
      // (Matrix effect cannot be shared as we have to display each Texture in a different location)
75
      mQueues[0].sink( new Static1D(8), mPoint, new Static4D(0,0,80,80));  // enlarge the nose
76
      mQueues[0].distort(dDistort,mPoint);                                 // keep moving the whole bitmap left and right.
68 77
      }
69 78

  
70 79
///////////////////////////////////////////////////////////////////////////////////////////////////
......
98 107
      
99 108
      long time = System.currentTimeMillis();
100 109
      
101
      for(int i=NUM-1; i>=0; i--) mObj[i].draw(time, mGrid);
110
      for(int i=NUM-1; i>=0; i--) mQueues[i].draw(time, mTexture[i], mGrid);
102 111
      }
103 112

  
104 113
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 116
      {  
108 117
      for(int i=NUM-1; i>=0; i--) 
109 118
        {   
110
        mObj[i].abortEffects(EffectTypes.MATRIX);
119
        mQueues[i].abortEffects(EffectTypes.MATRIX);
111 120
        }
112 121
      
113 122
      if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width )
......
117 126

  
118 127
        for(int i=NUM-1; i>=0; i--) 
119 128
          {
120
          mObj[i].move( new Static3D((width-NUM*w)/2 +i*w ,0,0) );
121
          mObj[i].scale(factor);
129
          mQueues[i].move( new Static3D((width-NUM*w)/2 +i*w ,0,0) );
130
          mQueues[i].scale(factor);
122 131
          }
123 132
        }
124 133
      else
......
129 138

  
130 139
        for(int i=NUM-1; i>=0; i--) 
131 140
          {
132
          mObj[i].move( new Static3D(i*w,(height-h)/2,0) );
133
          mObj[i].scale(factor);
141
          mQueues[i].move( new Static3D(i*w,(height-h)/2,0) );
142
          mQueues[i].scale(factor);
134 143
          }
135 144
        }
136 145
         
......
150 159
      bmpHeight = bitmap0.getHeight();
151 160
      bmpWidth  = bitmap0.getWidth();
152 161
      
153
      // create NUM DistortedBitmaps with shared effects
154
      mObj = new DistortedObject[NUM];
155
      mObj[0] = new DistortedObject(bmpWidth, bmpHeight, 1);
156
      for(int i=1; i<NUM; i++) 
157
        mObj[i] = new DistortedObject(mObj[0], Distorted.CLONE_VERTEX|Distorted.CLONE_FRAGMENT);
162
      mTexture = new DistortedTexture[NUM];
163
      for(int i=0; i<NUM; i++)
164
        mTexture[i] = new DistortedTexture(bmpWidth, bmpHeight,0);
158 165
      
159
      mObj[0].setTexture(bitmap0);
160
      mObj[1].setTexture(bitmap1);
161
      mObj[2].setTexture(bitmap2);
162
         
163
      mObj[0].sink( new Static1D(8), mPoint, new Static4D(0,0,80,80));
164
      mObj[0].distort(dDistort,mPoint);
166
      mTexture[0].setTexture(bitmap0);
167
      mTexture[1].setTexture(bitmap1);
168
      mTexture[2].setTexture(bitmap2);
165 169

  
166 170
      mGrid = new GridFlat(30,30*bmpHeight/bmpWidth);
167 171

  

Also available in: Unified diff