2013-03-28 23 views
-1

我想使用touchesMoved方法旋轉屏幕上的圖像。 所以如果我將手指從右側移動到左側,我想讓我的 圖像從左到右旋轉。OpenGLES 2.0旋轉touchesMoved

這是不是有可能?

回答

0

找到解決方案!

- (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; 
} 

「開始」 和 「結束」 是從觸摸給出的兩點感動:

- (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]; 
}