summaryrefslogtreecommitdiff
path: root/include/llmr/map/transform.hpp
blob: 39b533c6b8282e4a8b95bee86a89a661ea5b5749 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef LLMR_MAP_TRANSFORM
#define LLMR_MAP_TRANSFORM


#include <llmr/util/vec.hpp>
#include <llmr/util/mat4.hpp>
#include <llmr/util/animation.hpp>

#include <cmath>
#include <cstdint>
#include <forward_list>

namespace llmr {

struct box;

class Transform {
public:
    Transform();

    // Make noncopyable
    Transform(const Transform&) = delete;
    Transform(const Transform&&) = delete;
    Transform &operator=(const Transform&) = delete;
    Transform &operator=(const Transform&&) = delete;

    // Animations
    bool needsAnimation() const;
    void updateAnimations();

    // Relative changes
    void moveBy(double dx, double dy);
    void scaleBy(double ds, double cx, double cy);
    void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey);

    // Absolute changes
    void setScale(double scale);
    void setAngle(double angle, double duration = 0);
    void setZoom(double zoom);
    void setLonLat(double lon, double lat);

    // Getters
    void matrixFor(mat4& matrix, const vec3<int32_t>& id) const;
    float getZoom() const;
    int32_t getIntegerZoom() const;
    double getScale() const;
    double getAngle() const;
    void getLonLat(double& lon, double& lat) const;


    // Temporary
    void mapCornersToBox(uint32_t z, box& b) const;

private:
    double pixel_x() const;
    double pixel_y() const;

public:
    // logical dimensions
    uint32_t width = 0;
    uint32_t height = 0;

    // physical (framebuffer) dimensions
    uint32_t fb_width = 0;
    uint32_t fb_height = 0;

    double pixelRatio = 1;

private:
    double x = 0, y = 0; // pixel values of the map center in the current scale
    double angle = 0;
    double scale = 1;

    double min_scale = pow(2, 0);
    double max_scale = pow(2, 20);

    // tile size
    const int32_t size = 512;

    // cache values for spherical mercator math
    double zc, Bc, Cc;

    std::forward_list<util::animation> animations;
};

}

#endif