#include "fsCCollisionShape.h"
#include <fsAppCore/components/fsISpriteComponent.h>
#include "Box2D/Collision/Shapes/b2CircleShape.h"
#include "Box2D/Collision/Shapes/b2PolygonShape.h"
#include "../../fsICollisionWorld.h"
using namespace fsNCollision;
fsCCollisionShape::fsCCollisionShape(fsISpriteComponent* pSprt):
fsICollisionShape(fsICollisionShape::eSHAPE::POLYGON)
{
mImpl = new b2PolygonShape();
b2PolygonShape* const polygon = dynamic_cast<b2PolygonShape*>(mImpl);
polygon->SetAsBox(pSprt->widthGet() / fsICollisionWorld::instanceGet()->scaleFactorGet() / 2,
pSprt->heightGet() / fsICollisionWorld::instanceGet()->scaleFactorGet() / 2);
polygon->m_centroid = b2Vec2(0.0f, 0.0f);
mShape = eSHAPE::POLYGON;
}
fsCCollisionShape::fsCCollisionShape(eSHAPE pShape):
fsICollisionShape(pShape)
{
if (eSHAPE::CIRCLE == pShape)
{
mImpl = new b2CircleShape();
b2CircleShape* const circle = dynamic_cast<b2CircleShape*>(mImpl);
circle->m_radius = 50.0f;
circle->m_p = b2Vec2(0.0f, 0.0f);
mShape = eSHAPE::POLYGON;
}
else
{
mImpl = new b2PolygonShape();<--- Class 'fsCCollisionShape' does not have a copy constructor which is recommended since it has dynamic memory/resource management.<--- Class 'fsCCollisionShape' does not have a operator= which is recommended since it has dynamic memory/resource management.
b2PolygonShape* const polygon = dynamic_cast<b2PolygonShape*>(mImpl);
polygon->SetAsBox(50.0f, 10.0f);
polygon->m_centroid = b2Vec2(0.0f, 0.0f);
mShape = eSHAPE::POLYGON;
}
}
fsCCollisionShape::~fsCCollisionShape()
{
delete mImpl;
}