mirror of https://github.com/axmolengine/axmol.git
issue #2771: add pointQuery
This commit is contained in:
parent
4efacdbcf3
commit
13efb7e822
|
@ -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* arr = Array::create();
|
||||
|
|
|
@ -80,6 +80,7 @@ typedef struct PhysicsRayCastInfo
|
|||
*/
|
||||
typedef std::function<bool(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data)> PhysicsRayCastCallbackFunc;
|
||||
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.
|
||||
|
@ -100,6 +101,7 @@ public:
|
|||
|
||||
void rayCast(PhysicsRayCastCallbackFunc func, const Point& point1, const Point& point2, 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;
|
||||
PhysicsShape* getShape(const Point& point) const;
|
||||
Array* getAllBodies() const;
|
||||
|
|
Loading…
Reference in New Issue