Magic_Game/Easy2D/Geometry/EGeometry.cpp

115 lines
2.2 KiB
C++
Raw Normal View History

#include "..\egeometry.h"
2017-10-31 17:19:13 +08:00
#include "..\emanagers.h"
2017-10-28 18:48:21 +08:00
#include "..\enodes.h"
2017-10-31 17:19:13 +08:00
#include "..\Win\winbase.h"
e2d::EGeometry::EGeometry()
: m_nCategoryBitmask(0)
, m_nCollisionBitmask(0)
2017-10-31 17:19:13 +08:00
, m_bIsVisiable(true)
2017-10-29 23:48:32 +08:00
, m_nColor(EColor::RED)
, m_fOpacity(1)
, m_pParentNode(nullptr)
2017-10-28 18:48:21 +08:00
, m_pTransformedGeometry(nullptr)
{
2017-10-29 23:48:32 +08:00
}
e2d::EGeometry::~EGeometry()
{
SafeReleaseInterface(&m_pTransformedGeometry);
}
2017-10-28 18:48:21 +08:00
e2d::ENode * e2d::EGeometry::getParentNode() const
{
return m_pParentNode;
}
2017-10-31 17:19:13 +08:00
UINT32 e2d::EGeometry::getCategoryBitmask() const
{
return m_nCategoryBitmask;
}
UINT32 e2d::EGeometry::getCollisionBitmask() const
2017-10-31 17:19:13 +08:00
{
return m_nCollisionBitmask;
2017-10-31 17:19:13 +08:00
}
void e2d::EGeometry::setCategoryBitmask(UINT32 mask)
{
m_nCategoryBitmask = mask;
}
void e2d::EGeometry::setCollisionBitmask(UINT32 mask)
2017-10-31 17:19:13 +08:00
{
m_nCollisionBitmask = mask;
2017-10-31 17:19:13 +08:00
}
void e2d::EGeometry::setVisiable(bool bVisiable)
{
m_bIsVisiable = bVisiable;
}
2017-10-29 23:48:32 +08:00
void e2d::EGeometry::setColor(UINT32 color)
{
m_nColor = color;
}
void e2d::EGeometry::setOpacity(float opacity)
{
2017-10-31 17:19:13 +08:00
m_fOpacity = min(max(opacity, 0), 1);
2017-10-29 23:48:32 +08:00
}
void e2d::EGeometry::_onRender()
{
if (m_pTransformedGeometry)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
GetRenderTarget()->CreateSolidColorBrush(
D2D1::ColorF(
m_nColor,
m_fOpacity),
&GetSolidColorBrush()
);
// <20><><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD>״
GetRenderTarget()->DrawGeometry(m_pTransformedGeometry, GetSolidColorBrush());
// <20>ͷ<EFBFBD><CDB7><EFBFBD>ʱ<EFBFBD><CAB1>Դ
SafeReleaseInterface(&GetSolidColorBrush());
}
}
2017-10-28 18:48:21 +08:00
e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EGeometry::_intersectWith(EGeometry * pGeometry)
{
2017-10-29 23:48:32 +08:00
if (m_pTransformedGeometry && pGeometry->m_pTransformedGeometry)
{
D2D1_GEOMETRY_RELATION relation;
2017-10-29 23:48:32 +08:00
m_pTransformedGeometry->CompareWithGeometry(
pGeometry->m_pTransformedGeometry,
D2D1::Matrix3x2F::Identity(),
&relation
);
2017-10-29 23:48:32 +08:00
return EPhysicsMsg::INTERSECT_RELATION(relation);
}
return EPhysicsMsg::INTERSECT_RELATION::UNKNOWN;
2017-10-28 18:48:21 +08:00
}
void e2d::EGeometry::_transform()
{
2017-10-29 23:48:32 +08:00
if (m_pParentNode)
{
2017-10-31 17:19:13 +08:00
// <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD>״
2017-10-28 18:48:21 +08:00
SafeReleaseInterface(&m_pTransformedGeometry);
2017-10-31 17:19:13 +08:00
// <20><><EFBFBD>ݸ<EFBFBD><DDB8>ڵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
2017-10-28 18:48:21 +08:00
GetFactory()->CreateTransformedGeometry(
_getD2dGeometry(),
m_pParentNode->m_MatriFinal,
2017-10-28 18:48:21 +08:00
&m_pTransformedGeometry
);
2017-10-29 23:48:32 +08:00
2017-10-31 17:19:13 +08:00
// <20>ж<EFBFBD><D0B6><EFBFBD>״<EFBFBD><EFBFBD><E4BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
EPhysicsManager::PhysicsGeometryProc(this);
2017-10-28 18:48:21 +08:00
}
}