Project

General

Profile

« Previous | Next » 

Revision 6f779cd4

Added by Leszek Koltunski over 8 years ago

beginnings of support for drawing the Region in Vertex3D app.

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java
362 362
      case 8: mObject.saturation(dyn1,       regi, true ); break;
363 363
      case 9: mObject.contrast  (dyn1,       regi, false); break;
364 364
      case 10:mObject.contrast  (dyn1,       regi, true ); break;
365

  
366 365
      }
367 366
    }
368 367

  
src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
70 70
  private ArrayList<Vertex3DEffect> mEffects;
71 71
  private int mEffectAdd;
72 72
  private float mCenterX, mCenterY;
73
  private float mRegionX, mRegionY, mRegionR;
73 74

  
74 75
///////////////////////////////////////////////////////////////////////////////////////////////////
75 76

  
......
201 202
    tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
202 203
    }
203 204

  
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

  
207
  public void setRegion(float x, float y, float r)
208
    {
209
    mRegionX = x;
210
    mRegionY = y;
211
    mRegionR = r;
212

  
213
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
214

  
215
    view.getRenderer().setRegion(mRegionX, mRegionY, mRegionR);
216
    }
217

  
204 218
///////////////////////////////////////////////////////////////////////////////////////////////////
205 219

  
206 220
  public void setCenter(float x, float y)
......
227 241
    return mCenterY;
228 242
    }
229 243

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

  
246
  public float getRegionX()
247
    {
248
    return mRegionX;
249
    }
250

  
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

  
253
  public float getRegionY()
254
    {
255
    return mRegionY;
256
    }
257

  
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

  
260
  public float getRegionR()
261
    {
262
    return mRegionR;
263
    }
264

  
230 265
///////////////////////////////////////////////////////////////////////////////////////////////////
231 266

  
232 267
  public void Continue(View v)
......
312 347
    }
313 348

  
314 349
///////////////////////////////////////////////////////////////////////////////////////////////////
315
// 'second screen' methods
316 350

  
317
  private void setVertexView()
351
  private void resetData()
318 352
    {
319 353
    mCenterX = 0.5f*getWidth();
320 354
    mCenterY = 0.5f*getHeight();
355
    mRegionX = 0;
356
    mRegionY = 0;
357
    mRegionR = getWidth()/2;
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
// 'second screen' methods
362

  
363
  private void setVertexView()
364
    {
365
    resetData();
321 366

  
322 367
    final View view = getLayoutInflater().inflate(R.layout.vertex3dlayout, null);
323 368

  
......
392 437
    layout.removeAllViews();
393 438
    mObject.abortEffects(EffectTypes.VERTEX);
394 439

  
395
    mCenterX = 0.5f*getWidth();
396
    mCenterY = 0.5f*getHeight();
440
    resetData();
397 441

  
398 442
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
399 443
    Vertex3DRenderer renderer= view.getRenderer();
400 444

  
401 445
    renderer.setCenter( mCenterX, mCenterY );
446
    renderer.setRegion( mRegionX, mRegionY, mRegionR );
402 447
    renderer.mQuat1.set(0,0,0,1);
403 448
    renderer.mQuat2.set(0,0,0,1);
404 449
    }
src/main/java/org/distorted/examples/vertex3d/Vertex3DEffect.java
70 70
    float x = (mInterCenter[0]*0.012f - 0.1f)*act.getWidth();
71 71
    float y = (mInterCenter[1]*0.012f - 0.1f)*act.getHeight();
72 72
    mCenterSta.set(x,y);
73

  
74
    act.setCenter(x,y);
75 73
    }
76 74

  
77 75
///////////////////////////////////////////////////////////////////////////////////////////////////
......
452 450
      setCenterText();
453 451
      }
454 452

  
455
    mAct.get().setCenter(mCenterSta.getX(),mCenterSta.getY());
453
    Vertex3DActivity act = mAct.get();
454

  
455
    act.setCenter(mCenterSta.getX(),mCenterSta.getY());
456
    act.setRegion(mRegionSta.getX(),mRegionSta.getY(), mRegionSta.getZ());
456 457
    }
457 458

  
458 459
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
48 48
    private DistortedObject mObject;
49 49
    private DistortedBitmap mBackground;
50 50
    private DistortedBitmap mCenter;
51
    private DistortedBitmap mRegion;
51 52
    private int mObjWidth, mObjHeight;
52 53
    private DynamicQuat mQuatInt1, mQuatInt2;
53 54

  
54 55
    private Dynamic3D mMoveInter;
55 56
    private Static3D mMovePoint;
56
    private float mFactorObj;
57
    private Dynamic3D mRegionScaleInter;
58
    private Static3D mRegionScalePoint;
59

  
60
    private float mFactorObj, mFactorReg;
57 61

  
58 62
    Static4D mQuat1, mQuat2;
59 63
    int mScreenMin;
