2012-12-31 68 views
1

我一直在尋找遍佈互聯網的任何指南,甚至是Chipmunk Physics的cpSpaceBBQuery函數的例子。我已閱讀並重新閱讀由作者自己提供的文檔,但沒有運氣。Chipmunk Physics/Cocos2d/Objective-c - cpSpaceBBQuery

這裏是一切花栗鼠的文檔:http://chipmunk-physics.net/release/ChipmunkLatest-Docs/

從我的理解,你必須某處調用函數cpSpaceBBQuery在你的代碼,設置邊框作爲參考和功能時的形狀被發現被調用。當我設置這2個元素時,我的函數永遠不會被調用。我嘗試添加一個精靈作爲數據參數,但沒有任何運氣。我錯過了什麼?

一個例子,去與此會很好。

謝謝你的時間!

回答

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

感謝您的回答,但我已經在使用它們已經看到了這些例子中,沒有任何運氣。此外,此處顯示的示例甚至不使用ccSpaceBBQuery函數。謝謝你:) – Cubia

+0

也許如果你可以分享你的一些代碼,人們(比我更懂這個問題:P)可以明白爲什麼你的函數沒有被調用。對不起,聽到這些小提示並沒有多大幫助:)。 –

+0

我真正需要的是關於這個函數如何工作的解釋。我還沒有找到任何文件解釋這個部門。 – Cubia

相關問題