mirror of https://github.com/axmolengine/axmol.git
fix PhysicsBody bitmask bug.
This commit is contained in:
parent
ddde741d86
commit
ee3a8da13c
|
@ -69,10 +69,6 @@ PhysicsBody::PhysicsBody()
|
|||
, _linearDamping(0.0f)
|
||||
, _angularDamping(0.0f)
|
||||
, _tag(0)
|
||||
, _categoryBitmask(UINT_MAX)
|
||||
, _collisionBitmask(0)
|
||||
, _contactTestBitmask(UINT_MAX)
|
||||
, _group(0)
|
||||
, _positionResetTag(false)
|
||||
, _rotationResetTag(false)
|
||||
, _rotationOffset(0)
|
||||
|
@ -422,11 +418,6 @@ PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/*
|
|||
}
|
||||
|
||||
_shapes.pushBack(shape);
|
||||
|
||||
if (_group != CP_NO_GROUP && shape->getGroup() == CP_NO_GROUP)
|
||||
{
|
||||
shape->setGroup(_group);
|
||||
}
|
||||
}
|
||||
|
||||
return shape;
|
||||
|
@ -829,34 +820,64 @@ void PhysicsBody::update(float delta)
|
|||
|
||||
void PhysicsBody::setCategoryBitmask(int bitmask)
|
||||
{
|
||||
_categoryBitmask = bitmask;
|
||||
|
||||
for (auto& shape : _shapes)
|
||||
{
|
||||
shape->setCategoryBitmask(bitmask);
|
||||
}
|
||||
}
|
||||
|
||||
int PhysicsBody::getCategoryBitmask() const
|
||||
{
|
||||
if (!_shapes.empty())
|
||||
{
|
||||
return _shapes.front()->getCategoryBitmask();
|
||||
}
|
||||
else
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsBody::setContactTestBitmask(int bitmask)
|
||||
{
|
||||
_contactTestBitmask = bitmask;
|
||||
|
||||
for (auto& shape : _shapes)
|
||||
{
|
||||
shape->setContactTestBitmask(bitmask);
|
||||
}
|
||||
}
|
||||
|
||||
int PhysicsBody::getContactTestBitmask() const
|
||||
{
|
||||
if (!_shapes.empty())
|
||||
{
|
||||
return _shapes.front()->getContactTestBitmask();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0x00000000;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsBody::setCollisionBitmask(int bitmask)
|
||||
{
|
||||
_collisionBitmask = bitmask;
|
||||
|
||||
for (auto& shape : _shapes)
|
||||
{
|
||||
shape->setCollisionBitmask(bitmask);
|
||||
}
|
||||
}
|
||||
|
||||
int PhysicsBody::getCollisionBitmask() const
|
||||
{
|
||||
if (!_shapes.empty())
|
||||
{
|
||||
return _shapes.front()->getCollisionBitmask();
|
||||
}
|
||||
else
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsBody::setGroup(int group)
|
||||
{
|
||||
for (auto& shape : _shapes)
|
||||
|
@ -865,6 +886,18 @@ void PhysicsBody::setGroup(int group)
|
|||
}
|
||||
}
|
||||
|
||||
int PhysicsBody::getGroup() const
|
||||
{
|
||||
if (!_shapes.empty())
|
||||
{
|
||||
return _shapes.front()->getGroup();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsBody::setPositionOffset(const Vec2& position)
|
||||
{
|
||||
if (!_positionOffset.equals(position))
|
||||
|
|
|
@ -171,12 +171,12 @@ public:
|
|||
* The default value is 0xFFFFFFFF (all bits set).
|
||||
*/
|
||||
void setCollisionBitmask(int bitmask);
|
||||
/** get the category bit mask */
|
||||
inline int getCategoryBitmask() const { return _categoryBitmask; }
|
||||
/** get the contact test bit mask */
|
||||
inline int getContactTestBitmask() const { return _contactTestBitmask; }
|
||||
/** get the collision bit mask */
|
||||
inline int getCollisionBitmask() const { return _collisionBitmask; }
|
||||
/** Return bitmask of first shape, if there is no shape in body, return default value.(0xFFFFFFFF) */
|
||||
int getCategoryBitmask() const;
|
||||
/** Return bitmask of first shape, if there is no shape in body, return default value.(0x00000000) */
|
||||
int getContactTestBitmask() const;
|
||||
/** Return bitmask of first shape, if there is no shape in body, return default value.(0xFFFFFFFF) */
|
||||
int getCollisionBitmask() const;
|
||||
|
||||
/**
|
||||
* set the group of body
|
||||
|
@ -184,8 +184,8 @@ public:
|
|||
* it have high priority than bit masks
|
||||
*/
|
||||
void setGroup(int group);
|
||||
/** get the group of body */
|
||||
inline int getGroup() const { return _group; }
|
||||
/** Return bitmask of first shape, if there is no shape in body, return default value.(0) */
|
||||
int getGroup() const;
|
||||
|
||||
/** get the body position. */
|
||||
Vec2 getPosition() const;
|
||||
|
@ -339,11 +339,6 @@ protected:
|
|||
float _angularDamping;
|
||||
int _tag;
|
||||
|
||||
int _categoryBitmask;
|
||||
int _collisionBitmask;
|
||||
int _contactTestBitmask;
|
||||
int _group;
|
||||
|
||||
bool _positionResetTag; /// To avoid reset the body position when body invoke Node::setPosition().
|
||||
bool _rotationResetTag; /// To avoid reset the body rotation when body invoke Node::setRotation().
|
||||
Vec2 _positionOffset;
|
||||
|
|
|
@ -140,6 +140,11 @@ public:
|
|||
inline void setCollisionBitmask(int bitmask) { _collisionBitmask = bitmask; }
|
||||
inline int getCollisionBitmask() const { return _collisionBitmask; }
|
||||
|
||||
/**
|
||||
* set the group of body
|
||||
* Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index)
|
||||
* it have high priority than bit masks
|
||||
*/
|
||||
void setGroup(int group);
|
||||
inline int getGroup() { return _group; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue