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