summaryrefslogtreecommitdiff
path: root/gfx/gl/bufferedLocation.h
blob: 8302b3c9945b83b044c5a14c4f00a48ceb3d1814 (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 "location.h"
#include <functional>
#include <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
#include <tuple>

class BufferedLocation {
public:
	BufferedLocation(Position3D = {}, Rotation3D = {});
	BufferedLocation(const Location &);
	virtual ~BufferedLocation() = default;

	BufferedLocation & operator=(const Location &);

	operator const Location &() const;

	[[nodiscard]] Position3D position() const;
	[[nodiscard]] Rotation3D rotation() const;
	void setPosition(Position3D, bool update = true);
	void setRotation(Rotation3D, bool update = true);
	void setLocation(Position3D, Rotation3D);

	[[nodiscard]] glm::mat4 getTransform() const;
	[[nodiscard]] glm::mat4 getRotationTransform() const;

private:
	virtual void updateBuffer() = 0;

	Location loc;
};

template<typename... Target> class BufferedLocationT : public BufferedLocation {
public:
	template<typename... LocationArgs>
	BufferedLocationT(Target &&... target, LocationArgs &&... t) :
		BufferedLocation {std::forward<LocationArgs>(t)...}, target {std::forward<Target>(target)...}
	{
		updateBuffer();
	}

	using BufferedLocation::operator=;

private:
	void
	updateBuffer() override
	{
		std::apply(std::invoke<const Target &...>, target) = getTransform();
	}

	std::tuple<Target...> target;
};