Project

General

Profile

« Previous | Next » 

Revision 52375039

Added by Leszek Koltunski about 2 months ago

improvement

View differences:

src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
9 9

  
10 10
package org.distorted.objectlib.touchcontrol;
11 11

  
12
import org.distorted.library.helpers.QuatHelper;
12 13
import org.distorted.library.type.Static4D;
13 14
import org.distorted.objectlib.main.TwistyObject;
14 15

  
......
204 205
      }
205 206
    }
206 207

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

  
212
  void getCastedRotAxis(float[] output, Static4D quat, float x, float y, float z, float w)
213
    {
214
    Static4D result = QuatHelper.rotateVectorByQuat(x,y,z,w, quat);
215

  
216
    float cx = result.get0();
217
    float cy = result.get1();
218
    float len= (float)Math.sqrt(cx*cx+cy*cy);
219

  
220
    if( len!=0 )
221
      {
222
      output[0] = cx/len;
223
      output[1] = cy/len;
224
      }
225
    else
226
      {
227
      output[0] = 1;
228
      output[1] = 0;
229
      }
230
    }
231

  
207 232
///////////////////////////////////////////////////////////////////////////////////////////////////
208 233

  
209 234
  public abstract boolean objectTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera);
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.java
336 336
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
337 337
    {
338 338
    Static3D a = mRotAxis[axisIndex];
339
    Static4D result = QuatHelper.rotateVectorByQuat(a.get0(),a.get1(),a.get2(),0,quat);
340

  
341
    float cx = result.get0();
342
    float cy = result.get1();
343
    float len= (float)Math.sqrt(cx*cx+cy*cy);
344

  
345
    if( len!=0 )
346
      {
347
      output[0] = cx/len;
348
      output[1] = cy/len;
349
      }
350
    else
351
      {
352
      output[0] = 1;
353
      output[1] = 0;
354
      }
339
    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),0);
355 340
    }
356 341

  
357 342
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
97 97
  // end FaceInfo
98 98

  
99 99
  private final float[] mTouch, mLastT;
100
  private final Static4D mTmpAxis;
101 100
  private int mNumCubits;
102 101
  private int[] mNumFaces;
103 102
  private boolean mPreparationDone;
......
123 122
    mLastT = new float[3];
124 123
    mObject= object;
125 124
    mPreparationDone = false;
126
    mTmpAxis = new Static4D(0,0,0,0);
127 125
    mGhostAxisEnabled = -1;
128 126

  
129 127
    if( object!=null )
......
717 715

  
718 716
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
719 717
    {
720
    Static3D rotAxis = mRotAxis[axisIndex];
721
    float rx = rotAxis.get0();
722
    float ry = rotAxis.get1();
723
    float rz = rotAxis.get2();
724

  
725
    mTmpAxis.set(rx,ry,rz,0);
726
    Static4D result = QuatHelper.rotateVectorByQuat(mTmpAxis, quat);
727

  
728
    float cx =result.get0();
729
    float cy =result.get1();
730

  
731
    float len = (float)Math.sqrt(cx*cx+cy*cy);
732

  
733
    if( len!=0 )
734
      {
735
      output[0] = cx/len;
736
      output[1] = cy/len;
737
      }
738
    else
739
      {
740
      output[0] = 1;
741
      output[1] = 0;
742
      }
718
    Static3D a = mRotAxis[axisIndex];
719
    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),0);
743 720
    }
744 721

  
745 722
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java
350 350

  
351 351
  public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
352 352
    {
353
    Static4D axis = mCastedRotAxis4D[mLastTouchedFace][axisIndex];
354
    Static4D result = QuatHelper.rotateVectorByQuat(axis, quat);
355

  
356
    output[0] =result.get0();
357
    output[1] =result.get1();
358

  
359
    float len = (float)Math.sqrt(output[0]*output[0] + output[1]*output[1]);
360

  
361
    if( len!=0 )
362
      {
363
      output[0] /= len;
364
      output[1] /= len;
365
      }
353
    Static4D a = mCastedRotAxis4D[mLastTouchedFace][axisIndex];
354
    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),a.get3());
366 355
    }
367 356

  
368 357
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff