팬을 사용하여 에있는 객체를 회전하려고합니다. 2 개의 회전 축이 있습니다 : 객체 y 축과 전역 고정 x 축. y 축 주위에 나는 방법 CATransform3DRotate
에 의해 생성 된 회전 행렬을 사용하고 고정 된 x 축 주위로 쿼터니언을 사용하여 간단히 회전합니다.쿼터니언을 사용하여 객체 회전
UITouch* touch = [touches anyObject];
CGPoint location = [touch locationInView: viewController.view];
CGPoint lastLoc = [touch previousLocationInView: viewController.view];
CGPoint diff = CGPointMake(lastLoc.x - location.x, lastLoc.y - location.y);
float rotX = 1 * DEGREES_TO_RADIANS(diff.y/4.0);
float rotY = -1 * DEGREES_TO_RADIANS(diff.x/4.0);
CATransform3D m = glView.modelTransform;
if(fabs(diff.y) > fabs(diff.x) * 5.0) { //up-down
Vector3D xAxis = {1.0, 0.0, 0.0};
Vector4D quaternion = [self makeQuaternionFromAxis: xAxis andAngle:rotX];
Vector4D currentQuaterion = [self makeQuaternionFromRotationMatrix: m];
quaternion = [self multiplyQuaternion:currentQuaterion buAnother:quaternion];
m = [self makeRo
tationMatrixFromQuaternion:quaternion];
m = CATransform3DConcat(m, origin);
}
else { //right-left
Vector3D yAxis = {0.0, 1.0, 0.0};
m = CATransform3DRotate(m, rotY, yAxis.x, yAxis.y,yAxis.z);
}
glView.modelTransform = m;
나는 수평 및 수직 이동 분리 : 는 여기에 몇 가지 코드 느릅 나무는 동작을 보여줍니다. 원점 변수는 3D 뷰에서 객체의 원래 posiotion입니다. 문제는 객체가 요각 회전을하고 회전이 엉망이되고 때로는 객체 자체가 엉망이된다는 것입니다. 이 상황은 내가 chaotically 화면에 냄비를 만들 때 나타납니다. 나는 움직임을 정상화하려고 노력했다. 그러나 이것은 나에게 도움이되지 않았다. 누군가 내가 뭘 잘못하고 있는지 말해 줄 수 있어요. 이 같은
이미이 문제가 해결되었습니다. – Demonoid67