Project

General

Profile

« Previous | Next » 

Revision d1484aba

Added by Leszek Koltunski over 5 years ago

App: some progress changing to cube size.

View differences:

.gitignore
1 1
/build
2
distorted-cube.iml
src/main/java/org/distorted/magic/RubikRenderer.java
49 49
    private boolean mCanRotate;
50 50
    private RubikCube mCube;
51 51

  
52
    private int mScreenWidth, mScreenHeight;
53

  
52 54
///////////////////////////////////////////////////////////////////////////////////////////////////
53 55

  
54 56
    RubikRenderer(RubikSurfaceView v)
......
62 64
      mQuatCurrent     = new Static4D(0,0,0,1);
63 65
      mQuatAccumulated = initializeQuat();
64 66

  
67
      mScreenWidth = mScreenHeight = 0;
68

  
65 69
      mMove  = new Static3D(0,0,0);
66 70
      mScale = new Static3D(1,1,1);
67 71

  
......
129 133
      mScreen.setProjection( fovInDegrees, 0.1f);
130 134
      mView.setScreenSize(width,height);
131 135
      mView.setCameraDist(cameraDistance);
136
      mScreen.resize(width, height);
132 137

  
133
      mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(width>height ? height:width);
134
      float texSize = mCube.getTextureSize();
135
      float scaleFactor = mCubeSizeInScreenSpace/(texSize*mCube.getSize());
136

  
137
      mMove.set( (width-scaleFactor*texSize)/2 , (height-scaleFactor*texSize)/2 , -scaleFactor*texSize/2 );
138
      mScale.set(scaleFactor,scaleFactor,scaleFactor);
138
      recomputeScaleFactor(width,height);
139 139

  
140
      mScreen.resize(width, height);
140
      mScreenHeight = height;
141
      mScreenWidth  = width;
141 142
      }
142 143

  
143 144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
184 185

  
185 186
     if( oldSize!=newSize )
186 187
       {
187
       if( mCube!=null )
188
       mCube = new RubikCube(newSize, mMove, mScale, mQuatCurrent, mQuatAccumulated);
189
       mCube.createTexture();
190

  
191
       if( mScreenWidth!=0 )
188 192
         {
189
         mScreen.detachAll();
193
         recomputeScaleFactor(mScreenWidth,mScreenHeight);
190 194
         }
191 195

  
192
       mCube = new RubikCube(newSize, mMove, mScale, mQuatCurrent, mQuatAccumulated);
196
       mScreen.detachAll();
193 197
       mCube.attachToScreen(mScreen);
194 198
       }
195 199
     }
196 200

  
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
   void recomputeScaleFactor(int screenWidth, int screenHeight)
204
     {
205
     mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(screenWidth>screenHeight ? screenHeight:screenWidth);
206
     float texSize = mCube.getTextureSize();
207
     float scaleFactor = mCubeSizeInScreenSpace/(texSize*mCube.getSize());
208

  
209
     mMove.set( (screenWidth-scaleFactor*texSize)/2 , (screenHeight-scaleFactor*texSize)/2 , -scaleFactor*texSize/2 );
210
     mScale.set(scaleFactor,scaleFactor,scaleFactor);
211
     }
212

  
197 213
///////////////////////////////////////////////////////////////////////////////////////////////////
198 214

  
199 215
   void scrambleCube()
src/main/java/org/distorted/magic/RubikSurfaceView.java
55 55
    private Static4D mQuatCurrent, mQuatAccumulated;
56 56
    private int mRotationVect;
57 57
    private RubikRenderer mRenderer;
58
    private RubikCube mCube;
59 58

  
60 59
    private float[] mPoint, mCamera, mTouchPointCastOntoFace, mDiff, mTouchPoint; // all in screen space
61 60
    private int mLastTouchedFace;
......
82 81

  
83 82
        mRenderer = new RubikRenderer(this);
84 83
        mRenderer.createCube(RubikActivity.DEFAULT_SIZE);
85
        mCube = mRenderer.getCube();
86 84

  
87 85
        mQuatCurrent     = new Static4D(0,0,0,1);
88 86
        mQuatAccumulated = mRenderer.initializeQuat();
......
241 239
      mTouchPoint[1] = mPoint[1];
242 240
      mTouchPoint[2] = mPoint[2];
243 241

  
244
      mCube.addNewRotation(mRotationVect,offset);
242
      mRenderer.getCube().addNewRotation(mRotationVect,offset);
245 243
      }
246 244

  
247 245
///////////////////////////////////////////////////////////////////////////////////////////////////
......
266 264
      int sign = retFaceRotationSign(mLastTouchedFace);
267 265
      float angle = (mRotationVect==xAxis ? mDiff[yAxis] : -mDiff[xAxis]);
268 266

  
269
      mCube.continueRotation(SWIPING_SENSITIVITY*sign*angle/mScreenMin);
267
      mRenderer.getCube().continueRotation(SWIPING_SENSITIVITY*sign*angle/mScreenMin);
270 268
      }
271 269

  
272 270
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff