android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转
我一直在嘗試為Android做魔方.我有一個關于輪換的問題.我想旋轉一個外觀正確的圖形.這意味著如果用戶觸摸屏,并且在將手指向右移動之后,圖形將從觀察點的一側向右旋轉.但是當我旋轉一些時,圖形開始朝不正確的方向移動.我了解,這取決于軸是否改變了他們的狀況.但是我嘗試使用逆模型矩陣來獲取必要的坐標,但尚未得到結果.有人可以在鼠標或觸摸屏的幫助下給我示例或視覺上正確旋轉3D圖形的鏈接嗎?
//get vector 3D of touch
Vector3f touchVector = getRubikSystemCoordinates(mTouchX,mTouchY,square.rubikRotationMatrix);
//Get vector 3D of move
Vector3f moveVector = getRubikSystemCoordinates(mMoveX,mMoveY,square.rubikRotationMatrix);
//get direction of motion
float direction = touchVector.substractFrom(moveVector);
//get axis for rotation
Vector3f axis = touchVector.vectorProductTo(moveVector);
//normalize axis
axis.normalize();
//get angle of rotation
float angle = direction.length;
//make identity Quad
Quaternion quad = new Quaternion();
//make rotation quad
quad.makeRotationKvaternion(angle,axis);
//from quad recieve matrix
Matrix4f matrix = quad.toMatrix();
//multiply to current modelview matrix
gl.glMultMatrixf(matrix.returnArray(),0);
//save rotation matrix
square.rotationMatrix = square.rotationMatrix.multiply(matrix);
//save modelView matrix
square.saveModelView(square.initMatrix.returnArray());
// touch coords to current modelView coords
private Vector3f getRubikSystemCoordinates(float x, float y, Matrix4f matrix){
// touch coords to normal coords of screen
Vector2f normalCoords = (new Vector2f(x,y)).toNormalScreenCoordinates(Settings.viewPort[2],Settings.viewPort[3]);
// to sphere coords in 3D
Vector3f sphereVector = new Vector3f(normalCoords.x,normalCoords.y, FloatMath.sqrt(2-normalCoords.x*normalCoords.x-normalCoords.y*normalCoords.y));
//Get inverse matrix from ModelView Matrix
Matrix4f m = matrix.inverseMatrix();
//Get vector for current modelView 3D coords
Vector3f vector = m.multiplyToVector(vector);
// make normalize vector
vector.normalize();
return vector;
}
解決方法:
您要尋找的是名為arcball rotation.您將在互聯網上的Java周圍找到大量資源.
標簽:android,opengl-es,rubiks-cube
來源: https://codeday.me/bug/20191013/1904622.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言将数组变为空,求助~~ 如何把数
- 下一篇: 荣耀手环5没有篮球鸿蒙,荣耀手环5和篮球