簡體   English   中英

花栗鼠物理/ Cocos2d / Objective-c-cpSpaceBBQuery

[英]Chipmunk Physics/Cocos2d/Objective-c - cpSpaceBBQuery

我一直在互聯網上尋找任何指南,甚至是Chipmunk Physics的cpSpaceBBQuery函數的示例。 我已經閱讀並重新閱讀了作者自己提供的文檔,但並不算幸運。

這是有關Chipmunk的所有文檔: http : //chipmunk-physics.net/release/ChipmunkLatest-Docs/

據我了解,您必須在代碼中的某個位置調用函數cpSpaceBBQuery,將邊界框設置為參考,並在找到形狀時調用該函數。 當我設置這兩個元素時,我的函數將永遠不會被調用。 我嘗試添加一個精靈作為數據參數,也沒有運氣。 我想念什么?

一個很好的例子。

謝謝你的時間!

沒有專家,但是我為您找到了以下內容,希望對您有所幫助。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM