2013-03-28 3 views
-1

touchesMoved 메서드를 사용하여 화면에서 이미지를 회전하고 싶습니다. 손가락을 오른쪽에서 왼쪽으로 움직이는 경우, 내 이미지가 왼쪽에서 오른쪽으로 회전되기를 원합니다.OpenGLES 2.0 회전 touchesMoved

어떻게 든 가능합니까?

답변

0

해결책을 찾았습니다!

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [[event allTouches] anyObject]; 

    CGPoint end = [touch locationInView:self.view]; 
    CGPoint start = [touch previousLocationInView:self.view]; 

    [self.scene handleDragFrom:start to:end]; 
} 
:

- (void)handleDragFrom:(CGPoint)start to:(CGPoint)end 
{ 
    [super handleDragFrom:start to:end]; 

    float rotationCenterX = self.player.position.x - (self.player.contentSize.width/2); 
    float rotationCenterY = self.player.position.y - (self.player.contentSize.height/2); 

    float dXStart = start.x - rotationCenterX; 
    float dYStart = start.y - rotationCenterY; 
    float radianStart = atan2(dYStart, dXStart); 

    float dXEnd = end.x - rotationCenterX; 
    float dYEnd = end.y - rotationCenterY; 
    float radianEnd = atan2(dYEnd, dXEnd); 

    float radian = GLKMathRadiansToDegrees(radianEnd - radianStart); 

    self.player.rotation -= radian; 
} 

"종료"터치에서 주어진 두 지점이 이동 "시작"

관련 문제