Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17070

Using AffineTransform for edge detection

$
0
0

@shipit wrote:

Basically I don't want the user to move/scale the sprite offscreen. For moving it's super easy, here's my working solution:

bool CoordsTest::onGesturePan(TGesturePan *gesture) {
    Vec2 delta = gesture->getTranslation();
    Rect contentRect = _contentNode->getBoundingBox();
    contentRect.origin += delta;

    if (contentRect.containsPoint(_screenMinPoint) && contentRect.containsPoint(_screenMaxPoint)) {
        _contentNode->setPosition(_contentNode->getPosition() + delta);
    }

    return true;
}

It works great! Here's another way I tried that isn't working and I want to figure this out in case I want to add scale/rotation operations:

bool CoordsTest::onGesturePan(TGesturePan *gesture) {
    Vec2 delta = gesture->getTranslation();
    Rect contentRect = _contentNode->getBoundingBox();
    
    AffineTransform transform = _contentNode->getNodeToWorldAffineTransform();
    transform = AffineTransformTranslate(transform, delta.x, delta.y);
    contentRect = RectApplyAffineTransform(contentRect, transform);

    if (contentRect.containsPoint(_screenMinPoint) && contentRect.containsPoint(_screenMaxPoint)) {
        _contentNode->setPosition(_contentNode->getPosition() + delta);
    }

    return true;
}

This does not work. I think my starting transform ie _contentNode->getNodeToWorldAffineTransform() maybe wrong.

help?! thx!

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17070

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>