Revision: 2599
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2599&view=rev
Author:   ulteq
Date:     2012-05-19 18:28:23 +0000 (Sat, 19 May 2012)
Log Message:
-----------
-Bugfix: Overview map (WIP)

Modified Paths:
--------------
    trunk/source/main/gui/MapTextureCreator.cpp
    trunk/source/main/gui/MapTextureCreator.h

Modified: trunk/source/main/gui/MapTextureCreator.cpp
===================================================================
--- trunk/source/main/gui/MapTextureCreator.cpp 2012-05-19 14:35:47 UTC (rev 
2598)
+++ trunk/source/main/gui/MapTextureCreator.cpp 2012-05-19 18:28:23 UTC (rev 
2599)
@@ -19,6 +19,7 @@
 */
 #include "MapTextureCreator.h"
 
+#include "heightfinder.h"
 #include "ResourceBuffer.h"
 #include "RoRFrameListener.h"
 #include "water.h"
@@ -31,21 +32,23 @@
          mSceneManager(mgr)
        , mMainCam(mMainCam)
        , mEfl(efl)
-       , mCamdir(Quaternion::ZERO)
+       , mCamDir(Quaternion::ZERO)
+       , mCamPos(Vector3::ZERO)
        , mCamera(NULL)
-       , mCampos(Vector3::ZERO)
        , mMaterial(NULL)
        , mRttTex(NULL)
        , mStatics(NULL)
        , mTextureUnitState(NULL)
        , mViewport(NULL)
