Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
guiScene.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2020 Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
4
5#pragma once
6
8#include "ICameraSceneNode.h"
9#include "StyleSpec.h"
10
11using namespace irr;
12
13class GUIScene : public gui::IGUIElement
14{
15public:
16 GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
17 gui::IGUIElement *parent, core::recti rect, s32 id = -1);
18
19 ~GUIScene();
20
21 scene::IAnimatedMeshSceneNode *setMesh(scene::IAnimatedMesh *mesh = nullptr);
22 void setTexture(u32 idx, video::ITexture *texture);
23 void setBackgroundColor(const video::SColor &color) noexcept { m_bgcolor = color; };
24 void setFrameLoop(f32 begin, f32 end);
25 void setAnimationSpeed(f32 speed);
26 void enableMouseControl(bool enable) noexcept { m_mouse_ctrl = enable; };
27 void setRotation(v2f rot) noexcept { m_custom_rot = rot; };
28 void enableContinuousRotation(bool enable) noexcept { m_inf_rot = enable; };
29 void setStyles(const std::array<StyleSpec, StyleSpec::NUM_STATES> &styles);
30
31 virtual void draw();
32 virtual bool OnEvent(const SEvent &event);
33
34private:
36 void updateTargetPos();
37 void updateCamera(scene::ISceneNode *target);
38 void setCameraRotation(v3f rot);
40 bool correctBounds(v3f &rot);
41 void cameraLoop();
42
43 void updateCameraPos() { m_cam_pos = m_cam->getPosition(); };
44 v3f getCameraRotation() const { return (m_cam_pos - m_target_pos).getHorizontalAngle(); };
45 void rotateCamera(const v3f &delta) { setCameraRotation(getCameraRotation() + delta); };
46
47 scene::ISceneManager *m_smgr;
48 video::IVideoDriver *m_driver;
49 scene::ICameraSceneNode *m_cam;
50 scene::ISceneNode *m_target = nullptr;
51 scene::IAnimatedMeshSceneNode *m_mesh = nullptr;
52
53 f32 m_cam_distance = 50.f;
54
55 u64 m_last_time = 0;
56
60 // Cursor positions
63 // Initial rotation
65
66 bool m_mouse_ctrl = true;
67 bool m_update_cam = false;
68 bool m_inf_rot = false;
69 bool m_initial_rotation = true;
70
71 video::SColor m_bgcolor = 0;
72};
Definition guiScene.h:14
void setAnimationSpeed(f32 speed)
Sets the animation speed (FPS) for the mesh.
Definition guiScene.cpp:157
scene::ICameraSceneNode * m_cam
Definition guiScene.h:49
virtual void draw()
Definition guiScene.cpp:65
void enableMouseControl(bool enable) noexcept
Definition guiScene.h:26
v2f m_last_pos
Definition guiScene.h:62
void setTexture(u32 idx, video::ITexture *texture)
Definition guiScene.cpp:52
v3f m_target_pos
Definition guiScene.h:58
~GUIScene()
Definition guiScene.cpp:28
v3f m_last_target_pos
Definition guiScene.h:59
scene::ISceneNode * m_target
Definition guiScene.h:50
video::IVideoDriver * m_driver
Definition guiScene.h:48
void setBackgroundColor(const video::SColor &color) noexcept
Definition guiScene.h:23
void setCameraRotation(v3f rot)
Definition guiScene.cpp:209
bool correctBounds(v3f &rot)
Definition guiScene.cpp:223
void setFrameLoop(f32 begin, f32 end)
Sets the frame loop range for the mesh.
Definition guiScene.cpp:148
void updateTargetPos()
Definition guiScene.cpp:202
virtual bool OnEvent(const SEvent &event)
Definition guiScene.cpp:113
f32 m_cam_distance
Definition guiScene.h:53
scene::IAnimatedMeshSceneNode * m_mesh
Definition guiScene.h:51
scene::IAnimatedMeshSceneNode * setMesh(scene::IAnimatedMesh *mesh=nullptr)
Definition guiScene.cpp:35
void setRotation(v2f rot) noexcept
Definition guiScene.h:27
video::SColor m_bgcolor
Definition guiScene.h:71
v2f m_curr_pos
Definition guiScene.h:61
void rotateCamera(const v3f &delta)
Definition guiScene.h:45
void updateCamera(scene::ISceneNode *target)
Definition guiScene.cpp:191
v3f m_cam_pos
Definition guiScene.h:57
scene::ISceneManager * m_smgr
Definition guiScene.h:47
GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr, gui::IGUIElement *parent, core::recti rect, s32 id=-1)
Definition guiScene.cpp:15
void calcOptimalDistance()
Definition guiScene.cpp:164
bool m_mouse_ctrl
Definition guiScene.h:66
void updateCameraPos()
Definition guiScene.h:43
void setStyles(const std::array< StyleSpec, StyleSpec::NUM_STATES > &styles)
Definition guiScene.cpp:136
bool m_initial_rotation
Definition guiScene.h:69
bool m_inf_rot
Definition guiScene.h:68
bool m_update_cam
Definition guiScene.h:67
u64 m_last_time
Definition guiScene.h:55
void enableContinuousRotation(bool enable) noexcept
Definition guiScene.h:28
v3f getCameraRotation() const
Definition guiScene.h:44
void cameraLoop()
Definition guiScene.cpp:243
v2f m_custom_rot
Definition guiScene.h:64
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
Definition clientmap.h:30
#define idx(x, y)
Definition noise.cpp:490