Update ContactEdge
This commit is contained in:
parent
bdd399af16
commit
c189ff79fa
|
|
@ -13,6 +13,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\kiwano-physics\Body.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\Contact.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\ContactEdge.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\ContactEvent.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\Fixture.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\helper.h" />
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Body.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Contact.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\ContactEdge.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\ContactEvent.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Fixture.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Joint.cpp" />
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano-physics\Fixture.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\Contact.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\ContactEvent.h" />
|
||||
<ClInclude Include="..\..\src\kiwano-physics\ContactEdge.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Body.cpp" />
|
||||
|
|
@ -19,5 +20,6 @@
|
|||
<ClCompile Include="..\..\src\kiwano-physics\Fixture.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\Contact.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\ContactEvent.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano-physics\ContactEdge.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
#include <kiwano-physics/helper.h>
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/Contact.h>
|
||||
#include <kiwano-physics/ContactEdge.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,17 +86,5 @@ namespace kiwano
|
|||
return world->World2Stage(contact_->GetTangentSpeed());
|
||||
}
|
||||
|
||||
|
||||
ContactEdge::ContactEdge()
|
||||
: edge_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ContactEdge::ContactEdge(b2ContactEdge* edge)
|
||||
: ContactEdge()
|
||||
{
|
||||
SetB2ContactEdge(edge);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,39 +108,14 @@ namespace kiwano
|
|||
b2Contact* GetB2Contact() const;
|
||||
void SetB2Contact(b2Contact* contact);
|
||||
|
||||
bool operator== (const Contact& rhs) const;
|
||||
bool operator!= (const Contact& rhs) const;
|
||||
|
||||
private:
|
||||
b2Contact* contact_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 接触边
|
||||
class KGE_API ContactEdge
|
||||
{
|
||||
public:
|
||||
ContactEdge();
|
||||
ContactEdge(b2ContactEdge* edge);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触物体
|
||||
Body* GetOtherBody() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触
|
||||
Contact GetContact() const;
|
||||
|
||||
b2ContactEdge* GetB2ContactEdge() const;
|
||||
void SetB2ContactEdge(b2ContactEdge* edge);
|
||||
|
||||
private:
|
||||
b2ContactEdge* edge_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ÎïÀí½Ó´¥Áбí
|
||||
class ContactList
|
||||
|
|
@ -183,7 +158,7 @@ namespace kiwano
|
|||
|
||||
inline bool operator== (const IteratorImpl& rhs) const
|
||||
{
|
||||
return elem_.GetB2Contact() == rhs.elem_.GetB2Contact();
|
||||
return elem_ == rhs.elem_;
|
||||
}
|
||||
|
||||
inline bool operator!= (const IteratorImpl& rhs) const
|
||||
|
|
@ -253,118 +228,6 @@ namespace kiwano
|
|||
value_type first_;
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触边列表
|
||||
class ContactEdgeList
|
||||
{
|
||||
template <typename _Ty>
|
||||
class IteratorImpl
|
||||
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
{
|
||||
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||
|
||||
public:
|
||||
|
||||
inline IteratorImpl(const _Ty& elem)
|
||||
: elem_(elem)
|
||||
{
|
||||
}
|
||||
|
||||
inline typename herit::reference operator*() const
|
||||
{
|
||||
return const_cast<typename herit::reference>(elem_);
|
||||
}
|
||||
|
||||
inline typename herit::pointer operator->() const
|
||||
{
|
||||
return std::pointer_traits<typename herit::pointer>::pointer_to(**this);
|
||||
}
|
||||
|
||||
inline IteratorImpl& operator++()
|
||||
{
|
||||
elem_ = elem_.GetB2ContactEdge()->next;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IteratorImpl operator++(int)
|
||||
{
|
||||
IteratorImpl old = *this;
|
||||
operator++();
|
||||
return old;
|
||||
}
|
||||
|
||||
inline bool operator== (const IteratorImpl& rhs) const
|
||||
{
|
||||
return elem_.GetB2ContactEdge() == rhs.elem_.GetB2ContactEdge();
|
||||
}
|
||||
|
||||
inline bool operator!= (const IteratorImpl& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
_Ty elem_;
|
||||
};
|
||||
|
||||
public:
|
||||
using value_type = ContactEdge;
|
||||
using iterator = IteratorImpl<value_type>;
|
||||
using const_iterator = IteratorImpl<const value_type>;
|
||||
|
||||
inline ContactEdgeList()
|
||||
{
|
||||
}
|
||||
|
||||
inline ContactEdgeList(const value_type& first)
|
||||
: first_(first)
|
||||
{
|
||||
}
|
||||
|
||||
inline const value_type& front() const
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
inline value_type& front()
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
inline iterator begin()
|
||||
{
|
||||
return iterator(first_);
|
||||
}
|
||||
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return const_iterator(first_);
|
||||
}
|
||||
|
||||
inline iterator end()
|
||||
{
|
||||
return iterator(nullptr);
|
||||
}
|
||||
|
||||
inline const_iterator end() const
|
||||
{
|
||||
return cend();
|
||||
}
|
||||
|
||||
inline const_iterator cend() const
|
||||
{
|
||||
return const_iterator(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
value_type first_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
|
@ -380,12 +243,8 @@ namespace kiwano
|
|||
inline void Contact::ResetRestitution() { KGE_ASSERT(contact_); contact_->ResetRestitution(); }
|
||||
inline b2Contact* Contact::GetB2Contact() const { return contact_; }
|
||||
inline void Contact::SetB2Contact(b2Contact* contact) { contact_ = contact; }
|
||||
|
||||
inline bool ContactEdge::IsValid() const { return edge_ != nullptr; }
|
||||
inline Body* ContactEdge::GetOtherBody() const { KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); }
|
||||
inline Contact ContactEdge::GetContact() const { KGE_ASSERT(edge_); return Contact(edge_->contact); }
|
||||
inline b2ContactEdge* ContactEdge::GetB2ContactEdge() const { return edge_; }
|
||||
inline void ContactEdge::SetB2ContactEdge(b2ContactEdge* edge) { edge_ = edge; }
|
||||
inline bool Contact::operator==(const Contact& rhs) const { return contact_ == rhs.contact_; }
|
||||
inline bool Contact::operator!=(const Contact& rhs) const { return contact_ != rhs.contact_; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2018-2019 Kiwano - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano-physics/ContactEdge.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
|
||||
ContactEdge::ContactEdge()
|
||||
: edge_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ContactEdge::ContactEdge(b2ContactEdge* edge)
|
||||
: ContactEdge()
|
||||
{
|
||||
SetB2ContactEdge(edge);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
// Copyright (c) 2018-2019 Kiwano - Nomango
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/Contact.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
/**
|
||||
* \addtogroup Physics
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 接触边
|
||||
class KGE_API ContactEdge
|
||||
{
|
||||
public:
|
||||
ContactEdge();
|
||||
ContactEdge(b2ContactEdge* edge);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 是否有效
|
||||
bool IsValid() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触物体
|
||||
Body* GetOtherBody() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取接触
|
||||
Contact GetContact() const;
|
||||
|
||||
b2ContactEdge* GetB2ContactEdge() const;
|
||||
void SetB2ContactEdge(b2ContactEdge* edge);
|
||||
|
||||
bool operator== (const ContactEdge& rhs) const;
|
||||
bool operator!= (const ContactEdge& rhs) const;
|
||||
|
||||
private:
|
||||
b2ContactEdge* edge_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触边列表
|
||||
class ContactEdgeList
|
||||
{
|
||||
template <typename _Ty>
|
||||
class IteratorImpl
|
||||
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
{
|
||||
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||
|
||||
public:
|
||||
inline IteratorImpl(const _Ty& elem)
|
||||
: elem_(elem)
|
||||
{
|
||||
}
|
||||
|
||||
inline typename herit::reference operator*() const
|
||||
{
|
||||
return const_cast<typename herit::reference>(elem_);
|
||||
}
|
||||
|
||||
inline typename herit::pointer operator->() const
|
||||
{
|
||||
return std::pointer_traits<typename herit::pointer>::pointer_to(**this);
|
||||
}
|
||||
|
||||
inline IteratorImpl& operator++()
|
||||
{
|
||||
elem_ = elem_.GetB2ContactEdge()->next;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IteratorImpl operator++(int)
|
||||
{
|
||||
IteratorImpl old = *this;
|
||||
operator++();
|
||||
return old;
|
||||
}
|
||||
|
||||
inline bool operator== (const IteratorImpl& rhs) const
|
||||
{
|
||||
return elem_ == rhs.elem_;
|
||||
}
|
||||
|
||||
inline bool operator!= (const IteratorImpl& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
_Ty elem_;
|
||||
};
|
||||
|
||||
public:
|
||||
using value_type = ContactEdge;
|
||||
using iterator = IteratorImpl<value_type>;
|
||||
using const_iterator = IteratorImpl<const value_type>;
|
||||
|
||||
inline ContactEdgeList()
|
||||
{
|
||||
}
|
||||
|
||||
inline ContactEdgeList(const value_type& first)
|
||||
: first_(first)
|
||||
{
|
||||
}
|
||||
|
||||
inline const value_type& front() const
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
inline value_type& front()
|
||||
{
|
||||
return first_;
|
||||
}
|
||||
|
||||
inline iterator begin()
|
||||
{
|
||||
return iterator(first_);
|
||||
}
|
||||
|
||||
inline const_iterator begin() const
|
||||
{
|
||||
return cbegin();
|
||||
}
|
||||
|
||||
inline const_iterator cbegin() const
|
||||
{
|
||||
return const_iterator(first_);
|
||||
}
|
||||
|
||||
inline iterator end()
|
||||
{
|
||||
return iterator(nullptr);
|
||||
}
|
||||
|
||||
inline const_iterator end() const
|
||||
{
|
||||
return cend();
|
||||
}
|
||||
|
||||
inline const_iterator cend() const
|
||||
{
|
||||
return const_iterator(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
value_type first_;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
inline bool ContactEdge::IsValid() const { return edge_ != nullptr; }
|
||||
inline Body* ContactEdge::GetOtherBody() const { KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); }
|
||||
inline Contact ContactEdge::GetContact() const { KGE_ASSERT(edge_); return Contact(edge_->contact); }
|
||||
inline b2ContactEdge* ContactEdge::GetB2ContactEdge() const { return edge_; }
|
||||
inline void ContactEdge::SetB2ContactEdge(b2ContactEdge* edge) { edge_ = edge; }
|
||||
inline bool ContactEdge::operator==(const ContactEdge& rhs) const { return edge_ == rhs.edge_; }
|
||||
inline bool ContactEdge::operator!=(const ContactEdge& rhs) const { return edge_ != rhs.edge_; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -117,6 +117,9 @@ namespace kiwano
|
|||
b2Fixture* GetB2Fixture() const;
|
||||
void SetB2Fixture(b2Fixture* fixture);
|
||||
|
||||
bool operator== (const Fixture& rhs) const;
|
||||
bool operator!= (const Fixture& rhs) const;
|
||||
|
||||
private:
|
||||
b2Fixture* fixture_;
|
||||
};
|
||||
|
|
@ -150,7 +153,7 @@ namespace kiwano
|
|||
|
||||
inline IteratorImpl& operator++()
|
||||
{
|
||||
elem_ = elem_.GetB2Contact()->GetNext();
|
||||
elem_ = elem_.GetB2Fixture()->GetNext();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +166,7 @@ namespace kiwano
|
|||
|
||||
inline bool operator== (const IteratorImpl& rhs) const
|
||||
{
|
||||
return elem_.GetB2Contact() == rhs.elem_.GetB2Contact();
|
||||
return elem_ == rhs.elem_;
|
||||
}
|
||||
|
||||
inline bool operator!= (const IteratorImpl& rhs) const
|
||||
|
|
@ -235,16 +238,18 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline bool Fixture::IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); }
|
||||
inline void Fixture::SetSensor(bool sensor) { KGE_ASSERT(fixture_); fixture_->SetSensor(sensor); }
|
||||
inline float Fixture::GetDensity() const { KGE_ASSERT(fixture_); return fixture_->GetDensity(); }
|
||||
inline void Fixture::SetDensity(float density) { KGE_ASSERT(fixture_); fixture_->SetDensity(density); }
|
||||
inline float Fixture::GetFriction() const { KGE_ASSERT(fixture_); return fixture_->GetFriction(); }
|
||||
inline void Fixture::SetFriction(float friction) { KGE_ASSERT(fixture_); fixture_->SetFriction(friction); }
|
||||
inline float Fixture::GetRestitution() const { KGE_ASSERT(fixture_); return fixture_->GetRestitution(); }
|
||||
inline void Fixture::SetRestitution(float restitution) { KGE_ASSERT(fixture_); fixture_->SetRestitution(restitution); }
|
||||
inline bool Fixture::IsValid() const { return fixture_ != nullptr; }
|
||||
inline b2Fixture* Fixture::GetB2Fixture() const { return fixture_; }
|
||||
inline void Fixture::SetB2Fixture(b2Fixture* fixture) { fixture_ = fixture; }
|
||||
inline bool Fixture::IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); }
|
||||
inline void Fixture::SetSensor(bool sensor) { KGE_ASSERT(fixture_); fixture_->SetSensor(sensor); }
|
||||
inline float Fixture::GetDensity() const { KGE_ASSERT(fixture_); return fixture_->GetDensity(); }
|
||||
inline void Fixture::SetDensity(float density) { KGE_ASSERT(fixture_); fixture_->SetDensity(density); }
|
||||
inline float Fixture::GetFriction() const { KGE_ASSERT(fixture_); return fixture_->GetFriction(); }
|
||||
inline void Fixture::SetFriction(float friction) { KGE_ASSERT(fixture_); fixture_->SetFriction(friction); }
|
||||
inline float Fixture::GetRestitution() const { KGE_ASSERT(fixture_); return fixture_->GetRestitution(); }
|
||||
inline void Fixture::SetRestitution(float restitution) { KGE_ASSERT(fixture_); fixture_->SetRestitution(restitution); }
|
||||
inline bool Fixture::IsValid() const { return fixture_ != nullptr; }
|
||||
inline b2Fixture* Fixture::GetB2Fixture() const { return fixture_; }
|
||||
inline void Fixture::SetB2Fixture(b2Fixture* fixture) { fixture_ = fixture; }
|
||||
inline bool Fixture::operator==(const Fixture& rhs) const { return fixture_ == rhs.fixture_; }
|
||||
inline bool Fixture::operator!=(const Fixture& rhs) const { return fixture_ != rhs.fixture_; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue