New code to calculate the tiles position esp. in 2D.
This commit is contained in:
parent
a9630341c7
commit
b2eae08d02
4 changed files with 65 additions and 0 deletions
|
@ -10,6 +10,9 @@
|
|||
#include <cstdint>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
class TileIterator;
|
||||
|
||||
namespace implem {
|
||||
template <uint32_t D>
|
||||
size_t get_index_from_pos ( const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize ) a_pure;
|
||||
|
@ -35,11 +38,15 @@ namespace dk {
|
|||
|
||||
template <uint32_t D>
|
||||
Vector<CoordinateScalarType, D> buildPastEndCoordinate ( const Vector<CoordinateScalarType, D>& parFrom, const Vector<CoordinateScalarType, D>& parTo ) a_pure;
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
const Vector<CoordinateScalarType, D>& get_from_from_iterator ( const TileIterator<T, D, T1>& parIterator );
|
||||
} //namespace implem
|
||||
|
||||
template <typename T, uint32_t D, typename T1=typename std::remove_cv<T>::type>
|
||||
class TileIterator : public boost::iterator_facade<TileIterator<T, D>, T, boost::bidirectional_traversal_tag> {
|
||||
friend class boost::iterator_core_access;
|
||||
friend const Vector<CoordinateScalarType, D>& implem::get_from_from_iterator<> ( const TileIterator& parIterator );
|
||||
typedef std::vector<T1> vector_type;
|
||||
typedef typename implem::TypeWithQualifiers<T, vector_type>::result qualif_vector_type;
|
||||
public:
|
||||
|
|
22
include/doorkeeper/helpers/tilecoordinates.hpp
Normal file
22
include/doorkeeper/helpers/tilecoordinates.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef id73F121AEE1EB4BA0980FAC025E5CDF05
|
||||
#define id73F121AEE1EB4BA0980FAC025E5CDF05
|
||||
|
||||
#include "doorkeeper/components/tileiterator.hpp"
|
||||
|
||||
namespace dkh {
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<dk::CoordinateScalarType, 2> get_diamond_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize );
|
||||
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<dk::CoordinateScalarType, 2> get_half_diamond_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize );
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
dk::Vector<dk::CoordinateScalarType, D> get_square_coordinates ( const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, D>& parSize );
|
||||
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<dk::CoordinateScalarType, 2> get_hex_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize );
|
||||
} //namespace dkh
|
||||
|
||||
#include "doorkeeper/implem/tilecoordinates.inl"
|
||||
|
||||
#endif
|
31
include/doorkeeper/implem/tilecoordinates.inl
Normal file
31
include/doorkeeper/implem/tilecoordinates.inl
Normal file
|
@ -0,0 +1,31 @@
|
|||
namespace dkh {
|
||||
template <typename T, typename T1>
|
||||
inline
|
||||
dk::Vector<dk::CoordinateScalarType, 2> get_diamond_coordinates (const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize) {
|
||||
typedef dk::Vector<dk::CoordinateScalarType, 2> vec;
|
||||
|
||||
const auto abspos(parIterator.abs_position());
|
||||
const auto from(dk::implem::get_from_from_iterator(parIterator));
|
||||
const dk::CoordinateScalarType xoffs = abspos.y() % 2;
|
||||
|
||||
return (abspos - from) * parSize + vec(xoffs * parSize.x() / 2, 0);
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
inline
|
||||
dk::Vector<dk::CoordinateScalarType, 2> get_half_diamond_coordinates (const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize) {
|
||||
typedef dk::Vector<dk::CoordinateScalarType, 2> vec;
|
||||
return get_diamond_coordinates(parIterator, parSize / vec(1, 2));
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
inline
|
||||
dk::Vector<dk::CoordinateScalarType, D> get_square_coordinates (const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, D>& parSize) {
|
||||
return (parIterator.abs_position() - dk::implem::get_from_from_iterator(parIterator)) * parSize;
|
||||
}
|
||||
|
||||
//template <typename T, typename T1>
|
||||
//inline
|
||||
//dk::Vector<dk::CoordinateScalarType, 2> get_hex_coordinates (const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<dk::CoordinateScalarType, 2>& parSize) {
|
||||
//}
|
||||
} //namespace dkh
|
|
@ -30,6 +30,11 @@ namespace dk {
|
|||
retval[D - 1] = parTo[D - 1];
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
inline const Vector<CoordinateScalarType, D>& get_from_from_iterator (const TileIterator<T, D, T1>& parIterator) {
|
||||
return parIterator.m_from;
|
||||
}
|
||||
} //namespace implem
|
||||
|
||||
template <typename T, uint32_t D, typename T1>
|
||||
|
|
Loading…
Add table
Reference in a new issue