Update ContactList & FixtureList
This commit is contained in:
parent
8bd215403a
commit
fcb4f3bc63
|
|
@ -146,42 +146,223 @@ namespace kiwano
|
||||||
class ContactList
|
class ContactList
|
||||||
: public List<Contact>
|
: public List<Contact>
|
||||||
{
|
{
|
||||||
|
template <typename _Ty>
|
||||||
|
class IteratorImpl
|
||||||
|
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||||
|
{
|
||||||
|
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContactList()
|
IteratorImpl(const _Ty& elem)
|
||||||
|
: elem_(elem)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactList(const Contact& first)
|
inline typename herit::reference operator*() const
|
||||||
{
|
{
|
||||||
Contact current = first;
|
return const_cast<typename herit::reference>(elem_);
|
||||||
while (current.GetB2Contact())
|
}
|
||||||
|
|
||||||
|
inline typename herit::pointer operator->() const
|
||||||
{
|
{
|
||||||
push_back(current);
|
return std::pointer_traits<typename herit::pointer>::pointer_to(**this);
|
||||||
current = current.GetB2Contact()->GetNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline IteratorImpl& operator++()
|
||||||
|
{
|
||||||
|
elem_ = elem_.GetB2Contact()->GetNext();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline IteratorImpl operator++(int)
|
||||||
|
{
|
||||||
|
IteratorImpl old = *this;
|
||||||
|
operator++();
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator== (const IteratorImpl& rhs) const
|
||||||
|
{
|
||||||
|
return elem_.GetB2Contact() == rhs.elem_.GetB2Contact();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!= (const IteratorImpl& rhs) const
|
||||||
|
{
|
||||||
|
return !operator==(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
_Ty elem_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = Contact;
|
||||||
|
using iterator = IteratorImpl<value_type>;
|
||||||
|
using const_iterator = IteratorImpl<const value_type>;
|
||||||
|
|
||||||
|
inline ContactList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ContactList(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_;
|
||||||
|
};
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物理接触边列表
|
/// @brief 物理接触边列表
|
||||||
class ContactEdgeList
|
class ContactEdgeList
|
||||||
: public List<ContactEdge>
|
|
||||||
{
|
{
|
||||||
|
template <typename _Ty>
|
||||||
|
class IteratorImpl
|
||||||
|
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||||
|
{
|
||||||
|
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContactEdgeList()
|
|
||||||
|
inline IteratorImpl(const _Ty& elem)
|
||||||
|
: elem_(elem)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactEdgeList(const ContactEdge& first)
|
inline typename herit::reference operator*() const
|
||||||
{
|
{
|
||||||
ContactEdge current = first;
|
return const_cast<typename herit::reference>(elem_);
|
||||||
while (current.GetB2ContactEdge())
|
}
|
||||||
|
|
||||||
|
inline typename herit::pointer operator->() const
|
||||||
{
|
{
|
||||||
push_back(current);
|
return std::pointer_traits<typename herit::pointer>::pointer_to(**this);
|
||||||
current = current.GetB2ContactEdge()->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
||||||
|
|
@ -126,20 +126,111 @@ namespace kiwano
|
||||||
class FixtureList
|
class FixtureList
|
||||||
: public List<Fixture>
|
: public List<Fixture>
|
||||||
{
|
{
|
||||||
|
template <typename _Ty>
|
||||||
|
class IteratorImpl
|
||||||
|
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||||
|
{
|
||||||
|
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FixtureList()
|
IteratorImpl(const _Ty& elem)
|
||||||
|
: elem_(elem)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FixtureList(const Fixture& first)
|
inline typename herit::reference operator*() const
|
||||||
{
|
{
|
||||||
Fixture current = first;
|
return const_cast<typename herit::reference>(elem_);
|
||||||
while (current.GetB2Fixture())
|
}
|
||||||
|
|
||||||
|
inline typename herit::pointer operator->() const
|
||||||
{
|
{
|
||||||
push_back(current);
|
return std::pointer_traits<typename herit::pointer>::pointer_to(**this);
|
||||||
current = current.GetB2Fixture()->GetNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline IteratorImpl& operator++()
|
||||||
|
{
|
||||||
|
elem_ = elem_.GetB2Contact()->GetNext();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline IteratorImpl operator++(int)
|
||||||
|
{
|
||||||
|
IteratorImpl old = *this;
|
||||||
|
operator++();
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator== (const IteratorImpl& rhs) const
|
||||||
|
{
|
||||||
|
return elem_.GetB2Contact() == rhs.elem_.GetB2Contact();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!= (const IteratorImpl& rhs) const
|
||||||
|
{
|
||||||
|
return !operator==(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
_Ty elem_;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
using value_type = Fixture;
|
||||||
|
using iterator = IteratorImpl<value_type>;
|
||||||
|
using const_iterator = IteratorImpl<const value_type>;
|
||||||
|
|
||||||
|
inline FixtureList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline FixtureList(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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,11 @@ namespace kiwano
|
||||||
world_.SetGravity(b2Vec2(gravity.x, gravity.y));
|
world_.SetGravity(b2Vec2(gravity.x, gravity.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContactList World::GetContactList()
|
||||||
|
{
|
||||||
|
return ContactList(Contact(world_.GetContactList()));
|
||||||
|
}
|
||||||
|
|
||||||
void World::Update(Duration dt)
|
void World::Update(Duration dt)
|
||||||
{
|
{
|
||||||
world_.Step(dt.Seconds(), vel_iter_, pos_iter_);
|
world_.Step(dt.Seconds(), vel_iter_, pos_iter_);
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ namespace kiwano
|
||||||
/// @brief 设置重力 [N]
|
/// @brief 设置重力 [N]
|
||||||
void SetGravity(Vec2 gravity);
|
void SetGravity(Vec2 gravity);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取物理接触列表
|
||||||
|
ContactList GetContactList();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取全局缩放比例
|
/// @brief 获取全局缩放比例
|
||||||
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
/// @details 缩放比例是指由物理世界的单位米转换到屏幕像素的比例,默认比例为1:100
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue