Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
SurveyMapTextureCreator.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
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
22
23#include "Actor.h"
24#include "Application.h"
25#include "GameContext.h"
26#include "GfxScene.h"
27#include "IGfxWater.h"
28#include "Terrain.h"
29
30using namespace Ogre;
31using namespace RoR;
32
33static int counter = 0;
34
36 mCamera(nullptr),
37 mRttTex(nullptr),
38 mTerrainHeight(Math::Clamp(terrain_height + 100.0f, 150.0f, 2500.0f))
39{
40 counter++;
41 mTextureName = "MapRttTex-" + TOSTRING(counter);
42}
43
45{
46 if (mRttTex)
47 mRttTex->removeAllViewports();
48 if (mCamera)
49 App::GetGfxScene()->GetSceneManager()->destroyCamera(mCamera);
50 if (mTexture)
51 Ogre::TextureManager::getSingleton().remove(mTexture);
52}
53
54bool SurveyMapTextureCreator::init(int res, int fsaa)
55{
56 mTexture = Ogre::TextureManager::getSingleton().createManual(mTextureName,
57 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, res, res,
58 Ogre::TU_RENDERTARGET, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET, 0, false, fsaa);
59
60 if (!mTexture)
61 return false;
62
63 mRttTex = mTexture->getBuffer()->getRenderTarget();
64
65 if (!mRttTex)
66 return false;
67
68 mRttTex->addListener(this);
69 mRttTex->setAutoUpdated(false);
70
71 mCamera = App::GetGfxScene()->GetSceneManager()->createCamera("MapRttCam-" + TOSTRING(counter));
72 mCamera->setFixedYawAxis(false);
73 mCamera->setDirection(-Vector3::UNIT_Y);
74 mCamera->setProjectionType(PT_ORTHOGRAPHIC);
75 mCamera->setNearClipDistance(1.0f);
76 mCamera->setFarClipDistance(0);
77
78 auto mViewport = mRttTex->addViewport(mCamera);
79 mViewport->setBackgroundColour(ColourValue::Black);
80 mViewport->setOverlaysEnabled(false);
81 mViewport->setShadowsEnabled(false);
82 mViewport->setSkiesEnabled(false);
83
84 return true;
85}
86
87void SurveyMapTextureCreator::update(Vector2 center, Vector2 size)
88{
89 if (!mRttTex)
90 return;
91
92 mCamera->setOrthoWindow(size.x, size.y);
93 mCamera->setPosition(Vector3(center.x, mTerrainHeight, center.y));
94
95 mRttTex->update();
96}
97
98void SurveyMapTextureCreator::preRenderTargetUpdate(const RenderTargetEvent &evt)
99{
100 auto water = App::GetGameContext()->GetTerrain()->getGfxWater();
101 if (water)
102 {
103 water->SetForcedCameraTransform(mCamera->getFOVy(),
104 mCamera->getPosition(), mCamera->getOrientation()); // FIXME: Legacy OGRE API! Use camera node instead!
105 water->UpdateWater();
106 water->ClearForcedCameraTransform();
107 }
108}
109
110void SurveyMapTextureCreator::postRenderTargetUpdate(const RenderTargetEvent &evt)
111{
112 auto water = App::GetGameContext()->GetTerrain()->getGfxWater();
113 if (water)
114 {
115 water->UpdateWater();
116 }
117}
118
119Ogre::TexturePtr SurveyMapTextureCreator::convertTextureToStatic(const std::string& texName, const std::string& rgName)
120{
121 Ogre::Image img;
122 mTexture->convertToImage(img);
123 return Ogre::TextureManager::getSingleton().loadImage(texName, rgName, img);
124}
Central state/object manager and communications hub.
#define TOSTRING(x)
Definition Application.h:57
Game state manager and message-queue provider.
static int counter
const TerrainPtr & GetTerrain()
Ogre::SceneManager * GetSceneManager()
Definition GfxScene.h:83
virtual void UpdateWater()=0
virtual void SetForcedCameraTransform(Ogre::Radian, Ogre::Vector3, Ogre::Quaternion)
Definition IGfxWater.h:53
Ogre::TexturePtr convertTextureToStatic(const std::string &texName, const std::string &rgName)
void update(Ogre::Vector2 center, Ogre::Vector2 size)
SurveyMapTextureCreator(Ogre::Real terrain_height)
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
IGfxWater * getGfxWater()
Definition Terrain.h:88
GameContext * GetGameContext()
GfxScene * GetGfxScene()