issue #2771: add pointQuery

This commit is contained in:
boyu0 2013-11-11 15:03:17 +08:00
parent 4efacdbcf3
commit 13efb7e822
2 changed files with 20 additions and 0 deletions

View File

@ -818,6 +818,24 @@ void PhysicsWorld::rectQuery(PhysicsRectQueryCallbackFunc func, const Rect& rect
} }
} }
void PhysicsWorld::pointQuery(PhysicsPointQueryCallbackFunc func, const Point& point, void* data)
{
CCASSERT(func != nullptr, "callback.report shouldn't be nullptr");
if (func != nullptr)
{
RectQueryCallbackInfo info = {this, func, data};
PhysicsWorldCallback::continues = true;
cpSpaceBBQuery(this->_info->getSpace(),
PhysicsHelper::rect2cpbb(Rect(point.x - 0.01f, point.y - 0.01f, 0.02f, 0.02f)),
CP_ALL_LAYERS,
CP_NO_GROUP,
(cpSpaceBBQueryFunc)PhysicsWorldCallback::rectQueryCallbackFunc,
&info);
}
}
Array* PhysicsWorld::getShapes(const Point& point) const Array* PhysicsWorld::getShapes(const Point& point) const
{ {
Array* arr = Array::create(); Array* arr = Array::create();

View File

@ -80,6 +80,7 @@ typedef struct PhysicsRayCastInfo
*/ */
typedef std::function<bool(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data)> PhysicsRayCastCallbackFunc; typedef std::function<bool(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data)> PhysicsRayCastCallbackFunc;
typedef std::function<bool(PhysicsWorld&, PhysicsShape&, void*)> PhysicsRectQueryCallbackFunc; typedef std::function<bool(PhysicsWorld&, PhysicsShape&, void*)> PhysicsRectQueryCallbackFunc;
typedef PhysicsRectQueryCallbackFunc PhysicsPointQueryCallbackFunc;
/** /**
* @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object. * @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object.
@ -100,6 +101,7 @@ public:
void rayCast(PhysicsRayCastCallbackFunc func, const Point& point1, const Point& point2, void* data); void rayCast(PhysicsRayCastCallbackFunc func, const Point& point1, const Point& point2, void* data);
void rectQuery(PhysicsRectQueryCallbackFunc func, const Rect& rect, void* data); void rectQuery(PhysicsRectQueryCallbackFunc func, const Rect& rect, void* data);
void pointQuery(PhysicsPointQueryCallbackFunc func, const Point& point, void* data);
Array* getShapes(const Point& point) const; Array* getShapes(const Point& point) const;
PhysicsShape* getShape(const Point& point) const; PhysicsShape* getShape(const Point& point) const;
Array* getAllBodies() const; Array* getAllBodies() const;