Project

General

Profile

« Previous | Next » 

Revision 57ef6378

Added by Leszek Koltunski over 2 years ago

Float vertices - scratchbook

View differences:

src/main/java/org/distorted/objectlib/main/ObjectControl.java
27 27
import android.view.MotionEvent;
28 28

  
29 29
import org.distorted.library.main.QuatHelper;
30
import org.distorted.library.type.Static2D;
31 30
import org.distorted.library.type.Static4D;
32 31

  
33 32
import org.distorted.objectlib.helpers.BlockController;
......
64 63

  
65 64
    private float mRotAngle, mInitDistance;
66 65
    private float mStartRotX, mStartRotY;
67
    private float mAxisX, mAxisY;
68 66
    private float mRotationFactor;
69 67
    private int mLastCubitColor, mLastCubit;
70 68
    private int mCurrentAxis, mCurrentRow;
......
80 78
    private final boolean mIsAutomatic;
81 79

  
82 80
    private boolean mIsLocked, mRemLocked;
81
    private final int[] mBuffer;
82
    private final float[] mAxis;
83 83

  
84 84
    private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
85 85
    private static final Static4D mTemp= new Static4D(0,0,0,1);
86 86

  
87 87
    private static boolean mForcedIconMode = false;
88 88

  
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
91
// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
92

  
93
    private void computeCurrentAxis(Static4D axis)
94
      {
95
      Static4D result = QuatHelper.rotateVectorByQuat(axis, mQuat);
96

  
97
      mAxisX =result.get0();
98
      mAxisY =result.get1();
99

  
100
      float len = (float)Math.sqrt(mAxisX*mAxisX + mAxisY*mAxisY);
101
      mAxisX /= len;
102
      mAxisY /= len;
103
      }
104

  
105 89
///////////////////////////////////////////////////////////////////////////////////////////////////
106 90

  
107 91
    private void addSpeedProbe(float x, float y)
......
162 146

  
163 147
///////////////////////////////////////////////////////////////////////////////////////////////////
164 148

  
165
    private void replaceMode(TwistyObject object, boolean down)
149
    private void replaceMode(boolean down)
166 150
      {
167 151
      mBeginningRotation= false;
168 152

  
......
170 154
        {
171 155
        int color = mInterface.getCurrentColor();
172 156
        float[] point = mTouchControl.getTouchedPoint3D();
157
        TwistyObject object = mPreRender.getObject();
173 158
        mLastCubit = object.getCubit(point);
174 159
        mLastCubitColor = mInterface.cubitIsLocked(mLastCubit);
175 160
        int face;
......
213 198
        }
214 199
      else
215 200
        {
216
        TwistyObject object = mPreRender.getObject();
217
        CAMERA_POINT.set2( object==null ? 1.21f : mObjectNode.getCameraDist() );
218

  
201
        CAMERA_POINT.set2( mObjectNode.getCameraDist() );
219 202
        Static4D touchPoint = new Static4D(x, y, 0, 0);
220 203
        Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
221 204
        Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
222 205

  
223
        if( object!=null && mTouchControl !=null && mTouchControl.faceTouched(rotatedTouchPoint,rotatedCamera) )
206
        if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
224 207
          {
225 208
          mDragging           = false;
226 209
          mContinuingRotation = false;
227 210

  
228
          if( mode==MODE_ROTATE )
229
            {
230
            mBeginningRotation= !mPreRender.isTouchBlocked();
231
            }
232
          else if( mode==MODE_REPLACE ) replaceMode(object,down);
211
               if( mode==MODE_ROTATE  ) mBeginningRotation = !mPreRender.isTouchBlocked();
212
          else if( mode==MODE_REPLACE ) replaceMode(down);
233 213
          }
234 214
        else
235 215
          {
......
311 291
      {
312 292
      float dx = x-mStartRotX;
313 293
      float dy = y-mStartRotY;
314
      float alpha = dx*mAxisX + dy*mAxisY;
315
      float x2 = dx - alpha*mAxisX;
316
      float y2 = dy - alpha*mAxisY;
294
      float alpha = dx*mAxis[0] + dy*mAxis[1];
295
      float x2 = dx - alpha*mAxis[0];
296
      float y2 = dy - alpha*mAxis[1];
317 297

  
318 298
      float len = (float)Math.sqrt(x2*x2 + y2*y2);
319 299

  
320 300
      // we have the length of 1D vector 'angle', now the direction:
321
      float tmp = mAxisY==0 ? -mAxisX*y2 : mAxisY*x2;
301
      float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
322 302

  
323 303
      float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
324 304
      mCurrentAngle = SWIPING_SENSITIVITY*angle;
......
339 319

  
340 320
      Static4D touchPoint = new Static4D(x, y, 0, 0);
341 321
      Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
342
      Static2D res = mTouchControl.newRotation(rotatedTouchPoint);
322
      mTouchControl.newRotation(mBuffer,rotatedTouchPoint);
343 323

  
344
      mCurrentAxis = (int)res.get0();
345
      mCurrentRow  = (int)res.get1();
324
      mCurrentAxis = mBuffer[0];
325
      mCurrentRow  = mBuffer[1];
346 326

  
347
      computeCurrentAxis( mTouchControl.getCastedRotAxis(mCurrentAxis) );
327
      mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
348 328
      mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
349 329

  
350 330
      object.beginNewRotation( mCurrentAxis, mCurrentRow );
......
573 553
      {
574 554
      mIsAutomatic = false;
575 555

  
556
      mBuffer = new int[2];
557
      mAxis   = new float[2];
558

  
576 559
      mLastCubitColor = -1;
577 560
      mCurrRotSpeed   = 0.0f;
578 561

  

Also available in: Unified diff