Project

General

Profile

« Previous | Next » 

Revision 0fd3ac1f

Added by Leszek Koltunski about 4 years ago

Making the Dialogs more consistent.

View differences:

src/main/java/org/distorted/magic/RubikSurfaceView.java
55 55

  
56 56
    private RubikRenderer mRenderer;
57 57
    private RubikCubeMovement mMovement;
58

  
59 58
    private boolean mInScrambleMode;
60

  
61 59
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
62 60
    private float mX, mY;
63 61
    private int mScreenWidth, mScreenHeight, mScreenMin;
......
68 66
    private static Static4D mTempCurrent    = new Static4D(0,0,0,1);
69 67
    private static Static4D mTempAccumulated= new Static4D(0,0,0,1);
70 68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
    void setScreenSize(int width, int height)
72
      {
73
      mScreenWidth = width;
74
      mScreenHeight= height;
75

  
76
      mScreenMin = width<height ? width:height;
77
      }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
    RubikRenderer getRenderer()
82
      {
83
      return mRenderer;
84
      }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
    static int getRedButton()
89
      {
90
      return mButton;
91
      }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
    void setQuatAccumulated()
96
      {
97
      mQuatAccumulated.set(mTempAccumulated);
98
      }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
    void setQuatCurrent()
103
      {
104
      mQuatCurrent.set(mTempCurrent);
105
      }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
    Static4D getQuatAccumulated()
110
      {
111
      return mQuatAccumulated;
112
      }
113

  
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

  
116
    Static4D getQuatCurrent()
117
      {
118
      return mQuatCurrent;
119
      }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
    private Static4D quatFromDrag(float dragX, float dragY)
124
      {
125
      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
126
      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
127
      float axisZ = 0;
128
      float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
129

  
130
      if( axisL>0 )
131
        {
132
        axisX /= axisL;
133
        axisY /= axisL;
134
        axisZ /= axisL;
135

  
136
        float ratio = axisL;
137
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
138

  
139
        float cosA = (float)Math.cos(Math.PI*ratio);
140
        float sinA = (float)Math.sqrt(1-cosA*cosA);
141

  
142
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
143
        }
144

  
145
      return new Static4D(0f, 0f, 0f, 1f);
146
      }
147

  
71 148
///////////////////////////////////////////////////////////////////////////////////////////////////
72 149
// return quat1*quat2
73 150

  
......
123 200
      return quatMultiply(tmp,quat);
124 201
      }
125 202

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

  
128
    void setScreenSize(int width, int height)
129
      {
130
      mScreenWidth = width;
131
      mScreenHeight= height;
132

  
133
      mScreenMin = width<height ? width:height;
134
      }
135

  
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

  
138
    RubikRenderer getRenderer()
139
      {
140
      return mRenderer;
141
      }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
    static int getRedButton()
146
      {
147
      return mButton;
148
      }
149

  
150 203
///////////////////////////////////////////////////////////////////////////////////////////////////
151 204

  
152 205
    void markButton(int button)
......
261 314
        });
262 315
      }
263 316

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
    void setQuatAccumulated()
267
      {
268
      mQuatAccumulated.set(mTempAccumulated);
269
      }
270

  
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

  
273
    void setQuatCurrent()
274
      {
275
      mQuatCurrent.set(mTempCurrent);
276
      }
277

  
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279

  
280
    Static4D getQuatAccumulated()
281
      {
282
      return mQuatAccumulated;
283
      }
284

  
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286

  
287
    Static4D getQuatCurrent()
288
      {
289
      return mQuatCurrent;
290
      }
291

  
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

  
294
    private Static4D quatFromDrag(float dragX, float dragY)
295
      {
296
      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
297
      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
298
      float axisZ = 0;
299
      float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
300

  
301
      if( axisL>0 )
302
        {
303
        axisX /= axisL;
304
        axisY /= axisL;
305
        axisZ /= axisL;
306

  
307
        float ratio = axisL;
308
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
309

  
310
        float cosA = (float)Math.cos(Math.PI*ratio);
311
        float sinA = (float)Math.sqrt(1-cosA*cosA);
312

  
313
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
314
        }
315

  
316
      return new Static4D(0f, 0f, 0f, 1f);
317
      }
318

  
319 317
///////////////////////////////////////////////////////////////////////////////////////////////////
320 318
// PUBLIC API
321 319
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff