Start implementing pixel conversions as classes. WiP.
This commit is contained in:
parent
5cea116b8f
commit
83963e67ea
4 changed files with 154 additions and 21 deletions
|
@ -2,19 +2,90 @@
|
|||
#define id73F121AEE1EB4BA0980FAC025E5CDF05
|
||||
|
||||
#include "doorkeeper/components/tileiterator.hpp"
|
||||
#include "doorkeeper/implem/maptypes.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace dk {
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<2> get_diamond_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize );
|
||||
//MapType_IsometricStaggered,
|
||||
//MapType_Isometric,
|
||||
//MapType_Orthogonal,
|
||||
//MapType_Hex
|
||||
template <uint32_t D>
|
||||
class PixelConv {
|
||||
public:
|
||||
typedef Vector<D> coords;
|
||||
|
||||
explicit PixelConv ( MapTypes parType );
|
||||
|
||||
virtual coords to_pixel ( const coords& parFrom, const coords& parSize ) const = 0;
|
||||
MapTypes map_type ( void ) const;
|
||||
|
||||
private:
|
||||
const MapTypes m_map_type;
|
||||
};
|
||||
|
||||
template <uint32_t D>
|
||||
class PixelConvSquare : public PixelConv<D> {
|
||||
public:
|
||||
using base_class = PixelConv<D>;
|
||||
using typename base_class::coords;
|
||||
|
||||
PixelConvSquare ( void );
|
||||
virtual ~PixelConvSquare ( void ) noexcept = default;
|
||||
|
||||
virtual coords to_pixel ( const coords& parFrom, const coords& parSize ) const;
|
||||
};
|
||||
|
||||
class PixelConvDiamond : public PixelConv<2> {
|
||||
public:
|
||||
using base_class = PixelConv<2>;
|
||||
using base_class::coords;
|
||||
|
||||
PixelConvDiamond ( bool parStaggered, bool parFirstReentrant );
|
||||
virtual ~PixelConvDiamond ( void ) noexcept = default;
|
||||
|
||||
virtual coords to_pixel ( const coords& parFrom, const coords& parSize ) const;
|
||||
|
||||
protected:
|
||||
PixelConvDiamond ( MapTypes parType, bool parStaggered, bool parFirstReentrant );
|
||||
};
|
||||
|
||||
class PixelConvHalfDiamond : public PixelConvDiamond {
|
||||
public:
|
||||
using base_class = PixelConvDiamond;
|
||||
using base_class::coords;
|
||||
|
||||
explicit PixelConvHalfDiamond ( bool parHalfVertically );
|
||||
virtual ~PixelConvHalfDiamond ( void ) noexcept = default;
|
||||
|
||||
virtual coords to_pixel ( const coords& parFrom, const coords& parSize ) const;
|
||||
|
||||
private:
|
||||
const coords m_div;
|
||||
};
|
||||
|
||||
class PixelConvHex : public PixelConv<2> {
|
||||
public:
|
||||
using base_class = PixelConv<2>;
|
||||
using base_class::coords;
|
||||
|
||||
explicit PixelConvHex ( bool parFirstReentrant );
|
||||
virtual ~PixelConvHex ( void ) noexcept = default;
|
||||
|
||||
virtual coords to_pixel ( const coords& parFrom, const coords& parSize ) const;
|
||||
};
|
||||
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<2> get_half_diamond_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize );
|
||||
Vector<2> get_diamond_coordinates ( const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize ) a_pure;
|
||||
|
||||
template <typename T, typename T1>
|
||||
Vector<2> get_half_diamond_coordinates ( const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize ) a_pure;
|
||||
|
||||
template <uint32_t D, typename T, typename T1>
|
||||
dk::Vector<D> get_square_coordinates ( const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<D>& parSize );
|
||||
Vector<D> get_square_coordinates ( const TileIterator<T, D, T1>& parIterator, const Vector<D>& parSize ) a_pure;
|
||||
|
||||
template <typename T, typename T1>
|
||||
dk::Vector<2> get_hex_coordinates ( const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize );
|
||||
Vector<2> get_hex_coordinates ( const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize ) a_pure;
|
||||
} //namespace dk
|
||||
|
||||
#include "doorkeeper/implem/pixelconv.inl"
|
||||
|
|
|
@ -1,30 +1,51 @@
|
|||
namespace dk {
|
||||
template <typename T, typename T1>
|
||||
inline
|
||||
dk::Vector<2> get_diamond_coordinates (const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize) {
|
||||
typedef dk::Vector<2> vec;
|
||||
|
||||
const auto from(parIterator.position());
|
||||
const dk::CoordinateScalarType xoffs = from.y() % 2;
|
||||
|
||||
return from * parSize + vec(xoffs * parSize.x() / 2, 0);
|
||||
Vector<2> get_diamond_coordinates (const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize) {
|
||||
PixelConvDiamond pconv(true, true);
|
||||
return pconv.to_pixel(parIterator.position(), parSize);
|
||||
}
|
||||
|
||||
template <typename T, typename T1>
|
||||
inline
|
||||
dk::Vector<2> get_half_diamond_coordinates (const dk::TileIterator<T, 2, T1>& parIterator, const dk::Vector<2>& parSize) {
|
||||
typedef dk::Vector<2> vec;
|
||||
return get_diamond_coordinates(parIterator, parSize / vec(1, 2));
|
||||
Vector<2> get_half_diamond_coordinates (const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize) {
|
||||
PixelConvHalfDiamond pconv(true);
|
||||
return pconv.to_pixel(parIterator.position(), parSize);
|
||||
}
|
||||
|
||||
template <uint32_t D, typename T, typename T1>
|
||||
inline
|
||||
dk::Vector<D> get_square_coordinates (const dk::TileIterator<T, D, T1>& parIterator, const dk::Vector<D>& parSize) {
|
||||
return parIterator.position() * parSize;
|
||||
Vector<D> get_square_coordinates (const TileIterator<T, D, T1>& parIterator, const Vector<D>& parSize) {
|
||||
PixelConvSquare<D> pconv;
|
||||
return pconv.to_pixel(parIterator.position(), 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) {
|
||||
//}
|
||||
template <typename T, typename T1>
|
||||
inline
|
||||
Vector<2> get_hex_coordinates (const TileIterator<T, 2, T1>& parIterator, const Vector<2>& parSize) {
|
||||
PixelConvHex pconv(true);
|
||||
return pconv.to_pixel(parIterator.position(), parSize);
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
PixelConv<D>::PixelConv (MapTypes parType) :
|
||||
m_map_type(parType)
|
||||
{
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
MapTypes PixelConv<D>::map_type() const {
|
||||
return m_map_type;
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
PixelConvSquare<D>::PixelConvSquare() :
|
||||
base_class(MapType_Orthogonal)
|
||||
{
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
auto PixelConvSquare<D>::to_pixel (const coords& parFrom, const coords& parSize) const -> coords {
|
||||
return parFrom * parSize;
|
||||
}
|
||||
} //namespace dk
|
||||
|
|
|
@ -17,6 +17,7 @@ add_library(${PROJECT_NAME}
|
|||
tylermapsource.cpp
|
||||
tiger.c
|
||||
typename.cpp
|
||||
pixelconv.cpp
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
|
|
40
src/pixelconv.cpp
Normal file
40
src/pixelconv.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include "doorkeeper/components/pixelconv.hpp"
|
||||
|
||||
namespace dk {
|
||||
PixelConvDiamond::PixelConvDiamond (bool parStaggered, bool parFirstReentrant) :
|
||||
base_class(parStaggered ? MapType_IsometricStaggered : MapType_Isometric)
|
||||
{
|
||||
}
|
||||
|
||||
PixelConvDiamond::PixelConvDiamond (MapTypes parType, bool parStaggered, bool parFirstReentrant) :
|
||||
base_class(MapType_IsometricStaggered)
|
||||
{
|
||||
}
|
||||
|
||||
auto PixelConvDiamond::to_pixel (const coords& parFrom, const coords& parSize) const -> coords {
|
||||
const auto from(parFrom);
|
||||
const CoordinateScalarType xoffs = from.y() % 2;
|
||||
|
||||
return from * parSize + coords(xoffs * parSize.x() / 2, 0);
|
||||
}
|
||||
|
||||
PixelConvHalfDiamond::PixelConvHalfDiamond (bool parHalfVertically) :
|
||||
base_class(MapType_IsometricStaggered, true, true),
|
||||
m_div(parHalfVertically ? coords(1, 2) : coords(2, 1))
|
||||
{
|
||||
}
|
||||
|
||||
auto PixelConvHalfDiamond::to_pixel (const coords& parFrom, const coords& parSize) const -> coords {
|
||||
return base_class::to_pixel(parFrom, parSize / m_div);
|
||||
}
|
||||
|
||||
PixelConvHex::PixelConvHex (bool parFirstReentrant) :
|
||||
base_class(MapType_Hex)
|
||||
{
|
||||
}
|
||||
|
||||
auto PixelConvHex::to_pixel (const coords& parFrom, const coords& parSize) const -> coords {
|
||||
DK_ASSERT(false); //not implemented
|
||||
return coords(0);
|
||||
}
|
||||
} //namespace dk
|
Loading…
Add table
Reference in a new issue