summaryrefslogtreecommitdiff
path: root/src/gui/guiScene.h
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-11-04 21:46:18 +0100
committerGitHub <noreply@github.com>2020-11-04 21:46:18 +0100
commit3356da01513860d899cde503408436f7e1918f63 (patch)
treefa5c33194f29ca26c0118e33a7181ee484ef4da7 /src/gui/guiScene.h
parente3bd6704a0eb65e9490347680441c7a08df36f7a (diff)
downloadminetest-3356da01513860d899cde503408436f7e1918f63.tar.gz
minetest-3356da01513860d899cde503408436f7e1918f63.tar.bz2
minetest-3356da01513860d899cde503408436f7e1918f63.zip
Add model[] formspec element (#10320)
Formspec element to display models, written by @kilbith, rebased and tweaked. Co-authored-by: Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com> Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/gui/guiScene.h')
-rw-r--r--src/gui/guiScene.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/gui/guiScene.h b/src/gui/guiScene.h
new file mode 100644
index 000000000..707e6f66a
--- /dev/null
+++ b/src/gui/guiScene.h
@@ -0,0 +1,85 @@
+/*
+Minetest
+Copyright (C) 2020 Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "irrlichttypes_extrabloated.h"
+#include "ICameraSceneNode.h"
+#include "StyleSpec.h"
+
+using namespace irr;
+
+class GUIScene : public gui::IGUIElement
+{
+public:
+ GUIScene(gui::IGUIEnvironment *env, scene::ISceneManager *smgr,
+ gui::IGUIElement *parent, core::recti rect, s32 id = -1);
+
+ ~GUIScene();
+
+ 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 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;
+};