60 64

  
61

  
62 65
///////////////////////////////////////////////////////////////////////////////////////////////////
63 66

  
64 67
    public Vertex3DRenderer(GLSurfaceView v)
......
68 71
      mObject     = ((Vertex3DActivity)v.getContext()).getObject();
69 72
      mBackground = new DistortedBitmap(100, 100, 1);
70 73
      mCenter     = new DistortedBitmap(100, 100, 1);
74
      mRegion     = new DistortedBitmap(100, 100, 1);
71 75

  
72 76
      mObjWidth = mObject.getWidth();
73 77
      mObjHeight= mObject.getHeight();
......
81 85
      mQuatInt1.add(mQuat1);
82 86
      mQuatInt2.add(mQuat2);
83 87

  
84
      mMovePoint= new Static3D(0,0,0);
85 88
      mMoveInter= new Dynamic3D();
89
      mMovePoint= new Static3D(0,0,0);
86 90
      mMoveInter.add(mMovePoint);
91

  
92
      mRegionScaleInter = new Dynamic3D();
93
      mRegionScalePoint = new Static3D(0,0,0);
94
      mRegionScaleInter.add(mRegionScalePoint);
87 95
      }
88 96

  
89 97
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 101
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
94 102
      }
95 103

  
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

  
106
    public void setRegion(float x, float y, float r)
107
      {
108
      float f = mFactorReg*r;
109
      mRegionScalePoint.set(f,f,f);
110
      }
111

  
96 112
///////////////////////////////////////////////////////////////////////////////////////////////////
97 113

  
98 114
    public void onDrawFrame(GL10 glUnused)
......
105 121
      mBackground.draw(time);
106 122
      mObject.draw(time);
107 123
      mCenter.draw(time);
124
      mRegion.draw(time);
108 125
      }
109 126

  
110 127
///////////////////////////////////////////////////////////////////////////////////////////////////
......
116 133
      mObject.abortEffects(EffectTypes.MATRIX);
117 134
      mBackground.abortEffects(EffectTypes.MATRIX);
118 135
      mCenter.abortEffects(EffectTypes.MATRIX);
136
      mRegion.abortEffects(EffectTypes.MATRIX);
119 137

  
120 138
      float factorCen;
121 139
      int centerSize = mCenter.getWidth();
140
      int regionSize = mRegion.getWidth();
141

  
142
      mFactorReg = (0.5f*width)/regionSize;
122 143

  
123 144
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
124 145
        {
......
133 154

  
134 155
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
135 156
      mMovePoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0);
157
      float f = mFactorReg*act.getRegionR();
158
      mRegionScalePoint.set(f,f,f);
136 159

  
137 160
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
138 161

  
......
151 174
      mCenter.move(mMoveInter);
152 175
      mCenter.scale(factorCen);
153 176

  
177
      mRegion.quaternion(mQuatInt1, rotateCen);
178
      mRegion.quaternion(mQuatInt2, rotateCen);
179

  
180
      mRegion.move( new Static3D( (width -mFactorReg*regionSize-mFactorObj*mObjWidth )/2 ,
181
                                  (height-mFactorReg*regionSize-mFactorObj*mObjHeight)/2 , 12) );
182
      mRegion.move(mMoveInter);
183
      mRegion.scale(mRegionScaleInter);
184

  
154 185
      int backgroundSize = mBackground.getWidth();
155 186
      float factorBackX = ((float)width)/backgroundSize;
156 187
      float factorBackY = ((float)height)/backgroundSize;
......
170 201
      InputStream is1 = act.getResources().openRawResource(act.getBitmap());
171 202
      InputStream is2 = act.getResources().openRawResource(R.raw.water);
172 203
      InputStream is3 = act.getResources().openRawResource(R.raw.center);
204
      InputStream is4 = act.getResources().openRawResource(R.raw.region);
173 205

  
174
      Bitmap bitmap1,bitmap2,bitmap3;
206
      Bitmap bitmap1,bitmap2,bitmap3,bitmap4;
175 207
        
176 208
      try 
177 209
        {
178 210
        bitmap1 = BitmapFactory.decodeStream(is1);
179 211
        bitmap2 = BitmapFactory.decodeStream(is2);
180 212
        bitmap3 = BitmapFactory.decodeStream(is3);
213
        bitmap4 = BitmapFactory.decodeStream(is4);
181 214
        }
182 215
      finally 
183 216
        {
......
186 219
          is1.close();
187 220
          is2.close();
188 221
          is3.close();
222
          is4.close();
189 223
          } 
190 224
        catch(IOException e) { }
191 225
        }  
......
193 227
      mObject.setBitmap(bitmap1);
194 228
      mBackground.setBitmap(bitmap2);
195 229
      mCenter.setBitmap(bitmap3);
230
      mRegion.setBitmap(bitmap4);
196 231

  
197 232
      try
198 233
        {

Also available in: Unified diff