RigsofRods
Soft-body Physics Simulation
GUI_DirectionArrow.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #include "GUI_DirectionArrow.h"
24 
25 #include "Actor.h"
26 #include "AppContext.h"
27 #include "GfxActor.h"
28 #include "GfxScene.h"
29 #include "Language.h"
30 #include "GUIManager.h"
31 
32 #include <Overlay/OgreOverlayManager.h>
33 #include <fmt/core.h>
34 
35 using namespace RoR;
36 using namespace GUI;
37 
39 {
40  // Load overlay from .overlay file
41  m_overlay = Ogre::OverlayManager::getSingleton().getByName("tracks/DirectionArrow");
42 
43  // openGL fix
44  m_overlay->show();
45  m_overlay->hide();
46 
47  this->CreateArrow();
48 }
49 
51 {
52  // setup direction arrow
53  Ogre::Entity* arrow_entity = App::GetGfxScene()->GetSceneManager()->createEntity("arrow2.mesh");
54  arrow_entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
55 
56  // Add entity to the scene node
57  m_node = new Ogre::SceneNode(App::GetGfxScene()->GetSceneManager());
58  m_node->attachObject(arrow_entity);
59  m_node->setVisible(false);
60  m_node->setScale(0.1, 0.1, 0.1);
61  m_node->setPosition(Ogre::Vector3(-0.6, +0.4, -1));
62  m_node->setFixedYawAxis(true, Ogre::Vector3::UNIT_Y);
63  m_overlay->add3D(m_node);
64 }
65 
67 {
69 
70  if (data.simbuf_dir_arrow_visible)
71  {
72  // Set visible
73  m_node->setVisible(true);
74  m_overlay->show();
75 
76  // Update arrow direction
77  m_node->lookAt(data.simbuf_dir_arrow_target, Ogre::Node::TS_WORLD, Ogre::Vector3::UNIT_Y);
78  }
79  else
80  {
81  m_node->setVisible(false);
82  m_overlay->hide();
83  }
84 }
85 
86 // Only effective in main menu, simulation visibility is set in `Update()`
88 {
89  if (m_node && m_overlay)
90  {
91  m_node->setVisible(value);
92  if (value)
93  m_overlay->show();
94  else
95  m_overlay->hide();
96  }
97 }
RoR::GUI::DirectionArrow::CreateArrow
void CreateArrow()
Must be called again after OGRE scenemanager is cleared.
Definition: GUI_DirectionArrow.cpp:50
RoR::GfxScene::GetSimDataBuffer
GameContextSB & GetSimDataBuffer()
Definition: GfxScene.h:61
RoR::GameContextSB
Definition: SimBuffers.h:196
RoR::GameContextSB::simbuf_dir_arrow_visible
bool simbuf_dir_arrow_visible
Definition: SimBuffers.h:216
RoR::GUI::DirectionArrow::Update
void Update(RoR::GfxActor *player)
Definition: GUI_DirectionArrow.cpp:66
RoR::GUI::DirectionArrow::SetVisible
void SetVisible(bool value)
Only effective in main menu, simulation visibility is set in Update()
Definition: GUI_DirectionArrow.cpp:87
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
GUI_DirectionArrow.h
Race direction arrow and text info (using OGRE Overlay)
Language.h
GUIManager.h
Actor.h
RoR::GfxScene::GetSceneManager
Ogre::SceneManager * GetSceneManager()
Definition: GfxScene.h:64
RoR::GUI::DirectionArrow::LoadOverlay
void LoadOverlay()
Must be called after meshes+overlays were loaded.
Definition: GUI_DirectionArrow.cpp:38
GfxScene.h
RoR::GfxActor
Definition: GfxActor.h:52
GfxActor.h
Manager for all visuals belonging to a single actor.
RoR::GameContextSB::simbuf_dir_arrow_target
Ogre::Vector3 simbuf_dir_arrow_target
Definition: SimBuffers.h:214
RoR
Definition: AppContext.h:36
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276