Corrección visual correcta de rotación con OpenGl y capacidades de pantalla táctil
He estado tratando de hacer Cube of Rubik para Android. Tengo una pregunta sobre rotaciones. Quiero rotar una figura visualmente correcta. Significa que si el usuario toca la pantalla y luego mueve su dedo hacia la derecha, una figura gira hacia la derecha desde el lado del punto de observación. Pero cuando hago algunas rotaciones, la figura comienza a moverse en una dirección incorrecta. Entiendo que depende de que los ejes cambien su situación. Pero intenté usar una matriz de modelo inversa para obtener las coordenadas necesarias, pero aún no he obtenido el resultado. ¿Alguien podría darme un ejemplo o un enlace de rotación visual correcta de la figura 3D con la ayuda del mouse o la pantalla táctil?
//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;
}