android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转
我一直在嘗試為Android做魔方.我有一個(gè)關(guān)于輪換的問(wèn)題.我想旋轉(zhuǎn)一個(gè)外觀(guān)正確的圖形.這意味著如果用戶(hù)觸摸屏,并且在將手指向右移動(dòng)之后,圖形將從觀(guān)察點(diǎn)的一側(cè)向右旋轉(zhuǎn).但是當(dāng)我旋轉(zhuǎn)一些時(shí),圖形開(kāi)始朝不正確的方向移動(dòng).我了解,這取決于軸是否改變了他們的狀況.但是我嘗試使用逆模型矩陣來(lái)獲取必要的坐標(biāo),但尚未得到結(jié)果.有人可以在鼠標(biāo)或觸摸屏的幫助下給我示例或視覺(jué)上正確旋轉(zhuǎn)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.您將在互聯(lián)網(wǎng)上的Java周?chē)业酱罅抠Y源.
標(biāo)簽:android,opengl-es,rubiks-cube
來(lái)源: https://codeday.me/bug/20191013/1904622.html
與50位技術(shù)專(zhuān)家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: c语言将数组变为空,求助~~ 如何把数
- 下一篇: 荣耀手环5没有篮球鸿蒙,荣耀手环5和篮球