Project

General

Profile

« Previous | Next » 

Revision 7aa4c349

Added by Leszek Koltunski almost 3 years ago

Progress with RubikControl.

View differences:

src/main/java/org/distorted/control/RubikControlRotate.java
55 55

  
56 56
  private void computeInitQuat()
57 57
    {
58
    final double alphaZ = Math.PI/8;
59
    final double alphaY = Math.PI/16;
58
    double alphaZ = -Math.PI* 0.1250f;
59
    double alphaY = -Math.PI* 0.0625f;
60

  
61
    alphaY /= 2;
62
    alphaZ /= 2;
60 63

  
61 64
    float sinZ = (float)Math.sin(alphaZ);
62 65
    float cosZ = (float)Math.cos(alphaZ);
......
70 73
    }
71 74

  
72 75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// Take 3D vector 'ax', rotate it by quaternion 'objQuat' to get vector V1.
77
// Take 3D vector (1,0,0) and rotate it by INIT_QUAT to get vector V2.
78
// Return a quaternion Q such that if we rotate V1 by Q, we get V2.
73 79

  
74
  private Static4D computeQuat(Static3D ax)
80
  private Static4D computeQuat(Static3D ax, Static4D objQuat, float x, float y, float z)
75 81
    {
76
    return null;
82
    Static4D ax4D = new Static4D( ax.get0(), ax.get1(), ax.get2(), 0);
83
    Static4D axRo = QuatHelper.rotateVectorByQuat(ax4D,objQuat);
84
    return QuatHelper.retRotationQuat(axRo.get0(),axRo.get1(),axRo.get2(),x,y,z);
77 85
    }
78 86

  
79 87
///////////////////////////////////////////////////////////////////////////////////////////////////
......
82 90
    {
83 91
    TwistyObject object = mControl.getObject();
84 92
    Static3D[] axis = object.getRotationAxis();
93
    int chosen=-1,numAxis = axis.length;
85 94
    float cos,maxCos = -1.0f;
86 95
    Static4D quat;
87 96

  
88
    for (Static3D axi : axis)
97
    Static4D objCurrQuat = mControl.getCurrQuat();
98
    Static4D axisX = new Static4D(1,0,0,0);
99
    Static4D rotAxisX = QuatHelper.rotateVectorByQuat(axisX,INIT_QUAT);
100

  
101
    float axX = rotAxisX.get0();
102
    float axY = rotAxisX.get1();
103
    float axZ = rotAxisX.get2();
104

  
105
    for (int a=0; a<numAxis; a++)
89 106
      {
90
      quat = computeQuat(axi);
107
      quat = computeQuat(axis[a],objCurrQuat,axX,axY,axZ);
91 108
      cos = quat.get3();
92 109

  
93 110
      if (cos > maxCos)
94 111
        {
95 112
        maxCos = cos;
113
        chosen = a;
96 114
        mObjRotQuat = quat;
97 115
        }
98 116
      }
117

  
118
    android.util.Log.e("D", "axis chosen: "+chosen);
99 119
    }
100 120

  
101 121
///////////////////////////////////////////////////////////////////////////////////////////////////
......
110 130

  
111 131
  private void setObjectEffectsStage1()
112 132
    {
113
    // TODO
133
    mDynamic.resetToBeginning();
134
    mScale.notifyWhenFinished(mControl);
114 135
    }
115 136

  
116 137
///////////////////////////////////////////////////////////////////////////////////////////////////
......
186 207
      mObjectQuad = new MeshQuad();
187 208
      }
188 209

  
189
    if( INIT_QUAT==null )
190
      {
191
      computeInitQuat();
192
      computeRotQuat();
193
      }
210
    if( INIT_QUAT==null ) computeInitQuat();
211

  
212
    computeRotQuat();
194 213

  
195 214
    DistortedTexture texture = new DistortedTexture();
196 215
    texture.setColorARGB(0xff00ff00);

Also available in: Unified diff