Project

General

Profile

« Previous | Next » 

Revision 950511ed

Added by Leszek Koltunski over 8 years ago

re-add center to Vertex3D

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java
374 374
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
375 375
    layout.removeAllViews();
376 376
    mObject.abortEffects(EffectTypes.FRAGMENT);
377

  
378
    Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView);
379
    Fragment3DRenderer renderer= view.getRenderer();
380

  
381
    renderer.mQuat1.set(0,0,0,1);
382
    renderer.mQuat2.set(0,0,0,1);
377 383
    }
378 384

  
379 385
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java
69 69

  
70 70
  private ArrayList<Vertex3DEffect> mEffects;
71 71
  private int mEffectAdd;
72
  private float mCenterX, mCenterY;
72 73

  
73 74
///////////////////////////////////////////////////////////////////////////////////////////////////
74 75

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

  
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

  
206
  public void setCenter(float x, float y)
207
    {
208
    mCenterX = x;
209
    mCenterY = y;
210

  
211
    Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
212

  
213
    view.getRenderer().setCenter( mCenterX, mCenterY );
214
    }
215

  
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

  
218
  public float getCenterX()
219
    {
220
    return mCenterX;
221
    }
222

  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

  
225
  public float getCenterY()
226
    {
227
    return mCenterY;
228
    }
229

  
203 230
///////////////////////////////////////////////////////////////////////////////////////////////////
204 231

  
205 232
  public void Continue(View v)
......
289 316

  
290 317
  private void setVertexView()
291 318
    {
319
    mCenterX = 0.5f*getWidth();
320
    mCenterY = 0.5f*getHeight();
321

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

  
294 324
    setContentView(view);
......
329 359
    LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout);
330 360
    View view = eff.createView();
331 361
    layout.addView(view);
362

  
363
    if( mEffectAdd!=1 ) // deform does not support regions
364
      {
365
      View region = eff.createRegion();
366
      layout.addView(region);
367
      }
368

  
332 369
    View center = eff.createCenter();
333 370
    layout.addView(center);
334
    View region = eff.createRegion();
335
    layout.addView(region);
336 371

  
337 372
    Dynamic1D dyn1 = eff.getDyn1();
338 373
    Dynamic2D cent = eff.getCenter();
......
356 391
    LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout);
357 392
    layout.removeAllViews();
358 393
    mObject.abortEffects(EffectTypes.VERTEX);
394

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

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

  
401
    renderer.setCenter( mCenterX, mCenterY );
402
    renderer.mQuat1.set(0,0,0,1);
403
    renderer.mQuat2.set(0,0,0,1);
359 404
    }
360 405

  
361 406
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DEffect.java
67 67
    {
68 68
    Vertex3DActivity act = mAct.get();
69 69

  
70
    float x = (mInterCenter[0]*0.014f - 0.2f)*act.getWidth();
71
    float y = (mInterCenter[1]*0.014f - 0.2f)*act.getHeight();
70
    float x = (mInterCenter[0]*0.012f - 0.1f)*act.getWidth();
71
    float y = (mInterCenter[1]*0.012f - 0.1f)*act.getHeight();
72 72
    mCenterSta.set(x,y);
73

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

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

  
455
    mAct.get().setCenter(mCenterSta.getX(),mCenterSta.getY());
452 456
    }
453 457

  
454 458
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
29 29
import org.distorted.library.DistortedBitmap;
30 30
import org.distorted.library.DistortedObject;
31 31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.Dynamic3D;
32 33
import org.distorted.library.type.DynamicQuat;
33 34
import org.distorted.library.type.Static3D;
34 35
import org.distorted.library.type.Static4D;
......
46 47
    private GLSurfaceView mView;
47 48
    private DistortedObject mObject;
48 49
    private DistortedBitmap mBackground;
50
    private DistortedBitmap mCenter;
49 51
    private int mObjWidth, mObjHeight;
50 52
    private DynamicQuat mQuatInt1, mQuatInt2;
53

  
54
    private Dynamic3D mMoveInter;
55
    private Static3D mMovePoint;
56
    private float mFactorObj;
57

  
51 58
    Static4D mQuat1, mQuat2;
52 59
    int mScreenMin;
53 60

  
61

  
54 62
///////////////////////////////////////////////////////////////////////////////////////////////////
55 63

  
56 64
    public Vertex3DRenderer(GLSurfaceView v)
......
59 67

  
60 68
      mObject     = ((Vertex3DActivity)v.getContext()).getObject();
61 69
      mBackground = new DistortedBitmap(100, 100, 1);
70
      mCenter     = new DistortedBitmap(100, 100, 1);
62 71

  
63 72
      mObjWidth = mObject.getWidth();
64 73
      mObjHeight= mObject.getHeight();
......
71 80

  
72 81
      mQuatInt1.add(mQuat1);
