summaryrefslogtreecommitdiff
path: root/game/geoData.h
blob: 7bd6ae5f0e7fd91ba068462c8ebc320b5a226655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include <filesystem>
#include <glm/glm.hpp>
#include <span>
#include <utility>
#include <vector>

class GeoData {
public:
	struct Node {
		float height {-1.5F};
	};
	using Quad = std::array<glm::vec3, 4>;

	using Limits = std::pair<glm::ivec2, glm::ivec2>;

	GeoData() = default;
	explicit GeoData(Limits limit, float scale = 10.F);

	void generateRandom();
	void loadFromImages(const std::filesystem::path &, float scale);

	[[nodiscard]] glm::vec3 positionAt(glm::vec2) const;

	[[nodiscard]] unsigned int at(glm::ivec2) const;
	[[nodiscard]] unsigned int at(int x, int y) const;
	[[nodiscard]] Quad quad(glm::vec2) const;

	[[nodiscard]] Limits getLimit() const;
	[[nodiscard]] glm::uvec2 getSize() const;
	[[nodiscard]] float getScale() const;
	[[nodiscard]] std::span<const Node> getNodes() const;

	class RayTracer {
	public:
		RayTracer(glm::vec2 p0, glm::vec2 p1, float scale);

		glm::vec2 next();

	private:
		glm::vec2 p;
		const glm::vec2 d;
		float error;
		glm::vec3 inc;
	};

protected:
	Limits limit {}; // Base grid limits first(x,y) -> second(x,y)
	glm::uvec2 size {};
	float scale {1};
	std::vector<Node> nodes;
};