1 | #ifndef GAME_MANDELBROT_HPP |
2 | #define GAME_MANDELBROT_HPP |
3 |
|
4 |
|
5 | #include "ZydecoCommon.hpp" |
6 | #include "IUpdateable.hpp" |
7 | #include "IEventMouseSubscriber.hpp" |
8 |
|
9 |
|
10 | class IEventHandler; |
11 | class IWindow; |
12 | class GLRenderObjectFractal; |
13 | class GLTexture; |
14 | class GLUniformUploader; |
15 |
|
16 |
|
17 | struct MandelbrotSettings |
18 | { |
19 | double zoom = 2.0; |
20 | double pos_x = 0.0; |
21 | double pos_y = 0.0; |
22 |
|
23 | bool restart = true; |
24 | int do_interlacing = false; |
25 | int first_interlace = 1; |
26 | int interlace_layer = 0; |
27 | float param_z = 0.0; |
28 | float brightness = 1.0; |
29 | int iteration_count = 100; |
30 | int iteration_step = 50; |
31 | int adjusted_iteration_step = 50; |
32 | int current_iteration = 0; |
33 | float discard_threshold = 4.; |
34 | }; |
35 |
|
36 |
|
37 | const int ADAM7_MATRIX[8][8] = { |
38 | {1, 6, 4, 6, 2, 6, 4, 6}, |
39 | {7, 7, 7, 7, 7, 7, 7, 7}, |
40 | {5, 6, 5, 6, 5, 6, 5, 6}, |
41 | {7, 7, 7, 7, 7, 7, 7, 7}, |
42 | {3, 6, 4, 6, 3, 6, 4, 6}, |
43 | {7, 7, 7, 7, 7, 7, 7, 7}, |
44 | {5, 6, 5, 6, 5, 6, 5, 6}, |
45 | {7, 7, 7, 7, 7, 7, 7, 7}, |
46 | }; |
47 |
|
48 |
|
49 | struct ldvec3 { |
50 | long double x = 0.0; |
51 | long double y = 0.0; |
52 | long double z = 0.0; |
53 |
|
54 | ldvec3 operator +(const ldvec3& lhs) |
55 | { |
56 | return ldvec3{lhs.x + x, lhs.y + y, lhs.z + z}; |
57 | } |
58 |
|
59 | ldvec3 operator -(const ldvec3& lhs) |
60 | { |
61 | return ldvec3{lhs.x - x, lhs.y - y, lhs.z - z}; |
62 | } |
63 |
|
64 | long double operator *(const ldvec3& lhs) |
65 | { |
66 | return lhs.x * x + lhs.y * y + 0.0; |
67 | } |
68 |
|
69 | ldvec3 operator *(const double& lhs) |
70 | { |
71 | return ldvec3{lhs * x, lhs * y, lhs * z}; |
72 | } |
73 |
|
74 | ldvec3 operator /(const ldvec3& lhs) |
75 | { |
76 | return ldvec3{x/lhs.x, y/lhs.y, z/lhs.z}; |
77 | } |
78 | }; |
79 |
|
80 |
|
81 | class Mandelbrot : public IUpdateable, public IEventMouseSubscriber |
82 | { |
83 | public: |
84 | Mandelbrot(IEventHandler& r_event_handler, IWindow& r_window, MandelbrotSettings *p_settings); |
85 | ~Mandelbrot(); |
86 |
|
87 | bool Update() override; |
88 |
|
89 | void OnMouseLeftDownEvent(uint64_t x, uint64_t y) override; |
90 | void OnMouseLeftUpEvent(uint64_t x, uint64_t y) override; |
91 |
|
92 | void OnMouseMiddleDownEvent(uint64_t x, uint64_t y) override; |
93 | void OnMouseMiddleUpEvent(uint64_t x, uint64_t y) override; |
94 |
|
95 | void OnMouseRightDownEvent(uint64_t x, uint64_t y) override; |
96 | void OnMouseRightUpEvent(uint64_t x, uint64_t y) override; |
97 |
|
98 | void OnMouseMoveEvent(uint64_t x, uint64_t y, int64_t dx, int64_t dy) override; |
99 |
|
100 | void OnMouseWheelScrollEvent(int64_t dx, int64_t dy) override; |
101 |
|
102 | private: |
103 | MandelbrotSettings *m_pSettings; |
104 |
|
105 | uint64_t m_windowWidth; |
106 | uint64_t m_windowHeight; |
107 |
|
108 | GLsync m_glSyncObject = nullptr; |
109 |
|
110 | uint64_t m_mousex = 0; |
111 | uint64_t m_mousey = 0; |
112 | bool m_mouseDown = false; |
113 | bool m_restart = true; |
114 |
|
115 | GLUniformUploader *m_pComputeUniformUploader; |
116 | GLRenderObjectFractal *m_pRenderObject; |
117 | GLTexture *m_pTexture; |
118 |
|
119 | IEventHandler& m_rEventHandler; |
120 | IWindow& m_rWindow; |
121 | }; |
122 |
|
123 |
|
124 | #endif |
125 |
|