From bf31cadc7191d63cda4fae574d6d7fa2e865d82c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 28 Sep 2012 18:43:28 +0200 Subject: [PATCH] Added getter functions for size, solid and static properties. --- source/abstract/Physical.cpp | 27 ++++++++++++++++++++++++++- source/abstract/Physical.h | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/source/abstract/Physical.cpp b/source/abstract/Physical.cpp index 87b1207..522f941 100755 --- a/source/abstract/Physical.cpp +++ b/source/abstract/Physical.cpp @@ -21,7 +21,7 @@ Physical::Physical(const PhysicalData& data) : assert(data.size != Vector2i()); b2BodyDef bodyDef; - bodyDef.type = (data.moving) + bodyDef.type = (data.moving) ? b2_dynamicBody : b2_staticBody; bodyDef.position = vector(data.position); @@ -122,6 +122,31 @@ Physical::getCategory() const { 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 * limit collisions to/with certain objects. Default implementation always returns true. diff --git a/source/abstract/Physical.h b/source/abstract/Physical.h index 3216d0b..66490c3 100755 --- a/source/abstract/Physical.h +++ b/source/abstract/Physical.h @@ -80,6 +80,10 @@ public: float getAngle() const; bool getDelete() const; Category getCategory() const; + Vector2f getSize() const; + + bool isSolid() const; + bool isMovable() const; virtual bool doesCollide(Physical& other); virtual void onCollide(Physical& other, uint16 category);