Revision: 2680 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2680&view=rev Author: rorthomas Date: 2012-05-26 02:43:12 +0000 (Sat, 26 May 2012) Log Message: ----------- merged heightfinder
Modified Paths: -------------- trunk/source/main/terrain/TerrainGeometryManager.h trunk/source/main/terrain/TerrainManager.cpp trunk/source/main/terrain/TerrainManager.h Removed Paths: ------------- trunk/source/main/physics/collision/heightfinder.h trunk/source/main/physics/collision/tsmheightfinder.cpp Deleted: trunk/source/main/physics/collision/heightfinder.h =================================================================== --- trunk/source/main/physics/collision/heightfinder.h 2012-05-26 02:34:46 UTC (rev 2679) +++ trunk/source/main/physics/collision/heightfinder.h 2012-05-26 02:43:12 UTC (rev 2680) @@ -1,77 +0,0 @@ -/* -This source file is part of Rigs of Rods -Copyright 2005-2012 Pierre-Michel Ricordel -Copyright 2007-2012 Thomas Fischer - -For more information, see http://www.rigsofrods.com/ - -Rigs of Rods is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License version 3, as -published by the Free Software Foundation. - -Rigs of Rods 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 General Public License for more details. - -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 __HeightFinder_H_ -#define __HeightFinder_H_ - -#include "RoRPrerequisites.h" - -#include "OgreTerrainGroup.h" - -#include "TerrainManager.h" - -/** - * This is the common interface for all Scene-Manager specific implementations of the Height-Finder - */ -class HeightFinder -{ -public: - - HeightFinder() {}; - virtual ~HeightFinder() {}; - - virtual float getHeightAt(float x, float z) = 0; - virtual Ogre::Vector3 getNormalAt(float x, float y, float z, float precision = 0.1f) - { - Ogre::Vector3 left(-precision, getHeightAt(x - precision, z) - y, 0.0f); - Ogre::Vector3 down(0.0f, getHeightAt(x, z + precision) - y, precision); - down = left.crossProduct(down); - down.normalise(); - return down; - } -}; - -/** - * Height-Finder for the standard Ogre Terrain Manager - */ -class TSMHeightFinder : public HeightFinder -{ -public: - - TSMHeightFinder(char *cfgfilename, char *fname, float defaultheight); - ~TSMHeightFinder(); - - float getHeightAt(float x, float z); - -protected: - - Ogre::String cfgfilename; - Ogre::Vector3 inverse_scale; - Ogre::Vector3 scale; - bool flipped; - float defaulth; - float dx, dz; - int size1; - int size; - unsigned short *data; - - void loadSettings(); -}; - -#endif // __HeightFinder_H_ Deleted: trunk/source/main/physics/collision/tsmheightfinder.cpp =================================================================== --- trunk/source/main/physics/collision/tsmheightfinder.cpp 2012-05-26 02:34:46 UTC (rev 2679) +++ trunk/source/main/physics/collision/tsmheightfinder.cpp 2012-05-26 02:43:12 UTC (rev 2680) @@ -1,152 +0,0 @@ -/* -This source file is part of Rigs of Rods -Copyright 2005-2012 Pierre-Michel Ricordel -Copyright 2007-2012 Thomas Fischer - -For more information, see http://www.rigsofrods.com/ - -Rigs of Rods is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License version 3, as -published by the Free Software Foundation. - -Rigs of Rods 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 General Public License for more details. - -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/>. -*/ -#include "heightfinder.h" - -#include <OgreConfigFile.h> - -using namespace Ogre; - -/** - * Height-Finder for the standard Ogre Terrain Manager - */ -TSMHeightFinder::TSMHeightFinder(char *cfgfilename, char *fname, float defaultheight) : - cfgfilename(cfgfilename) - , defaulth(defaultheight) - , flipped(false) -{ - String val; - ConfigFile config; - - ResourceGroupManager& rgm = ResourceGroupManager::getSingleton(); - DataStreamPtr stream = rgm.openResource(cfgfilename, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - config.load(stream); - - val = config.getSetting("PageSize"); - if (!val.empty()) - { - size = atoi(val.c_str()); - size1 = size - 1; - } - scale = Vector3::UNIT_SCALE; - - val = config.getSetting("PageWorldX"); - if (!val.empty()) - { - scale.x = atof(val.c_str()); - } - - val = config.getSetting("MaxHeight"); - if (!val.empty()) - { - scale.y = atof(val.c_str()); - } - - val = config.getSetting("PageWorldZ"); - if (!val.empty()) - { - scale.z = atof(val.c_str()); - } - // Scale x/z relative to page size - scale.x /= size1; - scale.z /= size1; - - inverse_scale.x= 1.0f / scale.x; - inverse_scale.y= scale.y / 65535.0f; - inverse_scale.z= 1.0f / scale.z; - - data = (unsigned short*)malloc(size*size*2); - DataStreamPtr ds = rgm.openResource(fname, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - ds->read(data, size*size*2); - // ds closes automatically, so do not close it explicitly here - loadSettings(); -} - -void TSMHeightFinder::loadSettings() -{ - ConfigFile cfg; - DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource(String(cfgfilename), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - cfg.load(ds, "\t:=", false); - flipped = (cfg.getSetting("Heightmap.flip") == "true"); - LOG("loading HeightFinder configuration from " + String(cfgfilename) + " flipped: " + TOSTRING(flipped)); -} - -TSMHeightFinder::~TSMHeightFinder() -{ - if (data) - { - free(data); - } -} - -float TSMHeightFinder::getHeightAt(float x, float z) -{ - - if (x < 0 || z < 0) return defaulth; - - float rx = x * inverse_scale.x; - float rz = z * inverse_scale.z; - - if (rx >= size1 || rz >= size1) return defaulth; - - int x_index = (int)rx; - int z_index = (int)rz; - - //dx=irx; dz=irz; - float t1=0.0f, t2=0.0f, b1=0.0f, b2=0.0f; - if (!flipped) - { - int z_i = z_index * size; - int z_iPlus1 = z_i + size; - t1 = data[x_index+z_i]; - t2 = data[x_index+1+z_i]; - b1 = data[x_index+z_iPlus1]; - b2 = data[x_index+1+z_iPlus1]; - } - else - { - int rez_i = (size1 - z_index) * size; - int rez_i1 = rez_i - size; - t1 = data[x_index + rez_i]; - t2 = data[x_index + 1 + rez_i]; - b1 = data[x_index + rez_i1]; - b2 = data[x_index +1 + rez_i1]; - } - - //dx=irx; dz=x_pct; - float x_pct = rx - x_index; - float z_pct = rz - z_index; - - if (x_pct + z_pct <= 1) - { - b2 = b1 + t2 - t1; - } else - { - t1 = b1 + t2 - b2; - } - - float t = t1 + x_pct * (t2 - t1); - float b = b1 + x_pct * (b2 - b1); - - float h = (t + z_pct * (b - t)) * inverse_scale.y; - - h = std::max(defaulth, h); - - return h; -} Modified: trunk/source/main/terrain/TerrainGeometryManager.h =================================================================== --- trunk/source/main/terrain/TerrainGeometryManager.h 2012-05-26 02:34:46 UTC (rev 2679) +++ trunk/source/main/terrain/TerrainGeometryManager.h 2012-05-26 02:43:12 UTC (rev 2680) @@ -31,7 +31,7 @@ #include <OgreConfigFile.h> // this class handles all interactions with the Ogre Terrain system -class TerrainGeometryManager : public HeightFinder +class TerrainGeometryManager { public: TerrainGeometryManager(Ogre::SceneManager *smgr, TerrainManager *terrainManager); @@ -41,11 +41,21 @@ inline Ogre::TerrainGroup *getTerrainGroup() { return mTerrainGroup; }; + inline float getHeightAt(float x, float z) { return mTerrainGroup->getHeightAtWorldPosition(x, 1000, z); } + inline Ogre::Vector3 getNormalAt(float x, float y, float z, float precision = 0.1f) + { + Ogre::Vector3 left(-precision, getHeightAt(x - precision, z) - y, 0.0f); + Ogre::Vector3 down(0.0f, getHeightAt(x, z + precision) - y, precision); + down = left.crossProduct(down); + down.normalise(); + return down; + } + protected: bool disableCaching; bool mTerrainsImported; Modified: trunk/source/main/terrain/TerrainManager.cpp =================================================================== --- trunk/source/main/terrain/TerrainManager.cpp 2012-05-26 02:34:46 UTC (rev 2679) +++ trunk/source/main/terrain/TerrainManager.cpp 2012-05-26 02:43:12 UTC (rev 2680) @@ -423,7 +423,7 @@ void TerrainManager::initWater() { //water! - if (waterline != -9999) + if (waterLine != -9999) { bool usewaves=(BSETTING("Waves", false)); @@ -434,20 +434,20 @@ String waterSettingsString = SSETTING("Water effects", "Reflection + refraction (speed optimized)"); if (waterSettingsString == "None") - w = 0; + water = 0; else if (waterSettingsString == "Basic (fastest)") - w = new WaterOld(WaterOld::WATER_BASIC, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); + water = new WaterOld(WaterOld::WATER_BASIC, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); else if (waterSettingsString == "Reflection") - w = new WaterOld(WaterOld::WATER_REFLECT, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); + water = new WaterOld(WaterOld::WATER_REFLECT, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); else if (waterSettingsString == "Reflection + refraction (speed optimized)") - w = new WaterOld(WaterOld::WATER_FULL_SPEED, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); + water = new WaterOld(WaterOld::WATER_FULL_SPEED, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); else if (waterSettingsString == "Reflection + refraction (quality optimized)") - w = new WaterOld(WaterOld::WATER_FULL_QUALITY, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); + water = new WaterOld(WaterOld::WATER_FULL_QUALITY, mCamera, mSceneMgr, mWindow, waterline, &mapsizex, &mapsizez, usewaves); } - if (w) w->setFadeColour(fadeColour); - if (person) person->setWater(w); - BeamFactory::getSingleton().w = w; - DustManager::getSingleton().setWater(w); + if (water) water->setFadeColour(ambientColor); + if (person) person->setWater(water); + BeamFactory::getSingleton().w = water; + DustManager::getSingleton().setWater(water); } void TerrainManager::initEnvironmentMap() Modified: trunk/source/main/terrain/TerrainManager.h =================================================================== --- trunk/source/main/terrain/TerrainManager.h 2012-05-26 02:34:46 UTC (rev 2679) +++ trunk/source/main/terrain/TerrainManager.h 2012-05-26 02:43:12 UTC (rev 2680) @@ -36,7 +36,7 @@ inline Collisions *getCollisions() { return collisions; }; - inline Water *getWater() { return w; }; + inline Water *getWater() { return water; }; inline Envmap *getEnvmap() { return envmap; }; protected: @@ -55,6 +55,7 @@ Envmap *envmap; Dashboard *dashboard; Collisions *collisions; + Water *water; // subsystem properties HDRListener *hdrListener; 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