Compare commits
2 Commits
1ac55d7e10
...
04bc08e9c0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
04bc08e9c0 | ||
![]() |
79dd655e96 |
16
cpp/src/camera.cpp
Normal file
16
cpp/src/camera.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "camera.hpp"
|
||||||
|
#include "math.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
// for now only pass-through placeholder functions,
|
||||||
|
// since we draw the whole map
|
||||||
|
|
||||||
|
WindowPos Camera::WorldToWindow(WorldPos world) const
|
||||||
|
{
|
||||||
|
return WindowPos{world[0], world[1]};
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldPos Camera::WindowToWorld(WindowPos window) const
|
||||||
|
{
|
||||||
|
return WorldPos{window[0], window[1]};
|
||||||
|
}
|
16
cpp/src/camera.hpp
Normal file
16
cpp/src/camera.hpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "math.hpp"
|
||||||
|
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowPos WorldToWindow(WorldPos) const;
|
||||||
|
WorldPos WindowToWorld(WindowPos) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// TODO this should be replaced with a matrix
|
||||||
|
float m_Zoom;
|
||||||
|
WorldPos m_RectCorner; // upper left corner (0,0) of the drawn regios
|
||||||
|
|
||||||
|
};
|
118
cpp/src/math.hpp
118
cpp/src/math.hpp
@ -259,121 +259,3 @@ struct TilePosHash {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// old stuff - TODO delete
|
|
||||||
|
|
||||||
// constexpr double EQUALITY_LIMIT = 1e-6;
|
|
||||||
// template <typename T> struct Vec2D {
|
|
||||||
// public:
|
|
||||||
// Vec2D() = default;
|
|
||||||
// ~Vec2D() = default;
|
|
||||||
//
|
|
||||||
// template <typename U>
|
|
||||||
// Vec2D(Vec2D<U> other) {
|
|
||||||
// this->x = static_cast<T>(other.x);
|
|
||||||
// this->y = static_cast<T>(other.y);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Vec2D& operator+=(const Vec2D &other) {
|
|
||||||
// x += other.x;
|
|
||||||
// y += other.y;
|
|
||||||
// return *this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template <typename U>
|
|
||||||
// requires std::is_arithmetic_v<U>
|
|
||||||
// Vec2D& operator/=(U k) {
|
|
||||||
// this->x /= static_cast<T>(k);
|
|
||||||
// this->y /= static_cast<T>(k);
|
|
||||||
// return *this;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// friend Vec2D operator+(const Vec2D &a, const Vec2D &b) {
|
|
||||||
// return Vec2D{a.x + b.x, a.y + b.y};
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// friend Vec2D operator-(const Vec2D &a, const Vec2D &b) {
|
|
||||||
// return Vec2D{a.x - b.x, a.y - b.y};
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template <typename U>
|
|
||||||
// requires std::is_arithmetic_v<U>
|
|
||||||
// friend Vec2D operator*(U k, const Vec2D &v)
|
|
||||||
// {
|
|
||||||
// return Vec2D{k * v.x, k * v.y};
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template <typename U>
|
|
||||||
// requires std::is_arithmetic_v<U>
|
|
||||||
// friend Vec2D operator/(const Vec2D &v, U k)
|
|
||||||
// {
|
|
||||||
// return Vec2D{v.x / k, v.y / k};
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// friend bool operator==(const Vec2D &a, const Vec2D &b) {
|
|
||||||
// if constexpr (std::is_integral_v<T>) {
|
|
||||||
// return a.x == b.x && a.y == b.y;
|
|
||||||
// } else if constexpr (std::is_floating_point_v<T>) {
|
|
||||||
// return a.distance(b) < EQUALITY_LIMIT;
|
|
||||||
// } else {
|
|
||||||
// static_assert("Unhandled comparison");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Vec2D operator*(float b) const { return Vec2D{b * x, b * y}; }
|
|
||||||
//
|
|
||||||
// T distance_squared(const Vec2D &other) const {
|
|
||||||
// T dx = x - other.x;
|
|
||||||
// T dy = y - other.y;
|
|
||||||
// return dx * dx + dy * dy;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// T distance(const Vec2D &other) const
|
|
||||||
// requires std::floating_point<T>
|
|
||||||
// {
|
|
||||||
// return sqrt(distance_squared(other));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// void normalize()
|
|
||||||
// requires std::floating_point<T>
|
|
||||||
// {
|
|
||||||
// auto length = sqrt(x * x + y * y);
|
|
||||||
// if (length < EQUALITY_LIMIT) {
|
|
||||||
// x = y = 0;
|
|
||||||
// } else {
|
|
||||||
// x /= length;
|
|
||||||
// y /= length;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Vec2D normalized()
|
|
||||||
// requires std::floating_point<T>
|
|
||||||
// {
|
|
||||||
// Vec2D v(*this);
|
|
||||||
// v.normalize();
|
|
||||||
// return v;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Vec2D orthogonal() const
|
|
||||||
// {
|
|
||||||
// Vec2D v(*this);
|
|
||||||
//
|
|
||||||
// std::swap(v.x, v.y);
|
|
||||||
// v.x = -v.x;
|
|
||||||
// return v;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template <typename U> Vec2D(std::initializer_list<U> list) {
|
|
||||||
// assert(list.size() == 2);
|
|
||||||
// auto first_element = *list.begin();
|
|
||||||
// auto second_element = *(list.begin() + 1);
|
|
||||||
// x = static_cast<T>(first_element);
|
|
||||||
// y = static_cast<T>(second_element);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// T x, y;
|
|
||||||
//
|
|
||||||
// friend std::ostream &operator<<(std::ostream &os, const Vec2D &obj) {
|
|
||||||
// os << "( " << obj.x << ", " << obj.y << ")";
|
|
||||||
// return os;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
@ -13,7 +13,7 @@ PathFinderBase::PathFinderBase(const Map* map) : m_Map(map) {}
|
|||||||
|
|
||||||
// LinearPathFinder also lives here, since it is too small to get it's
|
// LinearPathFinder also lives here, since it is too small to get it's
|
||||||
// own implementation file
|
// own implementation file
|
||||||
Path LinearPathFinder::CalculatePath(WorldPos start, WorldPos end)
|
Path LinearPathFinder::CalculatePath(WorldPos, WorldPos end) // first argument (start pos) not used
|
||||||
{
|
{
|
||||||
auto path = Path{end};
|
auto path = Path{end};
|
||||||
return path;
|
return path;
|
||||||
|
@ -21,7 +21,6 @@ std::expected<void, std::string> UserInput::Init() { return {}; }
|
|||||||
|
|
||||||
const std::vector<UserAction> &UserInput::GetActions() {
|
const std::vector<UserAction> &UserInput::GetActions() {
|
||||||
m_Actions.clear();
|
m_Actions.clear();
|
||||||
static WorldPos move_direction = {0.0f, 0.0f};
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user