1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#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;
}