blob: d9e0b78294e0cd28f998984b487ae7c544d7071f (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
scene::IAnimatedMeshSceneNode *setMesh(scene::IAnimatedMesh *mesh = nullptr);
void setTexture(u32 idx, video::ITexture *texture);
void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
void setFrameLoop(s32 begin, s32 end);
void setAnimationSpeed(f32 speed);
void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles);
virtual void draw();
virtual bool OnEvent(const SEvent &event);
private:
void calcOptimalDistance();
void updateTargetPos();
void updateCamera(scene::ISceneNode *target);
void setCameraRotation(v3f rot);
/// @return true indicates that the rotation was corrected
bool correctBounds(v3f &rot);
void cameraLoop();
void updateCameraPos() { m_cam_pos = m_cam->getPosition(); };
v3f getCameraRotation() const { return (m_cam_pos - m_target_pos).getHorizontalAngle(); };
void rotateCamera(const v3f &delta) { setCameraRotation(getCameraRotation() + delta); };
scene::ISceneManager *m_smgr;
video::IVideoDriver *m_driver;
scene::ICameraSceneNode *m_cam;
scene::ISceneNode *m_target = nullptr;
scene::IAnimatedMeshSceneNode *m_mesh = nullptr;
f32 m_cam_distance = 50.f;
u64 m_last_time = 0;
v3f m_cam_pos;
v3f m_target_pos;
v3f m_last_target_pos;
// Cursor positions
v2f m_curr_pos;
v2f m_last_pos;
// Initial rotation
v2f m_custom_rot;
bool m_mouse_ctrl = true;
bool m_update_cam = false;
bool m_inf_rot = false;
bool m_initial_rotation = true;
video::SColor m_bgcolor = 0;
};
|