2013-03-16 2 views
2

화면 중앙에서 터치 지점을 180도 회전시키지 않습니다 (미러링). ccpRotateByAngle(screenCenter, touchPoint, 180)을 시도했지만 잘못된 데이터를 받았습니다. 구조에CGPoint를 미러하는 방법

답변

4

삼각법 :

// get your center in some way, here I'm using fixed coordinates 'cuz I'm lazy 
CGPoint screenCenter = ccp(240, 160); 

// this creates the vector between center and touch location 
CGPoint touchPointToCenter = ccpSub(screenCenter, touchPoint); 

// just add the vector to screen center and you mirrored it around center 
CCPoint mirror = ccpAdd(screenCenter, touchPointToCenter); 

예를 들어,의는 터치 포인트가 200이라고 200을 보자

touchPointToCenter: {240, 160} - {200, 200} = {40, -40} 
mirror: {240, 160} + {40, -40} = {280, 120} 

미러링 된 포인트가 280, 120

참고 : 내가 사용한 함수는 cocos2d-iphone에서 가져온 것입니다. 나는 그들이 cocos2d-x에도 있다고 가정한다. 이름이 다를 수 있습니다. 확실하지 않습니다. 예제에서와 같이 "수동으로"계산을 실행할 수도 있습니다.

+0

빠른 답변 주셔서 감사합니다. 그것은 완벽하게 작동합니다. – McDermott

관련 문제