I've been trying to understand segment shape radius property.
I took a look at ChipmunkDebugDraw.c function:
Code: Select all
void ChipmunkDebugDrawFatSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor)
Then I tried to make my own segment draw function, based on the shown bounding box.
Code: Select all
case CP_SEGMENT_SHAPE: {
cpSegmentShape *shape = (cpSegmentShape*)m_shape;
if(shape->r == 0) {
PointF p1 = PointF(shape->a.x - position.x, -(shape->a.y - position.y));
PointF p2 = PointF(shape->b.x - position.x, -(shape->b.y - position.y));
g_painter->drawLine(p1 * ppu, p2 * ppu);
}
else {
float angle = std::atan2(shape->b.y - shape->a.y, shape->b.x - shape->a.x);
PointF p1 = PointF(shape->a.x - position.x, -(shape->a.y - position.y));
PointF p2 = PointF(shape->b.x - position.x, -(shape->b.y - position.y));
PointF dR = PointF(shape->r * sin(angle), shape->r * cos(angle));
g_painter->drawLine((p1 - dR) * ppu, (p2 - dR) * ppu);
g_painter->drawLine((p1 + dR) * ppu, (p2 + dR) * ppu);
g_painter->drawCircle(p1 * ppu, shape->r * ppu, 20, angle + stdext::pi / 2., angle + stdext::pi / 2. + stdext::pi);
g_painter->drawCircle(p2 * ppu, shape->r * ppu, 20, angle - stdext::pi / 2., angle - stdext::pi / 2. + stdext::pi);
}
break;
}
(Gray is the bounding box, Red is the shape)
Is this how radius is supposed to be?
The collision is not exactly as I expected, and that's why I'm creating this topic.
Another question about them,
I'm adding segment shapes to my 'background' objects (they wont collide ever) so it's bounding box can fit the whole texture.
Image to exemplify the use of segment shapes on 'background' objects.
Is this the right approach to do this?
I couldnt figure another way to adjust their bounding box so they'll be detected by queryBB function.
Also,
Code: Select all
typedef struct cpSegmentShape {
cpShape shape;
cpVect a, b, n;
cpVect ta, tb, tn;
cpFloat r;
cpVect a_tangent, b_tangent;
} cpSegmentShape;
r is the radius, and what's ta, tb, tn?
Thanks a lot !