Dokumentation ...

This commit is contained in:
Hartmut Seichter 2023-07-01 14:35:14 +02:00
parent d21f526290
commit 1a5287bbc2
4 changed files with 110 additions and 58 deletions

View file

@ -23,44 +23,70 @@
#ifndef PARADISO_BITMAP_HPP
#define PARADISO_BITMAP_HPP
#include <paradiso/globals.hpp>
#include <paradiso/geometry.hpp>
#include <paradiso/globals.hpp>
#include <paradiso/rgba.hpp>
namespace paradiso {
/**
* @brief aggregate to handle bitmap data
*/
struct Bitmap final {
/**
* @brief creates an empty bitmap
* @param[in] size extent of bitmap
* @return an empty bitmap
*/
constexpr static Bitmap empty(Size size) noexcept {
return {.size = size, .data = std::vector<RGBA>{size.area()}};
}
/**
* @brief creates a bitmap from manually adding data
* @param[in] size extent of bitmap
* @param[in] values values to set the bitmap from
* @return bitmap with data from this call
*/
template <typename... Arguments>
static constexpr Bitmap from_data(Size size, Arguments... values) noexcept {
assert(sizeof...(Arguments) == size.height * size.width);
return {
.size = size,
.data = {values...}
};
return {.size = size, .data = {values...}};
}
/**
* @brief fills a bitmap uniformly
* @param[in] color RGBA value of a color
* @return reference to itself
*/
constexpr auto fill(const RGBA& color) noexcept {
std::fill(data.begin(), data.end(), color);
return *this;
}
/**
* @brief access a pixel by position
* @param[in] x x-component of position
* @param[in] y y-component of position
* @return reference to pixel data at position
*/
constexpr RGBA& pixel(std::integral auto x, std::integral auto y) {
return data[y * size.width + x];
}
/**
* @brief access a pixel by position
* @param[in] x x-component of position
* @param[in] y y-component of position
* @return const reference to pixel data at position
*/
constexpr const RGBA& pixel(std::integral auto x,
std::integral auto y) const {
return data[y * size.width + x];
}
Size size{.width = 0, .height = 0};
std::vector<RGBA> data{};
Size size{.width = 0, .height = 0}; //!< extent of bitmap
std::vector<RGBA> data{}; //!< data storage
};
} // namespace paradiso

View file

@ -25,37 +25,34 @@
#include <paradiso/globals.hpp>
namespace paradiso
{
namespace paradiso {
struct Point final
{
using value_type = int32_t;
value_type x{0}, y{0};
};
struct Point final {
using value_type = int32_t;
value_type x{0}, y{0};
};
struct Size final
{
using value_type = uint32_t;
value_type width{0}, height{0};
struct Size final {
using value_type = uint32_t;
value_type width{0}, height{0};
constexpr auto area() const noexcept
{
return width * height;
}
};
constexpr auto area() const noexcept { return width * height; }
struct Rectangle
{
Point position;
Size size;
constexpr Size minimal_extent() const noexcept {
return {.width = std::min(width, height),
.height = std::min(width, height)};
}
};
constexpr bool contains(const Point &p) const noexcept
{
return p.x >= position.x && p.x <= position.x + size.width &&
p.y >= position.y && p.y <= position.y + size.height;
}
};
}
struct Rectangle {
Point position;
Size size;
constexpr bool contains(const Point& p) const noexcept {
return p.x >= position.x && p.x <= position.x + size.width &&
p.y >= position.y && p.y <= position.y + size.height;
}
};
} // namespace paradiso
#endif

View file

@ -23,21 +23,22 @@
#ifndef PARADISO_SPRITE_HPP
#define PARADISO_SPRITE_HPP
#include <paradiso/bitmap.hpp>
#include <paradiso/globals.hpp>
#include <paradiso/bitmap.hpp>
#include <paradiso/matrix.hpp>
#include <paradiso/vector.hpp>
namespace paradiso {
/**
* @brief simple sprite handler
*/
struct Sprite final {
using ChangeCountType = std::uint64_t;
static constexpr Sprite create() noexcept { return {}; }
Bitmap bitmap{}; //!< associated bitmap
Bitmap bitmap{};
Vector2<float> pivot{Vector2<float>::zero()};
Vector2<float> pivot{Vector2<float>::zero()}; //!< center point
// 0 3 | y
// +------+ | ^
@ -46,23 +47,23 @@ struct Sprite final {
// +------+ | z
// 1 2 |
std::array<std::uint32_t, 6> indices{0, 1, 2, 0, 2, 3};
std::array<std::uint32_t, 6> indices{0, 1, 2, 0, 2, 3}; //!< topology
std::array<Vector3<float>, 4> vertices{
std::array<Vector3<float>, 4> vertices{ //!< geometry
Vector3<float>::make(-1.0f, +1.0f, 0.0f),
Vector3<float>::make(-1.0f, -1.0f, 0.0f),
Vector3<float>::make(+1.0f, -1.0f, 0.0f),
Vector3<float>::make(+1.0f, +1.0f, 0.0f)};
std::array<Vector3<float>, 4> normals{
std::array<Vector3<float>, 4> normals{ //!< normals
Vector3<float>::z_axis(), Vector3<float>::z_axis(),
Vector3<float>::z_axis(), Vector3<float>::z_axis()};
std::array<Vector2<float>, 4> texture_coordinates{
std::array<Vector2<float>, 4> texture_coordinates{ //!< UV coordinates
Vector2<float>::make(0.0f, 0.0f), Vector2<float>::make(1.0f, 0.0f),
Vector2<float>::make(1.0f, 1.0f), Vector2<float>::make(0.0f, 1.0f)};
ChangeCountType change_count{};
ChangeCountType change_count{}; //!< cookie to track changes
};
} // namespace paradiso