Project

General

Profile

« Previous | Next » 

Revision d2337a3a

Added by Leszek Koltunski almost 8 years ago

Progress with Vertex3D

View differences:

src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java
50 50

  
51 51
class Vertex3DRenderer implements GLSurfaceView.Renderer
52 52
{
53
    public static final int SIZE = 100;
53
    private static final int SIZE = 100;
54 54

  
55 55
    private GLSurfaceView mView;
56
    private static DistortedObject mObject;
56
    private DistortedObject mObject;
57 57
    private DistortedBitmap mCenter;
58
    private int mCols;
58
    private float mFactorCen, mFactorObj;
59 59

  
60 60
    private int mObjWidth, mObjHeight;
61 61

  
62 62
    private DynamicQuat mQuatInt1, mQuatInt2;
63 63

  
64
    private static EffectNames[] order;
64
    private EffectNames[] order;
65 65

  
66
    private static Dynamic2D mCenterInter;
67
    private static Dynamic3D mDeformInter, mDistortInter, mMoveInter;
68
    private static Dynamic1D mSinkInter, mSwirlInter;
66
    private Dynamic2D mCenterInter;
67
    private Dynamic3D mDeformInter, mDistortInter, mMoveInter;
68
    private Dynamic1D mSinkInter, mSwirlInter;
69 69

  
70
    private static Static2D mCenterPoint;
71
    private static Static3D mDeformPoint, mDistortPoint, mMovePoint;
72
    private static Static1D mSinkPoint, mSwirlPoint;
70
    private Static2D mCenterPoint;
71
    private Static3D mDeformPoint, mDistortPoint, mMovePoint;
72
    private Static1D mSinkPoint, mSwirlPoint;
73 73

  
74 74
    Static4D mQuat1, mQuat2;
75
    static int mScreenMin;
75
    int mScreenMin;
76 76

  
77 77
///////////////////////////////////////////////////////////////////////////////////////////////////
78 78

  
79
    public static void setDeform(float x, float y, float z)
79
    public void setDeform(float x, float y, float z)
80 80
      {
81 81
      mDeformPoint.set(x, y, z);
82 82
      }
83 83
    
84 84
///////////////////////////////////////////////////////////////////////////////////////////////////
85 85

  
86
    public static void setDistort(float x, float y, float z)
86
    public void setDistort(float x, float y, float z)
87 87
      {
88 88
      mDistortPoint.set(x, y, z);
89 89
      }
90 90
     
91 91
///////////////////////////////////////////////////////////////////////////////////////////////////
92 92

  
93
    public static void setSink(float s)
93
    public void setSink(float s)
94 94
      {
95 95
      mSinkPoint.set(s);
96 96
      }
97 97
    
98 98
///////////////////////////////////////////////////////////////////////////////////////////////////
99 99

  
100
    public static void setSwirl(float s)
100
    public void setSwirl(float s)
101 101
      {
102 102
      mSwirlPoint.set(s);
103 103
      }
104 104

  
105 105
///////////////////////////////////////////////////////////////////////////////////////////////////
106 106

  
107
    public static void setCenter(float x, float y)
107
    public void setCenter(float x, float y)
108 108
      {
109
      x = (0.012f*x-0.1f)*mObjWidth;
110
      y = (0.012f*y-0.1f)*mObjHeight;
111

  
109 112
      mCenterPoint.set(x,y);
110
      mMovePoint.set(x,y,0);
113
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
111 114
      }
112 115

  
113 116
///////////////////////////////////////////////////////////////////////////////////////////////////
114 117

  
115
    public static void setOrder(EffectNames[] effects)
118
    public void setOrder(EffectNames[] effects)
116 119
      {
117 120
      order = effects;
118 121
      setVertexEffects();
......
120 123
      
121 124
///////////////////////////////////////////////////////////////////////////////////////////////////
122 125

  
123
    public static void setVertexEffects()
126
    public void setVertexEffects()
124 127
      {
125 128
      mObject.abortEffects(EffectTypes.VERTEX);
126 129

  
......
142 145
      {
143 146
      mView = v;
144 147

  
145
      mCols = Vertex3DActivity.getCols();
146

  
147
      mObject = new DistortedCubes( mCols, Vertex3DActivity.getShape(), SIZE);
148
      mObject = new DistortedCubes( Vertex3DActivity.getCols(), Vertex3DActivity.getShape(), SIZE);
148 149
      //mObject = new DistortedBitmap( SIZE, SIZE, 10);
149 150
      mCenter = new DistortedBitmap(SIZE, SIZE, 1);
150 151

  
......
204 205
      mObject.abortEffects(EffectTypes.MATRIX);
205 206
      mCenter.abortEffects(EffectTypes.MATRIX);
206 207

  
207
      float factorObj;
208
      int centerSize = mCenter.getWidth();
208 209

  
209 210
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
210 211
        {
211
        factorObj = (0.7f*height)/mObjHeight;
212
        mFactorObj = (0.70f*height)/mObjHeight;
213
        mFactorCen = (0.15f*height)/centerSize;
212 214
        }
213 215
      else
214 216
        {
215
        factorObj = (0.7f*width)/mObjWidth;
217
        mFactorObj = (0.70f*width)/mObjWidth;
218
        mFactorCen = (0.15f*width)/centerSize;
216 219
        }
217 220

  
221
      Vertex3DActivity act = (Vertex3DActivity)mView.getContext();
222
      float cX = act.getCenterX();
223
      float cY = act.getCenterY();
224

  
225
      cX = (0.012f*cX-0.1f)*mObjWidth;
226
      cY = (0.012f*cY-0.1f)*mObjHeight;
227

  
228
      mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0);
229

  
218 230
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
219 231

  
220
      mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
221
      mObject.scale(factorObj);
232
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
233
      mObject.scale(mFactorObj);
222 234
      mObject.quaternion(mQuatInt1, rotateObj);
223 235
      mObject.quaternion(mQuatInt2, rotateObj);
224 236

  
225
      int centerSize = mCenter.getWidth();
226 237
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
227 238

  
228
      float factorCen = (float)(mCols*SIZE) / (5*centerSize);  // make the 'center' bitmap 1/5 of the Object's width
229

  
230 239
      mCenter.quaternion(mQuatInt1, rotateCen);
231 240
      mCenter.quaternion(mQuatInt2, rotateCen);
232
      mCenter.move( new Static3D( (width -factorCen*centerSize-factorObj*mObjWidth )/2 ,
233
                                  (height-factorCen*centerSize-factorObj*mObjHeight)/2 , 10) );
241
      mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 ,
242
                                  (height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) );
234 243
      mCenter.move(mMoveInter);
235
      mCenter.scale(factorCen);
244
      mCenter.scale(mFactorCen);
236 245

  
237 246
      setVertexEffects();
238 247

  

Also available in: Unified diff