2011-11-09 3 views
3

개체를 둘러 볼 수있는 것처럼 보이게하는 응용 프로그램을 디자인하려고합니다. 나는 꽤 멀리 보았지만, 그림 프레임과 같이 공중에서 물체를 떠있는 것처럼 보이게 만드는 방법을 알아낼 수는 없다.Core Motion 및 CATransform3D를 사용하여 이미지 회전

CMMotionManager *motionManager = [[CMMotionManager alloc] init]; 
[motionManager setDeviceMotionUpdateInterval:0.1]; 

CMDeviceMotionHandler motionHandler =^(CMDeviceMotion *motion, NSError *error) 
{ 
    [xLabel setText:[NSString stringWithFormat:@"X: %f, Yaw: %f", motion.userAcceleration.x, motion.attitude.yaw]]; 
    [yLabel setText:[NSString stringWithFormat:@"Y: %f, Pitch: %f", motion.userAcceleration.y, motion.attitude.pitch]]; 
    [zLabel setText:[NSString stringWithFormat:@"Z: %f, Roll: %f", motion.userAcceleration.z, motion.attitude.roll]]; 

    CATransform3D transform; 
    transform = CATransform3DMakeRotation(motion.attitude.pitch, 1, 0, 0); 
    transform = CATransform3DRotate(transform, motion.attitude.roll, 0, 1, 0); 
    transform = CATransform3DRotate(transform, motion.attitude.yaw, 0, 0, 1); 

    myView.layer.sublayerTransform = transform; 
    //[myImage setNeedsDisplay]; 
}; 

[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler]; 

이 사진이 책상에 평면처럼 보이게하지만,이 벽에 끊었 것처럼 대신 표시되어야합니다

여기 내 코드입니다. 어떻게하는지에 대한 아이디어가 있습니까?

답변

1

평평하게 보일 경우 기본적으로 수직으로 세우려면 올바른 회전을 피치 회전 코드에 추가하면됩니다. 그 위쪽이 아래로 대신 뺄셈을 수행하려고하면

transform = CATransform3DMakeRotation(motion.attitude.pitch + M_PI_2, 1, 0, 0);

아래의 코드에 피치 회전을 변경해보십시오.

관련 문제