Hello,
I might have found a bug with testSegment:
When the segment is perpendicular to a segment of the shape tested,
it seems that it tests that segment of the polygon as if it was a infinite line (instead of a segment of that line).
Edit: I added a .love showing the bug
Bug with testSegment ?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Bug with testSegment ?
- Attachments
-
- testSegmentBug.love
- (996 Bytes) Downloaded 252 times
Re: Bug with testSegment ?
It's not clear enough or nobody cares ?
Re: Bug with testSegment ?
Sorry, I saw this, then completely forgot about it.
I've tried looking at the LOVE source and Box2D source, but I can't find any obvious errors. Here's the LOVE wrapper code, maybe someone else can spot an error.
Thanks for pointing this out, btw. I'll have to ask at the Box2D forums when I get the time.
I've tried looking at the LOVE source and Box2D source, but I can't find any obvious errors. Here's the LOVE wrapper code, maybe someone else can spot an error.
Code: Select all
int Shape::testSegment(lua_State * L)
{
love::luax_assert_argc(L, 4, 4);
b2Segment s;
s.p1.x = (float)lua_tonumber(L, 1);
s.p1.y = (float)lua_tonumber(L, 2);
s.p2.x = (float)lua_tonumber(L, 3);
s.p2.y = (float)lua_tonumber(L, 4);
float lambda;
b2Vec2 normal;
if(shape->TestSegment(shape->GetBody()->GetXForm(), &lambda, &normal, s, 1.0f))
{
lua_pushnumber(L, lambda);
lua_pushnumber(L, normal.x);
lua_pushnumber(L, normal.y);
return 3;
}
return 0;
}
Re: Bug with testSegment ?
Thanks for the reply =)
I'm trying to convert it to c++ with the testbed of Box2d to see if there is the same problem.
(I use the version 2.0.1 of Box2d, I think that LOVE use the same.)
I'm trying to convert it to c++ with the testbed of Box2d to see if there is the same problem.
(I use the version 2.0.1 of Box2d, I think that LOVE use the same.)
Re: Bug with testSegment ?
So, the bug seems to come from Box2d, I found the same problem with this code:
(Note: I had to add "virtual" to the line 144 of Test.h "void MouseMove(const b2Vec2& p);" so I can get the mouse position when the mouse is down,
add #include "TestSegment.h" and {"TestSegment", TestSegment::Create}, in TestEntries.cpp)
The red and blue line shouldn't stop because they aren't colliding with the shape:
Code: Select all
#ifndef TEST_SEGMENT_H
#define TEST_SEGMENT_H
class TestSegment : public Test
{
public:
b2Body* m_body;
b2Vec2 m_mousePos;
TestSegment()
{
{
b2PolygonDef shape;
shape.SetAsBox(5.0f, 1.0f);
b2BodyDef body;
body.position.Set(0.0f, 20.0f);
m_body = m_world->CreateBody(&body);
m_body->CreateShape(&shape);
}
}
void MouseMove(const b2Vec2& p)
{
Test::MouseMove(p);
m_mousePos = p;
}
void Step(Settings* settings)
{
Test::Step(settings);
float lambda;
b2Vec2 normal;
b2Shape* shape = m_body->GetShapeList();
b2Segment greenSegment, redSegment, blueSegment;
greenSegment.p1 = b2Vec2(10, 10);
greenSegment.p2 = m_mousePos;
redSegment.p1 = b2Vec2(m_mousePos.x, 10);
redSegment.p2 = m_mousePos;
blueSegment.p1 = b2Vec2(10, m_mousePos.y);
blueSegment.p2 = m_mousePos;
if(shape->TestSegment(shape->GetBody()->GetXForm(), &lambda, &normal, greenSegment, 1.0f)) {
DrawSegment(greenSegment.p1, greenSegment.p1 + lambda * (greenSegment.p2 - greenSegment.p1), b2Color(0, 255, 0));
} else {
DrawSegment(greenSegment.p1, greenSegment.p2, b2Color(0, 255, 0));
}
if(shape->TestSegment(shape->GetBody()->GetXForm(), &lambda, &normal, redSegment, 1.0f)) {
DrawSegment(redSegment.p1, redSegment.p1 + lambda * (redSegment.p2 - redSegment.p1), b2Color(255, 0, 0));
} else {
DrawSegment(redSegment.p1, redSegment.p2, b2Color(255, 0, 0));
}
if(shape->TestSegment(shape->GetBody()->GetXForm(), &lambda, &normal, blueSegment, 1.0f)) {
DrawSegment(blueSegment.p1, blueSegment.p1 + lambda * (blueSegment.p2 - blueSegment.p1), b2Color(0, 0, 255));
} else {
DrawSegment(blueSegment.p1, blueSegment.p2, b2Color(0, 0, 255));
}
}
static Test* Create()
{
return new TestSegment;
}
};
#endif
add #include "TestSegment.h" and {"TestSegment", TestSegment::Create}, in TestEntries.cpp)
The red and blue line shouldn't stop because they aren't colliding with the shape:
Re: Bug with testSegment ?
Nice work ... we'll have to ask Box2D author Erin Catto about it then.
Who is online
Users browsing this forum: Google [Bot] and 4 guests