73 82
      mQuatInt2.add(mQuat2);
83

  
84
      mMovePoint= new Static3D(0,0,0);
85
      mMoveInter= new Dynamic3D();
86
      mMoveInter.add(mMovePoint);
87
      }
88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

  
91
    public void setCenter(float x, float y)
92
      {
93
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
74 94
      }
75 95

  
76 96
///////////////////////////////////////////////////////////////////////////////////////////////////
......
84 104

  
85 105
      mBackground.draw(time);
86 106
      mObject.draw(time);
107
      mCenter.draw(time);
87 108
      }
88 109

  
89 110
///////////////////////////////////////////////////////////////////////////////////////////////////
......
94 115

  
95 116
      mObject.abortEffects(EffectTypes.MATRIX);
96 117
      mBackground.abortEffects(EffectTypes.MATRIX);
97
      float factorObj;
118
      mCenter.abortEffects(EffectTypes.MATRIX);
119

  
120
      float factorCen;
121
      int centerSize = mCenter.getWidth();
98 122

  
99 123
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
100 124
        {
101
        factorObj = (0.80f*height)/mObjHeight;
125
        mFactorObj = (0.80f*height)/mObjHeight;
126
        factorCen  = (0.08f*height)/centerSize;
102 127
        }
103 128
      else
104 129
        {
105
        factorObj = (0.80f*width)/mObjWidth;
130
        mFactorObj = (0.80f*width)/mObjWidth;
131
        factorCen  = (0.08f*width)/centerSize;
106 132
        }
107 133

  
134
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
135
      mMovePoint.set(mFactorObj*act.getCenterX(),mFactorObj*act.getCenterY(),0);
136

  
108 137
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
109 138

  
110
      mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
111
      mObject.scale(factorObj);
139
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
140
      mObject.scale(mFactorObj);
112 141
      mObject.quaternion(mQuatInt1, rotateObj);
113 142
      mObject.quaternion(mQuatInt2, rotateObj);
114 143

  
144
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
145

  
146
      mCenter.quaternion(mQuatInt1, rotateCen);
147
      mCenter.quaternion(mQuatInt2, rotateCen);
148

  
149
      mCenter.move( new Static3D( (width -factorCen*centerSize-mFactorObj*mObjWidth )/2 ,
150
                                  (height-factorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) );
151
      mCenter.move(mMoveInter);
152
      mCenter.scale(factorCen);
153

  
115 154
      int backgroundSize = mBackground.getWidth();
116 155
      float factorBackX = ((float)width)/backgroundSize;
117 156
      float factorBackY = ((float)height)/backgroundSize;
118 157

  
119
      mBackground.move(new Static3D( -width/2, -height/2,-factorObj*(mObjWidth+mObjHeight)/2) );
158
      mBackground.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) );
120 159
      mBackground.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
121 160

  
122 161
      Distorted.onSurfaceChanged(width, height);
......
130 169

  
131 170
      InputStream is1 = act.getResources().openRawResource(act.getBitmap());
132 171
      InputStream is2 = act.getResources().openRawResource(R.raw.water);
172
      InputStream is3 = act.getResources().openRawResource(R.raw.center);
133 173

  
134
      Bitmap bitmap1,bitmap2;
174
      Bitmap bitmap1,bitmap2,bitmap3;
135 175
        
136 176
      try 
137 177
        {
138 178
        bitmap1 = BitmapFactory.decodeStream(is1);
139 179
        bitmap2 = BitmapFactory.decodeStream(is2);
180
        bitmap3 = BitmapFactory.decodeStream(is3);
140 181
        }
141 182
      finally 
142 183
        {
......
144 185
          {
145 186
          is1.close();
146 187
          is2.close();
188
          is3.close();
147 189
          } 
148 190
        catch(IOException e) { }
149 191
        }  
150 192
      
151 193
      mObject.setBitmap(bitmap1);
152
      mBackground.setBitmap(bitmap2)
153
      ;
194
      mBackground.setBitmap(bitmap2);
195
      mCenter.setBitmap(bitmap3);
196

  
154 197
      try
155 198
        {
156 199
        Distorted.onSurfaceCreated(mView.getContext());
src/main/res/layout/effectcenter.xml
39 39

  
40 40
    </LinearLayout>
41 41

  
42
    <View
43
        android:layout_height="3dip"
44
        android:background="#777777"
45
        android:layout_width="match_parent"
46
        />
47

  
42 48
</LinearLayout>
src/main/res/layout/effectregion.xml
64 64

  
65 65
    </LinearLayout>
66 66

  
67

  
68
    <View
69
        android:layout_height="3dip"
70
        android:background="#777777"
71
        android:layout_width="match_parent"
72
        />
73

  
74 67
</LinearLayout>

Also available in: Unified diff