3 Copyright (C) 2020 Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "irrlichttypes_extrabloated.h"
23 #include "ICameraSceneNode.h"
24 #include "StyleSpec.h"
28 class GUIScene : public gui::IGUIElement
31 GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
32 gui::IGUIElement *parent, core::recti rect, s32 id = -1);
36 scene::IAnimatedMeshSceneNode *setMesh(scene::IAnimatedMesh *mesh = nullptr);
37 void setTexture(u32 idx, video::ITexture *texture);
38 void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
39 void setFrameLoop(s32 begin, s32 end);
40 void setAnimationSpeed(f32 speed);
41 void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
42 void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
43 void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
44 void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles);
47 virtual bool OnEvent(const SEvent &event);
50 void calcOptimalDistance();
51 void updateTargetPos();
52 void updateCamera(scene::ISceneNode *target);
53 void setCameraRotation(v3f rot);
54 /// @return true indicates that the rotation was corrected
55 bool correctBounds(v3f &rot);
58 void updateCameraPos() { m_cam_pos = m_cam->getPosition(); };
59 v3f getCameraRotation() const { return (m_cam_pos - m_target_pos).getHorizontalAngle(); };
60 void rotateCamera(const v3f &delta) { setCameraRotation(getCameraRotation() + delta); };
62 scene::ISceneManager *m_smgr;
63 video::IVideoDriver *m_driver;
64 scene::ICameraSceneNode *m_cam;
65 scene::ISceneNode *m_target = nullptr;
66 scene::IAnimatedMeshSceneNode *m_mesh = nullptr;
68 f32 m_cam_distance = 50.f;
74 v3f m_last_target_pos;
81 bool m_mouse_ctrl = true;
82 bool m_update_cam = false;
83 bool m_inf_rot = false;
84 bool m_initial_rotation = true;
86 video::SColor m_bgcolor = 0;