blob: a5cd23ef6be34e94418c6fab706e1f1c20679ad7 (
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
|
#pragma once
#include "location.h"
#include <functional>
#include <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
#include <utility>
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() const = 0;
Location loc;
};
class BufferedLocationUpdater : public BufferedLocation {
public:
template<typename... LocationArgs>
BufferedLocationUpdater(std::function<void(const BufferedLocation *)> onUpdate, LocationArgs &&... t) :
BufferedLocation {std::forward<LocationArgs>(t)...}, onUpdate {std::move(onUpdate)}
{
updateBuffer();
}
using BufferedLocation::operator=;
private:
void updateBuffer() const override;
std::function<void(const BufferedLocation *)> onUpdate;
};
|