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/effects3d/Effects3DRenderer.java
26 26

  
27 27
import org.distorted.examples.R;
28 28
import org.distorted.library.Distorted;
29
import org.distorted.library.DistortedTexture;
29 30
import org.distorted.library.GridFlat;
30
import org.distorted.library.DistortedObject;
31
import org.distorted.library.DistortedEffectQueues;
31 32
import org.distorted.library.GridObject;
32 33
import org.distorted.library.EffectTypes;
33 34
import org.distorted.library.type.Dynamic3D;
......
46 47
class Effects3DRenderer implements GLSurfaceView.Renderer
47 48
{
48 49
    private GLSurfaceView mView;
49
    private DistortedObject mObject;
50
    private DistortedObject mBackground;
51
    private DistortedObject mCenter;
52
    private DistortedObject mRegion;
50
    private DistortedTexture mObjectTexture, mBackgroundTexture, mCenterTexture, mRegionTexture;
51
    private DistortedEffectQueues mObjectQueues, mBackgroundQueues, mCenterQueues, mRegionQueues;
53 52
    private GridFlat mQuad;
54
    private GridObject mGrid;
53
    private GridObject mObjectGrid;
55 54
    private int mObjWidth, mObjHeight, mObjDepth;
56 55
    private DynamicQuat mQuatInt1, mQuatInt2;
57 56

  
......
73 72

  
74 73
      Effects3DActivity act = (Effects3DActivity)v.getContext();
75 74

  
76
      mObject     = act.getObject();
77
      mGrid       = act.getGrid();
78
      mBackground = new DistortedObject(100, 100, 1);
79
      mCenter     = new DistortedObject(100, 100, 1);
80
      mRegion     = new DistortedObject(100, 100, 1);
81
      mQuad       = new GridFlat(1,1);
82

  
83
      mObjWidth = mObject.getWidth();
84
      mObjHeight= mObject.getHeight();
85
      mObjDepth = mObject.getDepth();
75
      mObjectTexture     = act.getTexture();
76
      mObjectGrid        = act.getGrid();
77
      mObjectQueues      = act.getQueues();
78
      mBackgroundTexture = new DistortedTexture(100, 100, 0);
79
      mCenterTexture     = new DistortedTexture(100, 100, 0);
80
      mRegionTexture     = new DistortedTexture(100, 100, 0);
81
      mQuad              = new GridFlat(1,1);
82
      mBackgroundQueues  = new DistortedEffectQueues();
83
      mCenterQueues      = new DistortedEffectQueues();
84
      mRegionQueues      = new DistortedEffectQueues();
85

  
86
      mObjWidth = mObjectTexture.getWidth();
87
      mObjHeight= mObjectTexture.getHeight();
88
      mObjDepth = mObjectTexture.getDepth();
86 89

  
87 90
      mQuat1 = new Static4D(0,0,0,1);  // unity
88 91
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
......
117 120

  
118 121
    void setRegion(float x, float y, float r)
119 122
      {
120
      mFactorReg = 2*mFactorObj*r/mRegion.getWidth();
123
      mFactorReg = 2*mFactorObj*r/mRegionTexture.getWidth();
121 124
      mRegionPoint.set(mFactorObj*x,mFactorObj*y,0);
122 125
      mRegionScalePoint.set(mFactorReg,mFactorReg,mFactorReg);
123 126
      }
......
130 133

  
131 134
      long time = System.currentTimeMillis();
132 135

  
133
      mBackground.draw(time,mQuad);
134
      mObject.draw(time,mGrid);
136
      mBackgroundQueues.draw(time,mBackgroundTexture,mQuad);
137
      mObjectQueues.draw(time,mObjectTexture,mObjectGrid);
135 138

  
136 139
      if( Effects3DActivity.supportsCenter() )
137 140
        {
138
        mCenter.draw(time, mQuad);
139
        if( Effects3DActivity.supportsRegion() ) mRegion.draw(time, mQuad);
141
        mCenterQueues.draw(time, mCenterTexture,mQuad);
142
        if( Effects3DActivity.supportsRegion() ) mRegionQueues.draw(time, mRegionTexture,mQuad);
140 143
        }
141 144
      }
