Added getter functions for size, solid and static properties.

This commit is contained in:
Felix Ableitner 2012-09-28 18:43:28 +02:00
parent 9a3f97b990
commit bf31cadc71
2 changed files with 30 additions and 1 deletions

View File

@ -21,7 +21,7 @@ Physical::Physical(const PhysicalData& data) :
assert(data.size != Vector2i()); assert(data.size != Vector2i());
b2BodyDef bodyDef; b2BodyDef bodyDef;
bodyDef.type = (data.moving) bodyDef.type = (data.moving)
? b2_dynamicBody ? b2_dynamicBody
: b2_staticBody; : b2_staticBody;
bodyDef.position = vector(data.position); bodyDef.position = vector(data.position);
@ -122,6 +122,31 @@ Physical::getCategory() const {
return (Category) mBody->GetFixtureList()->GetFilterData().categoryBits; return (Category) mBody->GetFixtureList()->GetFilterData().categoryBits;
} }
/**
* Returns the size of the body as a vector.
*/
Vector2f
Physical::getSize() const {
b2AABB aabb(mBody->GetFixtureList()->GetAABB(0));
return vector(aabb.upperBound - aabb.lowerBound);
}
/**
* Returns true if collisions are enabled for the body.
*/
bool
Physical::isSolid() const {
return mBody->GetFixtureList()->GetFilterData().maskBits != 0;
}
/**
* Returns true if the body is able to move.
*/
bool
Physical::isMovable() const {
return mBody->GetType() != b2_staticBody;
}
/** /**
* This method filters collisions with other physicals. Implement it if you want to * This method filters collisions with other physicals. Implement it if you want to
* limit collisions to/with certain objects. Default implementation always returns true. * limit collisions to/with certain objects. Default implementation always returns true.

View File

@ -80,6 +80,10 @@ public:
float getAngle() const; float getAngle() const;
bool getDelete() const; bool getDelete() const;
Category getCategory() const; Category getCategory() const;
Vector2f getSize() const;
bool isSolid() const;
bool isMovable() const;
virtual bool doesCollide(Physical& other); virtual bool doesCollide(Physical& other);
virtual void onCollide(Physical& other, uint16 category); virtual void onCollide(Physical& other, uint16 category);