+       , mZoom(3.0f)
 {
        mCounter++;
+       init();
 }
 
 bool MapTextureCreator::init()
 {
-       TexturePtr texture = 
TextureManager::getSingleton().createManual("MapRttTex"+TOSTRING(mCounter), 
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1024, 1024, 0, 
PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
+       TexturePtr texture = 
TextureManager::getSingleton().createManual("MapRttTex" + TOSTRING(mCounter), 
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 1024, 1024, 0, 
PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer());
        
        if ( texture.isNull() ) return false;;
 
@@ -55,30 +58,49 @@
 
        mRttTex->setAutoUpdated(true);
 
-       mCamera = mSceneManager->createCamera("MapRenderCam");
+       mCamera = mSceneManager->createCamera("MapRenderCam" + 
TOSTRING(mCounter));
 
        mViewport = mRttTex->addViewport(mCamera);
-       mViewport->setBackgroundColour(ColourValue::White);
+       mViewport->setBackgroundColour(ColourValue::Black);
        mViewport->setOverlaysEnabled(false);
 
-       mMaterial = 
MaterialManager::getSingleton().create("MapRttMat"+TOSTRING(mCounter), 
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+       mMaterial = MaterialManager::getSingleton().create("MapRttMat" + 
TOSTRING(mCounter), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 
        if ( mMaterial.isNull() ) return false;
 
-       mTextureUnitState = 
mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("MapRttTex"+TOSTRING(mCounter));
+       mTextureUnitState = 
mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("MapRttTex" + 
TOSTRING(mCounter));
 
        mRttTex->addListener(this);
 
-       mCamera->setFarClipDistance(0);
-       mCamera->setAspectRatio(1.0);
+       mCamera->setPosition(0.0f, 1000.0f, 0.0f);
+       mCamera->lookAt(Vector3::ZERO);
+
+       mCamera->setFarClipDistance(0.0f);
+       mCamera->setAspectRatio(1.0f);
        mCamera->setFixedYawAxis(false);
        mCamera->setProjectionType(PT_ORTHOGRAPHIC);
        mCamera->setFOVy(Radian(Math::HALF_PI));
+       mCamera->setNearClipDistance(mZoom);
 
        return true;
 }
 
+void MapTextureCreator::setCameraMode(PolygonMode pm)
+{
+       mCamera->setPolygonMode(pm);
+}
 
+void MapTextureCreator::setCameraZoom(float z)
+{
+       mZoom = std::max(0.3f, z);
+}
+
+void MapTextureCreator::setCamPosition(Vector3 pos, Quaternion direction)
+{
+       mCamPos = pos;
+       mCamDir = direction;
+}
+
 void MapTextureCreator::setStaticGeometry(StaticGeometry *geo)
 {
        mStatics = geo;
@@ -86,114 +108,56 @@
 
 void MapTextureCreator::update()
 {
-       if ( !mRttTex && !init() ) return;
+       if ( !mRttTex ) return;
 
        float width = mEfl->mapsizex;
        float height = mEfl->mapsizez;
+       float zoomFactor = mZoom * ((width + height) / 2.0f) * 0.002f;
        
-       mCamera->setOrthoWindow(1024, 1024);
-       mCamera->setPosition(width*0.5f, 100.0f, height*0.5f);
-       mCamera->lookAt(width*0.5f + 0.0001f, 0.0f, height*0.5f);
+       mCamPos = Vector3(mEfl->mapsizex / 2.0f, 
mEfl->hfinder->getHeightAt(mEfl->mapsizex / 2.0f, mEfl->mapsizez / 2.0f) , 
mEfl->mapsizez / 2.0f);
+       mCamDir = Quaternion(Degree(0), Vector3::UNIT_X);
 
-       mRttTex->update();
-#if 0
-       // 1 = max out = total overview
+       mCamera->setNearClipDistance(mZoom);
+       mCamera->setPosition(mCamPos + Vector3(0.0f, zoomFactor, 0.0f));
+       if ( mCamDir != Quaternion::ZERO )
+       {
+               mCamera->setOrientation(mCamDir);
+       }
+       mCamera->lookAt(mCamPos - Vector3(0.0f, zoomFactor, 0.0f));
 
-       float width = mEfl->mapsizex;
-       float height = mEfl->mapsizez;
+       float f = std::max(20.0f, 50.0f - mZoom);
 
-       //LOG(TOSTRING(mZoom));
-       mCamera->setOrthoWindow(1024, 1024);
-       mCamera->setPosition(width*0.5f, 100, height*0.5f);
-       mCamera->lookAt(width*0.5f + 0.0001f, 0, height*0.5f);
-       //mCamera->setOrientation(Quaternion(Radian(0), Vector3::UNIT_Z));
-
-
-       /*
-       // this is bugged, so deactivated for now
-       float f = 50-mZoom;
-       if(f<20)
-               f=20;
-       for (int i=0; i<mEfl->getTruckCount(); i++)
-               mEfl->getTruck(i)->preMapLabelRenderUpdate(true, f);
-       */
-
-       if (mStatics)
+       if ( mStatics )
        {
                mStatics->setRenderingDistance(0);
        }
-       // thats a huge workaround to be able to not use the normal LOD
 
-       setFogVisible(false);
-
        mRttTex->update();
 
-       setFogVisible(true);
+       Water *w = mEfl->getWater();
 
-       if (mEfl->getWater())
+       if ( w )
        {
-               mEfl->getWater()->setVisible(false);
+               w->setVisible(false);
        }
-       if (mStatics)
+       if ( mStatics )
        {
                mStatics->setRenderingDistance(1000);
        }
-       if (mEfl->getWater())
+       if ( w )
        {
-               mEfl->getWater()->setVisible(true);
+               w->setVisible(true);
        }
-       /*
-       // deactivated for the moment
-       for (int i=0; i<mEfl->getTruckCount(); i++)
-               mEfl->getTruck(i)->preMapLabelRenderUpdate(false);
-       */
-#endif
 }
 
-void MapTextureCreator::setFogVisible(bool value)
-{
-#if 0
-       return;
-       int fogmode = 0; //mEfl->getFogMode();
-       //LOG("fogswitch: "+TOSTRING(fogmode)+" / "+TOSTRING(value));
-       if(!fogmode || fogmode == 2)
-               return;
-
-       // this refuses to work, somehow:
-       if(fogmode == 1)
-       {
-               // TODO: tofix: caelum
-               // USE_CAELUM
-               if(value)
-                       static_cast<Caelum::StoredImageSkyColourModel 
*>(mEfl->getCaelumModel())->setFogDensity(mEfl->getFogDensity());
-               else
-                       static_cast<Caelum::StoredImageSkyColourModel 
*>(mEfl->getCaelumModel())->setFogDensity(0);
-
-               // force Caelum to update
-               if(value)
-                       
mEfl->getCaelumSystem()->setLocalTime(mEfl->getCaelumSystem()->getLocalTime()+1);
-               else
-                       
mEfl->getCaelumSystem()->setLocalTime(mEfl->getCaelumSystem()->getLocalTime()-1);
-       }
-       else if(fogmode == 3)
-       {
-               if(value)
-                       mSceneManager->setFog(FOG_LINEAR, 
mSceneManager->getFogColour(), mEfl->getFogDensity(), 
mSceneManager->getFogStart(), mSceneManager->getFogEnd());
-               else
-                       mSceneManager->setFog(FOG_NONE, 
mSceneManager->getFogColour(), mEfl->getFogDensity(), 
mSceneManager->getFogStart(), mSceneManager->getFogEnd());
-       }
-
-#endif //0
-}
-
 String MapTextureCreator::getMaterialName()
 {
-       return "MapRttMat"+TOSTRING(mCounter);
+       return "MapRttMat" + TOSTRING(mCounter);
 }
 
 String MapTextureCreator::getRTName()
 {
-       return "MapRttTex"+TOSTRING(mCounter);
+       return "MapRttTex" + TOSTRING(mCounter);
 }
 
 void MapTextureCreator::preRenderTargetUpdate(const RenderTargetEvent& evt)

Modified: trunk/source/main/gui/MapTextureCreator.h
===================================================================
--- trunk/source/main/gui/MapTextureCreator.h   2012-05-19 14:35:47 UTC (rev 
2598)
+++ trunk/source/main/gui/MapTextureCreator.h   2012-05-19 18:28:23 UTC (rev 
2599)
@@ -17,8 +17,8 @@
 You should have received a copy of the GNU General Public License
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
-#ifndef __MAP_TEXTURE_CREATOR_H_
-#define __MAP_TEXTURE_CREATOR_H_
+#ifndef __MapTextureCreator_H_
+#define __MapTextureCreator_H_
 
 #include "RoRPrerequisites.h"
 
@@ -29,30 +29,39 @@
 public:
 
        MapTextureCreator(Ogre::SceneManager *smgr, Ogre::Camera *mainCam, 
RoRFrameListener *efl);
+
        Ogre::String getMaterialName();
        Ogre::String getRTName();
-       void update();
+       
+       void setCamPosition(Ogre::Vector3 pos, Ogre::Quaternion direction);
+       void setCameraMode(Ogre::PolygonMode pm);
+       void setCameraZoom(float z);
        void setStaticGeometry(Ogre::StaticGeometry *geo);
 
+       void update();
+
 protected:
 
+       bool init();
+
        void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
     void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
-       void setFogVisible(bool value);
-       bool init();
 
        Ogre::Camera *mCamera;
        Ogre::Camera *mMainCam;
        Ogre::MaterialPtr mMaterial;
-       Ogre::Quaternion mCamdir;
+       Ogre::Quaternion mCamDir;
        Ogre::RenderTarget *mRttTex;
        Ogre::SceneManager *mSceneManager;
        Ogre::StaticGeometry *mStatics;
        Ogre::TextureUnitState* mTextureUnitState;
-       Ogre::Vector3 mCampos;
+       Ogre::Vector3 mCamPos;
        Ogre::Viewport *mViewport;
        RoRFrameListener *mEfl;
+
+       float mZoom;
+
        static int mCounter;
 };
 
-#endif // __MAP_TEXTURE_CREATOR_H_
+#endif // __MapTextureCreator_H_

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to