EListenerPhysicsContact更名为EListenerPhysicsCollision

This commit is contained in:
Nomango 2017-11-05 14:45:53 +08:00
parent e2c796ee59
commit 36b1d9ef50
8 changed files with 50 additions and 54 deletions

View File

@ -219,7 +219,7 @@
<ClCompile Include="Geometry\EGeometry.cpp" /> <ClCompile Include="Geometry\EGeometry.cpp" />
<ClCompile Include="Geometry\EPhysicsMsg.cpp" /> <ClCompile Include="Geometry\EPhysicsMsg.cpp" />
<ClCompile Include="Geometry\ERectangle.cpp" /> <ClCompile Include="Geometry\ERectangle.cpp" />
<ClCompile Include="Listener\EListenerPhysicsContact.cpp" /> <ClCompile Include="Listener\EListenerPhysicsCollision.cpp" />
<ClCompile Include="Listener\EListenerKeyboard.cpp" /> <ClCompile Include="Listener\EListenerKeyboard.cpp" />
<ClCompile Include="Listener\EListenerKeyboardPress.cpp" /> <ClCompile Include="Listener\EListenerKeyboardPress.cpp" />
<ClCompile Include="Listener\EListener.cpp" /> <ClCompile Include="Listener\EListener.cpp" />

View File

@ -198,9 +198,6 @@
<ClCompile Include="Listener\EListenerPhysics.cpp"> <ClCompile Include="Listener\EListenerPhysics.cpp">
<Filter>Listener</Filter> <Filter>Listener</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Listener\EListenerPhysicsContact.cpp">
<Filter>Listener</Filter>
</ClCompile>
<ClCompile Include="Common\EFont.cpp"> <ClCompile Include="Common\EFont.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
@ -210,6 +207,9 @@
<ClCompile Include="Common\ETexture.cpp"> <ClCompile Include="Common\ETexture.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Listener\EListenerPhysicsCollision.cpp">
<Filter>Listener</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Win\winbase.h"> <ClInclude Include="Win\winbase.h">

View File

@ -6,7 +6,7 @@
e2d::EGeometry::EGeometry() e2d::EGeometry::EGeometry()
: m_bTransformed(false) : m_bTransformed(false)
, m_nCategoryBitmask(0) , m_nCategoryBitmask(0)
,m_nContactBitmask(0) , m_nCollisionBitmask(0)
, m_bIsVisiable(true) , m_bIsVisiable(true)
, m_nColor(EColor::RED) , m_nColor(EColor::RED)
, m_fOpacity(1) , m_fOpacity(1)
@ -20,11 +20,6 @@ e2d::EGeometry::~EGeometry()
SafeReleaseInterface(&m_pTransformedGeometry); SafeReleaseInterface(&m_pTransformedGeometry);
} }
bool e2d::EGeometry::isContactWith(EGeometry * geometry)
{
return ((this->m_nContactBitmask & geometry->m_nCategoryBitmask) != 0);
}
e2d::ENode * e2d::EGeometry::getParentNode() const e2d::ENode * e2d::EGeometry::getParentNode() const
{ {
return m_pParentNode; return m_pParentNode;
@ -35,9 +30,9 @@ UINT32 e2d::EGeometry::getCategoryBitmask() const
return m_nCategoryBitmask; return m_nCategoryBitmask;
} }
UINT32 e2d::EGeometry::getContactBitmask() const UINT32 e2d::EGeometry::getCollisionBitmask() const
{ {
return m_nContactBitmask; return m_nCollisionBitmask;
} }
void e2d::EGeometry::setCategoryBitmask(UINT32 mask) void e2d::EGeometry::setCategoryBitmask(UINT32 mask)
@ -45,9 +40,9 @@ void e2d::EGeometry::setCategoryBitmask(UINT32 mask)
m_nCategoryBitmask = mask; m_nCategoryBitmask = mask;
} }
void e2d::EGeometry::setContactBitmask(UINT32 mask) void e2d::EGeometry::setCollisionBitmask(UINT32 mask)
{ {
m_nContactBitmask = mask; m_nCollisionBitmask = mask;
} }
void e2d::EGeometry::setVisiable(bool bVisiable) void e2d::EGeometry::setVisiable(bool bVisiable)

