【问题标题】:Chipmunk Physics/Cocos2d/Objective-c - cpSpaceBBQuery花栗鼠物理/Cocos2d/Objective-c - cpSpaceBBQuery
【发布时间】:2012-12-31 21:21:16
【问题描述】:

我一直在互联网上寻找任何指南,甚至是花栗鼠物理的 cpSpaceBBQuery 函数的示例。我已经阅读并重新阅读了作者自己提供的文档,但没有运气。

这里是关于 Chipmunk 的所有文档:http://chipmunk-physics.net/release/ChipmunkLatest-Docs/

据我了解,您必须在代码中的某处调用函数 cpSpaceBBQuery,将边界框设置为参考,并在找到形状时调用函数。当我设置这两个元素时,我的函数永远不会被调用。我尝试添加一个精灵作为数据参数也没有运气。我错过了什么?

一个很好的例子。

感谢您的宝贵时间!

【问题讨论】:

    标签: objective-c cocos2d-iphone physics chipmunk


    【解决方案1】:

    没有这方面的专家,但我只是为您找到了以下内容,希望对您有所帮助。

    http://cutecoder.org/programming/wrapping-style-callbacks-blocks/

    http://code.google.com/p/chipmunk-physics/source/browse/wiki/Queries.wiki?r=408

    ==Bounding Box Queries==
    
    {{{
    typedef void (*cpSpaceBBQueryFunc)(cpShape *shape, void *data);
    void cpSpaceBBQuery(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void *data);
    }}}
     Query `space` over the area of `bb` filtering out matches using the given `layers` and `group`. `func` is called for each shape found along with the `data` argument passed to `cpSpaceBBQuery()`. The bounding box of all shapes passed to the callback overlap the given bounding box, but the shapes themselves might not overlap the box. This function is meant to be an efficient way to find objects in an area, but not a detailed intersection test.
    
    ==Examples==
    
    This is the mouse button handler function from the demo app. On mouse down, it finds the shape under the mouse if there is one and adds a joint to it so that you can drag it around.
    {{{
    static void
    click(int button, int state, int x, int y)
    {
            if(button == GLUT_LEFT_BUTTON){
                    if(state == GLUT_DOWN){
                            cpVect point = mouseToSpace(x, y);
    
                            cpShape *shape = cpSpacePointQueryFirst(space, point, GRABABLE_MASK_BIT, 0);
                            if(shape){
                                    cpBody *body = shape->body;
                                    mouseJoint = cpPivotJointNew2(mouseBody, body, cpvzero, cpBodyWorld2Local(body, point));
                                    mouseJoint->maxForce = 50000.0f;
                                    mouseJoint->biasCoef = 0.15f;
                                    cpSpaceAddConstraint(space, mouseJoint);
                            }
                    } else if(mouseJoint){
                            cpSpaceRemoveConstraint(space, mouseJoint);
                            cpConstraintFree(mouseJoint);
                            mouseJoint = NULL;
                    }
            }
    }
    }}}
    
    Shoot a laser through a space, find the first shape it hits. We want to draw particles where the laser beam enters and exits the shape.
    {{{
    cpSegmentQueryInfo info;
    if(cpSpaceSegmentQueryFirst(space, a, b, -1, 0, &info)){
            cpSegmentQueryInfo info2;
            cpShapeSegmentQuery(info.shape, b, a, &info2);
    
            cpVect enterPoint = cpSegmentQueryHitPoint(a, b, info);
            cpVect exitPoint = cpSegmentQueryHitPoint(b, a, info2);
    }
    }}}
    

    【讨论】:

    • 感谢您的回答,但我已经看过这些示例,但在使用它们时没有任何运气。此外,此处显示的示例甚至没有使用 ccSpaceBBQuery 函数。不过谢谢你:)
    • 也许如果你可以分享你的一些代码,人们(在这件事上比我更了解:P)可以看到为什么你的函数没有被调用。很抱歉听到这些小提示没有太大帮助:)。
    • 我真正需要的是解释这个函数是如何工作的。我还没有找到任何文档解释这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多