142 145

  
......
146 149
      {
147 150
      mScreenMin = width<height ? width:height;
148 151

  
149
      mObject.abortEffects(EffectTypes.MATRIX);
150
      mBackground.abortEffects(EffectTypes.MATRIX);
151
      mCenter.abortEffects(EffectTypes.MATRIX);
152
      mRegion.abortEffects(EffectTypes.MATRIX);
152
      mObjectQueues.abortEffects(EffectTypes.MATRIX);
153
      mBackgroundQueues.abortEffects(EffectTypes.MATRIX);
154
      mCenterQueues.abortEffects(EffectTypes.MATRIX);
155
      mRegionQueues.abortEffects(EffectTypes.MATRIX);
153 156

  
154 157
      float factorCen;
155
      int centerSize = mCenter.getWidth();
156
      int regionSize = mRegion.getWidth();
158
      int centerSize = mCenterTexture.getWidth();
159
      int regionSize = mRegionTexture.getWidth();
157 160

  
158 161
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
159 162
        {
......
175 178

  
176 179
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
177 180

  
178
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
179
      mObject.scale(mFactorObj);
180
      mObject.quaternion(mQuatInt1, rotateObj);
181
      mObject.quaternion(mQuatInt2, rotateObj);
181
      mObjectQueues.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
182
      mObjectQueues.scale(mFactorObj);
183
      mObjectQueues.quaternion(mQuatInt1, rotateObj);
184
      mObjectQueues.quaternion(mQuatInt2, rotateObj);
182 185

  
183 186
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
184 187

  
185
      mCenter.quaternion(mQuatInt1, rotateCen);
186
      mCenter.quaternion(mQuatInt2, rotateCen);
188
      mCenterQueues.quaternion(mQuatInt1, rotateCen);
189
      mCenterQueues.quaternion(mQuatInt2, rotateCen);
187 190

  
188
      mCenter.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
191
      mCenterQueues.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
189 192
                                  (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , mFactorObj*mObjDepth/2+10) );
190
      mCenter.move(mCenterInter);
191
      mCenter.scale(factorCen);
193
      mCenterQueues.move(mCenterInter);
194
      mCenterQueues.scale(factorCen);
192 195

  
193
      mRegion.quaternion(mQuatInt1, rotateCen);
194
      mRegion.quaternion(mQuatInt2, rotateCen);
196
      mRegionQueues.quaternion(mQuatInt1, rotateCen);
197
      mRegionQueues.quaternion(mQuatInt2, rotateCen);
195 198

  
196
      mRegion.move( new Static3D( (width -mFactorObj*mObjWidth )/2 ,
199
      mRegionQueues.move( new Static3D( (width -mFactorObj*mObjWidth )/2 ,
197 200
                                  (height-mFactorObj*mObjHeight)/2 , mFactorObj*mObjDepth/2+12) );
198
      mRegion.move(mCenterInter);
199
      mRegion.move(mRegionInter);
200
      mRegion.scale(mRegionScaleInter);
201
      mRegion.move( new Static3D( -regionSize/2 , -regionSize/2 , 0) );
201
      mRegionQueues.move(mCenterInter);
202
      mRegionQueues.move(mRegionInter);
203
      mRegionQueues.scale(mRegionScaleInter);
204
      mRegionQueues.move( new Static3D( -regionSize/2 , -regionSize/2 , 0) );
202 205

  
203
      int backgroundSize = mBackground.getWidth();
206
      int backgroundSize = mBackgroundTexture.getWidth();
204 207
      float factorBackX = ((float)width)/backgroundSize;
205 208
      float factorBackY = ((float)height)/backgroundSize;
206 209

  
207
      mBackground.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) );
208
      mBackground.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
210
      mBackgroundQueues.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) );
211
      mBackgroundQueues.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
209 212

  
210 213
      Distorted.onSurfaceChanged(width, height);
211 214
      }
......
218 221

  
219 222
      Effects3DActivity act = (Effects3DActivity)mView.getContext();
220 223

  
221
      InputStream is1 = act.getResources().openRawResource(R.raw.water);
222
      InputStream is2 = act.getResources().openRawResource(R.raw.center);
223
      InputStream is3 = act.getResources().openRawResource(R.raw.region);
224
      InputStream isB = act.getResources().openRawResource(R.raw.water);
225
      InputStream isC = act.getResources().openRawResource(R.raw.center);
226
      InputStream isR = act.getResources().openRawResource(R.raw.region);
224 227

  
225
      Bitmap bitmap1,bitmap2,bitmap3;
228
      Bitmap bitmapB,bitmapC,bitmapR;
226 229
        
227 230
      try 
228 231
        {
229
        bitmap1 = BitmapFactory.decodeStream(is1);
230
        bitmap2 = BitmapFactory.decodeStream(is2);
231
        bitmap3 = BitmapFactory.decodeStream(is3);
232
        bitmapB = BitmapFactory.decodeStream(isB);
233
        bitmapC = BitmapFactory.decodeStream(isC);
234
        bitmapR = BitmapFactory.decodeStream(isR);
232 235
        }
233 236
      finally 
234 237
        {
235 238
        try 
236 239
          {
237
          is1.close();
238
          is2.close();
239
          is3.close();
240
          isB.close();
241
          isC.close();
242
          isR.close();
240 243
          }
241 244
        catch(IOException e) { }
242 245
        }  
243 246
      
244
      mObject.setTexture( act.getBitmap() );
245
      mBackground.setTexture(bitmap1);
246
      mCenter.setTexture(bitmap2);
247
      mRegion.setTexture(bitmap3);
247
      mObjectTexture.setTexture( act.getBitmap() );
248
      mBackgroundTexture.setTexture(bitmapB);
249
      mCenterTexture.setTexture(bitmapC);
250
      mRegionTexture.setTexture(bitmapR);
248 251

  
249 252
      try
250 253
        {

Also available in: Unified diff