Project

General

Profile

« Previous | Next » 

Revision 75c7def3

Added by Leszek Koltunski almost 8 years ago

Fragment3D close to done now!

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DRenderer.java
54 54

  
55 55
    private GLSurfaceView mView;
56 56
    private DistortedObject mObject;
57
    private DistortedBitmap mCenter;
58 57
    private DistortedBitmap mBackground;
59
    private float mFactorCen, mFactorObj;
58
    private float mFactorObj;
60 59

  
61 60
    private int mObjWidth, mObjHeight;
62 61

  
63 62
    private DynamicQuat mQuatInt1, mQuatInt2;
64 63

  
65
    private Dynamic3D mMoveInter;
66
    private Static3D mMovePoint;
67

  
68 64
    Static4D mQuat1, mQuat2;
69 65
    int mScreenMin;
70 66

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
    public void setCenter(float x, float y)
74
      {
75
      x = (0.012f*x-0.1f)*mObjWidth;
76
      y = (0.012f*y-0.1f)*mObjHeight;
77

  
78
      mMovePoint.set(mFactorObj*x,mFactorObj*y,0);
79
      }
80

  
81 67
///////////////////////////////////////////////////////////////////////////////////////////////////
82 68

  
83 69
    public Fragment3DRenderer(GLSurfaceView v)
......
85 71
      mView = v;
86 72

  
87 73
      mObject     = ((Fragment3DActivity)v.getContext()).getObject();
88
      mCenter     = new DistortedBitmap(SIZE, SIZE, 1);
89 74
      mBackground = new DistortedBitmap(SIZE, SIZE, 1);
90 75

  
91 76
      mObjWidth = mObject.getWidth();
92 77
      mObjHeight= mObject.getHeight();
93 78

  
94
      mMovePoint= new Static3D(0,0,0);
95
      mMoveInter= new Dynamic3D();
96
      mMoveInter.add(mMovePoint);
97

  
98 79
      mQuat1 = new Static4D(0,0,0,1);  // unity
99 80
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
100 81

  
......
116 97

  
117 98
      mBackground.draw(time);
118 99
      mObject.draw(time);
119
      mCenter.draw(time);
120 100
      }
121 101

  
122 102
///////////////////////////////////////////////////////////////////////////////////////////////////
......
126 106
      mScreenMin = width<height ? width:height;
127 107

  
128 108
      mObject.abortEffects(EffectTypes.MATRIX);
129
      mCenter.abortEffects(EffectTypes.MATRIX);
130 109
      mBackground.abortEffects(EffectTypes.MATRIX);
131 110

  
132
      int centerSize = mCenter.getWidth();
133

  
134 111
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
135 112
        {
136 113
        mFactorObj = (0.70f*height)/mObjHeight;
137
        mFactorCen = (0.15f*height)/centerSize;
138 114
        }
139 115
      else
140 116
        {
141 117
        mFactorObj = (0.70f*width)/mObjWidth;
142
        mFactorCen = (0.15f*width)/centerSize;
143 118
        }
144 119

  
145
      Fragment3DActivity act = (Fragment3DActivity)mView.getContext();
146
      float cX = act.getCenterX();
147
      float cY = act.getCenterY();
148

  
149
      cX = (0.012f*cX-0.1f)*mObjWidth;
150
      cY = (0.012f*cY-0.1f)*mObjHeight;
151

  
152
      mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0);
153

  
154 120
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
155 121

  
156 122
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
......
158 124
      mObject.quaternion(mQuatInt1, rotateObj);
159 125
      mObject.quaternion(mQuatInt2, rotateObj);
160 126

  
161
      Static3D rotateCen = new Static3D(width/2,height/2, 0);
162

  
163
      mCenter.quaternion(mQuatInt1, rotateCen);
164
      mCenter.quaternion(mQuatInt2, rotateCen);
165
      mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 ,
166
                                  (height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) );
167
      mCenter.move(mMoveInter);
168
      mCenter.scale(mFactorCen);
169

  
170 127
      int backgroundSize = mBackground.getWidth();
171 128
      float factorBackX = ((float)width)/backgroundSize;
172 129
      float factorBackY = ((float)height)/backgroundSize;
......
184 141
      Fragment3DActivity act = (Fragment3DActivity)mView.getContext();
185 142

  
186 143
      InputStream is1 = act.getResources().openRawResource(act.getBitmap());
187
      InputStream is2 = act.getResources().openRawResource(R.raw.center);
188
      InputStream is3 = act.getResources().openRawResource(R.raw.water);
144
      InputStream is2 = act.getResources().openRawResource(R.raw.water);
189 145

  
190
      Bitmap bitmap1,bitmap2,bitmap3;
146
      Bitmap bitmap1,bitmap2;
191 147
        
192 148
      try 
193 149
        {
194 150
        bitmap1 = BitmapFactory.decodeStream(is1);
195 151
        bitmap2 = BitmapFactory.decodeStream(is2);
196
        bitmap3 = BitmapFactory.decodeStream(is3);
197 152
        }
198 153
      finally 
199 154
        {
......
201 156
          {
202 157
          is1.close();
203 158
          is2.close();
204
          is3.close();
205 159
          } 
206 160
        catch(IOException e) { }
207 161
        }  
208 162
      
209 163
      mObject.setBitmap(bitmap1);
210
      mCenter.setBitmap(bitmap2);
211
      mBackground.setBitmap(bitmap3)
164
      mBackground.setBitmap(bitmap2)
212 165
      ;
213 166
      try
214 167
        {

Also available in: Unified diff