我试图在像MeshLab这样的虚拟球体上用鼠标旋转对象。
private void RotateCamera(Vector3 newDragPoint)
{
var rotAxis = Vector3.Normalize(Vector3.Cross(oldDragPoint, newDragPoint));
var angle = Vector3.Dot(Vector3.Normalize(oldDragPoint), Vector3.Normalize(newDragPoint));
double angleVal = Math.Acos(angle);
Matrix4 rotateMatrix = Matrix4.CreateFromAxisAngle(rotAxis, (float)(angleVal));
var modelViewMatrixTemp = rotateMatrix * modelViewMatrix;
}
在开始工作的时候,模型视图矩阵是:
Row0: {(0.99888134, -0.044642903, -0.0154874, 0)}
Row1: {(0.04587658, 0.9947593, 0.0913476, 0)}
Row2: {(0.011327561, -0.0919559, 0.9956961, 0)}
Row3: {(0, 0, -1, 1)}
但是过了一段时间,如果x-y平面上的旋转足够大,物体就会开始与鼠标的运动作对,
Row0: {(-0.9778508, -0.19920659, -0.06419495, 0)}
Row1: {(0.18042804, -0.95778984, 0.22378196, 0)}
Row2: {(-0.10606451, 0.20724255, 0.97251993, 0)}
Row3: {(0, 0, -1, 1)}
在这种情况下,如何确定角度?
更新______
现在我发现旋转应用于初始姿态的物体,而不是旋转的物体,但仍然不知道如何修复它。
发布于 2022-07-07 09:23:35
将新的轮调与旧的轮调分开将解决这一问题。将当前旋转保持为oldRotation,然后将行var modelViewMatrixTemp = rotateMatrix * modelViewMatrix;
替换为
var modelViewMatrixTemp = oldRotation * rotateMatrix * modelViewMatrix;
oldRotation = oldRotation * rotateMatrix;
这将适用于旋转对象的旋转。
https://stackoverflow.com/questions/72892956
复制相似问题