Project

General

Profile

« Previous | Next » 

Revision 6f779cd4

Added by Leszek Koltunski almost 8 years ago

beginnings of support for drawing the Region in Vertex3D app.

View differences:

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