Add EdgeShape:set/getNext/PreviousVertex. ChainShape:setNext/PreviousVertex can now take no arguments to disable ghost vertices.

Resolves issue #1191.
This commit is contained in:
Alex Szpakowski
2016-08-01 10:15:34 -03:00
parent 2e8f785a01
commit fc2c79ad5f
6 changed files with 183 additions and 47 deletions
+29 -13
View File
@@ -55,6 +55,12 @@ void ChainShape::setNextVertex(float x, float y)
c->SetNextVertex(Physics::scaleDown(v));
}
void ChainShape::setNextVertex()
{
b2ChainShape *c = (b2ChainShape *)shape;
c->m_hasNextVertex = false;
}
void ChainShape::setPreviousVertex(float x, float y)
{
if (loop)
@@ -67,30 +73,40 @@ void ChainShape::setPreviousVertex(float x, float y)
c->SetPrevVertex(Physics::scaleDown(v));
}
bool ChainShape::hasNextVertex() const
void ChainShape::setPreviousVertex()
{
b2ChainShape *c = (b2ChainShape *)shape;
return c->m_hasNextVertex;
c->m_hasPrevVertex = false;
}
bool ChainShape::hasPreviousVertex() const
bool ChainShape::getNextVertex(float &x, float &y) const
{
b2ChainShape *c = (b2ChainShape *)shape;
return c->m_hasPrevVertex;
if (c->m_hasNextVertex)
{
b2Vec2 v = Physics::scaleUp(c->m_nextVertex);
x = v.x;
y = v.y;
return true;
}
return false;
}
b2Vec2 ChainShape::getNextVertex() const
bool ChainShape::getPreviousVertex(float &x, float &y) const
{
b2ChainShape *c = (b2ChainShape *)shape;
const b2Vec2 &v = c->m_nextVertex;
return Physics::scaleUp(v);
}
b2Vec2 ChainShape::getPreviousVertex() const
{
b2ChainShape *c = (b2ChainShape *)shape;
const b2Vec2 &v = c->m_prevVertex;
return Physics::scaleUp(v);
if (c->m_hasPrevVertex)
{
b2Vec2 v = Physics::scaleUp(c->m_prevVertex);
x = v.x;
y = v.y;
return true;
}
return false;
}
EdgeShape *ChainShape::getChildEdge(int index) const