日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转

發(fā)布時(shí)間:2025/3/19 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 触摸屏 旋转,android-使用OpenGl和触摸屏功能在视觉上纠正旋转 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我一直在嘗試為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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。