示例#1
0
void Slice::SliceQuery(cpShape *shape, cpVect point, cpVect normal, cpFloat alpha, struct SliceContext *context)
{
	cpVect a = context->a;
	cpVect b = context->b;
	
	// Check that the slice was complete by checking that the endpoints aren't in the sliced shape.
	if(cpShapePointQuery(shape, a, NULL) > 0.0f && cpShapePointQuery(shape, b, NULL) > 0.0f){
		// Can't modify the space during a query.
		// Must make a post-step callback to do the actual slicing.
		cpSpaceAddPostStepCallback(context->space, (cpPostStepFunc)SliceShapePostStep, shape, context);
	}
}
示例#2
0
	bool RigidBody2D::ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const
	{
		cpVect pos = cpv(cpFloat(position.x), cpFloat(position.y));

		float minDistance = std::numeric_limits<float>::infinity();
		Nz::Vector2f closest;
		for (cpShape* shape : m_shapes)
		{
			cpPointQueryInfo result;
			cpShapePointQuery(shape, pos, &result);

			float resultDistance = float(result.distance);
			if (resultDistance < minDistance)
			{
				closest.Set(float(result.point.x), float(result.point.y));
				minDistance = resultDistance;
			}
		}

		if (std::isinf(minDistance))
			return false;

		if (closestPoint)
			*closestPoint = closest;

		if (minDistance)
			*closestDistance = minDistance;

		return true;
	}
示例#3
0
static void 
pointQueryHelper(cpVect *point, cpShape *shape, pointQueryContext *context)
{
	if(
		!(shape->group && context->group == shape->group) && (context->layers&shape->layers) &&
		cpShapePointQuery(shape, *point)
	){
		context->func(shape, context->data);
	}
}
示例#4
0
static void 
PointQuery(struct PointQueryContext *context, cpShape *shape, void *data)
{
	if(
		!(shape->group && context->group == shape->group) && (context->layers&shape->layers) &&
		cpShapePointQuery(shape, context->point)
	){
		context->func(shape, context->data);
	}
}
示例#5
0
static int 
pointQueryHelper(void *point, void *obj, void *data)
{
	cpShape *shape = (cpShape *)obj;
	pointQueryFuncPair *pair = (pointQueryFuncPair *)data;
	
	if(cpShapePointQuery(shape, *((cpVect *)point)))
		pair->func(shape, pair->data);
	
	return 1; // return value needed for historical reasons (value is ignored)
}
bool PhysicsShape::containsPoint(const Vec2& point) const
{
    for (auto shape : _cpShapes)
    {
        if (cpShapePointQuery(shape, PhysicsHelper::point2cpv(point), nullptr) < 0)
        {
            return true;
        }
    }
    
    return false;
}
bool PhysicsShape::containsPoint(const Point& point) const
{
    for (auto shape : _info->getShapes())
    {
        if (cpShapePointQuery(shape, PhysicsHelper::point2cpv(point)))
        {
            return true;
        }
    }
    
    return false;
}
示例#8
0
static cpCollisionID 
PointQuery(struct PointQueryContext *context, cpShape *shape, cpCollisionID id, void *data)
{
	if(
		!(shape->group && context->group == shape->group) && (context->layers&shape->layers) &&
		cpShapePointQuery(shape, context->point)
	){
		context->func(shape, context->data);
	}
	
	return id;
}
示例#9
0
文件: wrapper.c 项目: Et999/Hipmunk
int wrShapePointQuery(cpShape *shape, cpVect *p) {
    return cpShapePointQuery(shape, *p);
}