我在渲染的模型的时候定义了三个6个变量
float _rotationX;//旋转变量x
float _rotationZ;//旋转变量z
float _rotationY;//旋转变量y
float _lastRotationX;//最后一个旋转落点得x
float _lastRotationZ;//最后一个旋转落点得z
float _lastRotationY;//最后一个旋转落点的y
在update方法内有如下方法
GLKMatrix4 modelViewMatrix = GLKMatrix4Translate(GLKMatrix4Identity, 0.0f, 0.0f, 0.0f);
modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 0.0f, 0.0f, 1.0f); //旋转
modelViewMatrix = GLKMatrix4RotateX(modelViewMatrix, GLKMathDegreesToRadians(_rotationX));
modelViewMatrix = GLKMatrix4RotateZ(modelViewMatrix, GLKMathDegreesToRadians(_rotationZ));
modelViewMatrix = GLKMatrix4RotateY(modelViewMatrix, GLKMathDegreesToRadians(_rotationY));
然后我在手势的移动方法内事这样写的
#pragma mark 实现单指头拖拽旋转
UIGestureRecognizerState state = [sender state];
//判断当手指开始移动或者改变的时候
if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged)
{
//声明一个点为当前手指落在屏幕上的点
CGPoint translation = [sender translationInView:sender.view];
_rotationY = translation.x - _lastRotationX;
_rotationX = translation.y - _lastRotationY ;
}
if (state == UIGestureRecognizerStateEnded) {
//_lastRotationX,Y,Z为用户手指离开屏幕所记录的点
_lastRotationX = -_rotationY;
_lastRotationZ = _rotationZ;
_lastRotationY = -_rotationX;
NSLog(@"_rotationY = %f",_rotationY);
}
我现在的出现的问题是
第一:当模型被旋转颠倒后,在去旋转X轴方向就倒过来了(就是说一个小猫刚开始旋转左右旋转是正常的左右方向,如果你把她上下颠倒后,在旋转就是右左方向,反方向旋转了)
第二:我没有添加Z的旋转体系,所以模型的侧面怎么都旋转不到(我是不知道怎么添加。。。。)
求解惑
잘 이해가 안 되네요.
1. 첫 번째 문제는 객체가 자체 좌표를 기준으로 회전하므로 자체 방향에 의해 간섭을 받는 것 같습니다. 원근 변환이 전달되기 전의 행렬이어야 합니다. 즉, 세계 좌표계가 표준입니다.
2. Z축은 화면을 향한 방향입니다. Z축을 따른 회전은 화면에서 두 손가락을 회전시키는 동작이어야 합니다.