2012-09-02 2 views
0

나는이 질문을 쓰기 :나는 이해하지 않는다 -적인 Cocos2D + Box2D의 예에 (CGAffineTransform) nodeToParentTransform을 나는 아이폰적인 Cocos2D에서 제공하는 예제 코드의 조각을 이해하지 않기 때문에

-(CGAffineTransform) nodeToParentTransform 
{ 
b2Vec2 pos = body_->GetPosition(); 

float x = pos.x * PTM_RATIO; 
float y = pos.y * PTM_RATIO; 

if (ignoreAnchorPointForPosition_) { 
    x += anchorPointInPoints_.x; 
    y += anchorPointInPoints_.y; 
} 

// Make matrix 
float radians = body_->GetAngle(); 
float c = cosf(radians); 
float s = sinf(radians); 

if(! CGPointEqualToPoint(anchorPointInPoints_, CGPointZero)){ 
    x += c*-anchorPointInPoints_.x + -s*-anchorPointInPoints_.y; 
    y += s*-anchorPointInPoints_.x + c*-anchorPointInPoints_.y; 
} 

// Rot, Translate Matrix 
transform_ = CGAffineTransformMake(c, s, 
            -s, c, 
            x, y);  

return transform_; 
} 

그것은의를 PhysicsSprite.mm 파일에 있습니다.

어쩌면 그것은 일 것입니다. 저는 공간 구조가있는입니다. 누군가 설명 할 수 있다면 매우 고맙습니다.

고마워요.

답변

0
if(! CGPointEqualToPoint(anchorPointInPoints_, CGPointZero)){ 
    x += c*-anchorPointInPoints_.x + -s*-anchorPointInPoints_.y; 
    y += s*-anchorPointInPoints_.x + c*-anchorPointInPoints_.y; 
} 

코드의 상기 부분은 간단히 XY가 축에게 세타 $ 도 \ 반 시계하여 $ 180 좌표 회전 이전 X로 새로운 좌표를 상기 이전 코드의 조각으로부터 수득 y 좌표를 추가 위의 라인.

http://en.wikipedia.org/wiki/Rotation_of_axes 축의 회전식을 제공합니다.

+0

예, 그렇습니다. ...이 코드 조각을 완전히 제거하면 내 장면의 객체가 중력과 함께 움직이지 않아서 왜 그런지 이해하지 못합니다. –

관련 문제