View File

@ -1,29 +1,29 @@
#include "..\elisteners.h" #include "..\elisteners.h"
#include "..\egeometry.h" #include "..\egeometry.h"
e2d::EListenerPhysicsContact::EListenerPhysicsContact() e2d::EListenerPhysicsCollision::EListenerPhysicsCollision()
: EListenerPhysics() : EListenerPhysics()
{ {
} }
e2d::EListenerPhysicsContact::EListenerPhysicsContact(const EString & name) e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name)
: EListenerPhysics(name) : EListenerPhysics(name)
{ {
} }
e2d::EListenerPhysicsContact::EListenerPhysicsContact(const COLLISION_LISTENER_CALLBACK & callback) e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const COLLISION_LISTENER_CALLBACK & callback)
: EListenerPhysics() : EListenerPhysics()
{ {
this->m_Callback = callback; this->m_Callback = callback;
} }
e2d::EListenerPhysicsContact::EListenerPhysicsContact(const EString & name, const COLLISION_LISTENER_CALLBACK & callback) e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name, const COLLISION_LISTENER_CALLBACK & callback)
: EListenerPhysics(name) : EListenerPhysics(name)
{ {
this->m_Callback = callback; this->m_Callback = callback;
} }
void e2d::EListenerPhysicsContact::_callOn() void e2d::EListenerPhysicsCollision::_callOn()
{ {
if (EPhysicsMsg::getMsg() == EPhysicsMsg::OVERLAP || if (EPhysicsMsg::getMsg() == EPhysicsMsg::OVERLAP ||
EPhysicsMsg::getMsg() == EPhysicsMsg::CONTAINS || EPhysicsMsg::getMsg() == EPhysicsMsg::CONTAINS ||

View File

@ -26,19 +26,20 @@ void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry)
if (pActiveGeometry != pPassiveGeometry) if (pActiveGeometry != pPassiveGeometry)
{ {
// 判断两物体是否会产生接触消息 // 判断两物体是否是相互冲突的物体
if (!pActiveGeometry->isContactWith(pPassiveGeometry)) if (pActiveGeometry->m_nCollisionBitmask & pPassiveGeometry->m_nCategoryBitmask)
continue;
// pPassiveGeometry 为被动方
EPhysicsMsg::s_pPassiveGeometry = pPassiveGeometry;
// 获取两方的关系
EPhysicsMsg::s_nRelation = pActiveGeometry->_intersectWith(pPassiveGeometry);
// 如果关系不为未知或无交集,响应监听器
if (EPhysicsMsg::s_nRelation != EPhysicsMsg::UNKNOWN &&
EPhysicsMsg::s_nRelation != EPhysicsMsg::DISJOINT)
{ {
// 执行监听器 // pPassiveGeometry 为被动方
PhysicsListenerProc(); EPhysicsMsg::s_pPassiveGeometry = pPassiveGeometry;
// 获取两方的关系
EPhysicsMsg::s_nRelation = pActiveGeometry->_intersectWith(pPassiveGeometry);
// 如果关系不为未知或无交集,响应监听器
if (EPhysicsMsg::s_nRelation != EPhysicsMsg::UNKNOWN &&
EPhysicsMsg::s_nRelation != EPhysicsMsg::DISJOINT)
{
// 执行监听器
PhysicsListenerProc();
}
} }
} }
} }

View File

@ -49,27 +49,22 @@ public:
virtual ~EGeometry(); virtual ~EGeometry();
// 判断是否可以和另一几何图形产生接触消息
bool isContactWith(
EGeometry * geometry
);
// 获取父节点 // 获取父节点
ENode * getParentNode() const; ENode * getParentNode() const;
// 获取类别掩码 // 获取类别掩码
UINT32 getCategoryBitmask() const; UINT32 getCategoryBitmask() const;
// 获取接触掩码 // »ñÈ¡³åÍ»ÑÚÂë
UINT32 getContactBitmask() const; UINT32 getCollisionBitmask() const;
// 设置类别掩码 // 设置类别掩码
void setCategoryBitmask( void setCategoryBitmask(
UINT32 mask UINT32 mask
); );
// 设置接触掩码 // ÉèÖóåÍ»ÑÚÂë
void setContactBitmask( void setCollisionBitmask(
UINT32 mask UINT32 mask
); );
@ -106,7 +101,7 @@ protected:
bool m_bTransformed; bool m_bTransformed;
bool m_bIsVisiable; bool m_bIsVisiable;
UINT32 m_nCategoryBitmask; UINT32 m_nCategoryBitmask;
UINT32 m_nContactBitmask; UINT32 m_nCollisionBitmask;
UINT32 m_nColor; UINT32 m_nColor;
float m_fOpacity; float m_fOpacity;
ENode * m_pParentNode; ENode * m_pParentNode;

View File

@ -328,12 +328,6 @@ protected:
}; };
// 物理世界消息监听器回调函数(参数:主动方、被动方、两方关系)
typedef std::function<void(ENode *active, ENode *passive, int relation)> PHYSICS_LISTENER_CALLBACK;
// 碰撞消息监听器回调函数(参数:主动方、被动方)
typedef std::function<void(ENode *active, ENode *passive)> COLLISION_LISTENER_CALLBACK;
// 物理世界消息监听器 // 物理世界消息监听器
class EListenerPhysics : class EListenerPhysics :
public EListener public EListener
@ -380,23 +374,22 @@ protected:
}; };
class EListenerPhysicsContact : // 几何体冲突消息监听器
class EListenerPhysicsCollision :
public EListenerPhysics public EListenerPhysics
{ {
friend EMsgManager;
public: public:
EListenerPhysicsContact(); EListenerPhysicsCollision();
EListenerPhysicsContact( EListenerPhysicsCollision(
const EString &name const EString &name
); );
EListenerPhysicsContact( EListenerPhysicsCollision(
const COLLISION_LISTENER_CALLBACK &callback const COLLISION_LISTENER_CALLBACK &callback
); );
EListenerPhysicsContact( EListenerPhysicsCollision(
const EString &name, const EString &name,
const COLLISION_LISTENER_CALLBACK &callback const COLLISION_LISTENER_CALLBACK &callback
); );

View File

@ -103,13 +103,19 @@ struct EWindowStyle
} }
}; };
// 二维向量
typedef EPoint EVec; typedef EPoint EVec;
// 字符串
typedef std::wstring EString; typedef std::wstring EString;
// Vector 容器
template<typename T> template<typename T>
using EVector = std::vector<T>; using EVector = std::vector<T>;
class ENode;
// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) // 定时器回调函数(参数为该定时器被调用的次数,从 0 开始)
typedef std::function<void(int)> TIMER_CALLBACK; typedef std::function<void(int)> TIMER_CALLBACK;
@ -134,4 +140,10 @@ typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_DBLCLK_LISTENER_CALLBACK;
// 鼠标拖动消息监听回调函数(参数为拖动前位置和拖动后位置) // 鼠标拖动消息监听回调函数(参数为拖动前位置和拖动后位置)
typedef std::function<void(EPoint begin, EPoint end)> MOUSE_DRAG_LISTENER_CALLBACK; typedef std::function<void(EPoint begin, EPoint end)> MOUSE_DRAG_LISTENER_CALLBACK;
// 物理世界消息监听器回调函数(参数:主动方、被动方、两方关系)
typedef std::function<void(ENode *active, ENode *passive, int relation)> PHYSICS_LISTENER_CALLBACK;
// 碰撞消息监听器回调函数(参数:主动方、被动方)
typedef std::function<void(ENode *active, ENode *passive)> COLLISION_LISTENER_CALLBACK;
} }