Revision: 2708 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2708&view=rev Author: ulteq Date: 2012-05-26 19:21:09 +0000 (Sat, 26 May 2012) Log Message: ----------- Water compiles through
Modified Paths: -------------- trunk/source/main/gfx/IWater.h trunk/source/main/gfx/Skidmark.cpp trunk/source/main/gfx/Skidmark.h Added Paths: ----------- trunk/source/main/gfx/Water.cpp trunk/source/main/gfx/Water.h Removed Paths: ------------- trunk/source/main/gfx/WaterOld.cpp trunk/source/main/gfx/WaterOld.h Modified: trunk/source/main/gfx/IWater.h =================================================================== --- trunk/source/main/gfx/IWater.h 2012-05-26 18:49:59 UTC (rev 2707) +++ trunk/source/main/gfx/IWater.h 2012-05-26 19:21:09 UTC (rev 2708) @@ -23,12 +23,12 @@ #include "RoRPrerequisites.h" // interface only -class Water +class IWater { public: - Water() {}; - Water(int type, float wHeight, float *MapSizeX, float *MapSizeZ, bool useWaves); - virtual ~Water() {}; + IWater() {}; + IWater(int type, float wHeight, float *MapSizeX, float *MapSizeZ, bool useWaves); + virtual ~IWater() {}; virtual float getHeight() = 0; virtual float getHeightWaves(Ogre::Vector3 pos) = 0; Modified: trunk/source/main/gfx/Skidmark.cpp =================================================================== --- trunk/source/main/gfx/Skidmark.cpp 2012-05-26 18:49:59 UTC (rev 2707) +++ trunk/source/main/gfx/Skidmark.cpp 2012-05-26 19:21:09 UTC (rev 2708) @@ -126,11 +126,10 @@ // this is a hardcoded array which we use to map ground types to a certain texture with UV/ coords Vector2 Skidmark::tex_coords[4] = {Vector2(0,0), Vector2(0,1), Vector2(1,0), Vector2(1,1)}; -Skidmark::Skidmark(wheel_t *wheel, HeightFinder *hfinder, SceneNode *snode, int _lenght, int bucketCount) : +Skidmark::Skidmark(wheel_t *wheel, Ogre::SceneNode *snode, int lenght /* = 500 */, int bucketCount /* = 20 */) : mNode(snode) - , hfinder(hfinder) , mDirty(true) - , lenght((_lenght%2) ? (_lenght-(_lenght%2)) : _lenght) + , lenght(lenght) , bucketCount(bucketCount) , wheel(wheel) , minDistance(0.1f) @@ -138,6 +137,10 @@ , minDistanceSquared(minDistance * minDistance) , maxDistanceSquared(maxDistance * maxDistance) { + if (lenght % 2) + { + lenght--; + } } Skidmark::~Skidmark() @@ -171,7 +174,7 @@ skid.points.resize(lenght); skid.faceSizes.resize(lenght); skid.groundTexture.resize(lenght); - skid.obj = scm->createManualObject("skidmark" + TOSTRING(instanceCounter++)); + skid.obj = gEnv->ogreSceneManager->createManualObject("skidmark" + TOSTRING(instanceCounter++)); skid.obj->setDynamic(true); skid.obj->setRenderingDistance(2000); //2km sight range skid.obj->begin(bname, RenderOperation::OT_TRIANGLE_STRIP); @@ -199,7 +202,7 @@ //LOG("deleting first skidmarks section to keep the limits"); objects.front().points.clear(); objects.front().faceSizes.clear(); - scm->destroyManualObject(objects.front().obj); + gEnv->ogreSceneManager->destroyManualObject(objects.front().obj); objects.pop(); } } Modified: trunk/source/main/gfx/Skidmark.h =================================================================== --- trunk/source/main/gfx/Skidmark.h 2012-05-26 18:49:59 UTC (rev 2707) +++ trunk/source/main/gfx/Skidmark.h 2012-05-26 19:21:09 UTC (rev 2708) @@ -53,7 +53,7 @@ public: /// Constructor - see setOperationType() for description of argument. - Skidmark( wheel_t *wheel, Ogre::SceneNode *snode, int lenght=500, int bucketCount=20); + Skidmark( wheel_t *wheel, Ogre::SceneNode *snode, int lenght = 500, int bucketCount = 20); virtual ~Skidmark(); void updatePoint(); Copied: trunk/source/main/gfx/Water.cpp (from rev 2703, trunk/source/main/gfx/WaterOld.cpp) =================================================================== --- trunk/source/main/gfx/Water.cpp (rev 0) +++ trunk/source/main/gfx/Water.cpp 2012-05-26 19:21:09 UTC (rev 2708) @@ -0,0 +1,505 @@ +/* +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 "Water.h" + +#include "ResourceBuffer.h" +#include "RoRFrameListener.h" +#include "Settings.h" +#include "TerrainManager.h" + +using namespace Ogre; + +Entity* pPlaneEnt; + +Plane waterPlane; +Plane bottomPlane; +Plane reflectionPlane; +Plane refractionPlane; +SceneManager *waterSceneMgr; + +class RefractionTextureListener : public RenderTargetListener +{ +public: + + void preRenderTargetUpdate(const RenderTargetEvent& evt) + { + waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(false); + // Hide plane + pPlaneEnt->setVisible(false); + //hide Water spray + if (gEnv->frameListener) gEnv->frameListener->showspray(false); + } + + void postRenderTargetUpdate(const RenderTargetEvent& evt) + { + // Show plane + pPlaneEnt->setVisible(true); + waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(true); + //restore Water spray + if (gEnv->frameListener) gEnv->frameListener->showspray(true); + } +}; + +class ReflectionTextureListener : public RenderTargetListener +{ +public: + void preRenderTargetUpdate(const RenderTargetEvent& evt) + { + waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(false); + // Hide plane + pPlaneEnt->setVisible(false); + + } + void postRenderTargetUpdate(const RenderTargetEvent& evt) + { + // Show plane + pPlaneEnt->setVisible(true); + waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(true); + } +}; + +RefractionTextureListener mRefractionListener; +ReflectionTextureListener mReflectionListener; + +Water::Water(const Ogre::ConfigFile &mTerrainConfig) +{ + vRtt1 = vRtt2 = 0; + mScale = 1.0f; + if(gEnv->terrainManager->getMax().x < 1500) + mScale = 1.5f; + //reading wavefield + visible=true; + free_wavetrain=0; + maxampl=0; + + if(haswaves) + { + char line[1024] = {}; + FILE *fd = fopen((SSETTING("Config Root", "")+"wavefield.cfg").c_str(), "r"); + if (fd) + { + while (!feof(fd)) + { + int res = fscanf(fd," %[^\n\r]",line); + if (line[0] == ';') continue; + float wl,amp,mx,dir; + res = sscanf(line,"%f, %f, %f, %f",&wl,&,&mx,&dir); + if(res < 4) continue; + wavetrains[free_wavetrain].wavelength=wl; + wavetrains[free_wavetrain].amplitude=amp; + wavetrains[free_wavetrain].maxheight=mx; + wavetrains[free_wavetrain].direction=dir/57.0; + free_wavetrain++; + } + fclose(fd); + } + for (int i=0; i<free_wavetrain; i++) + { + wavetrains[i].wavespeed=1.25*sqrt(wavetrains[i].wavelength); + maxampl+=wavetrains[i].maxheight; + } + } + //theCam=camera; + pTestNode=0; + waterSceneMgr=gEnv->ogreSceneManager; + framecounter=0; + //height=wheight; + orgheight=wheight; + //mType=type; + rttTex1=0; + rttTex2=0; + MeshPtr mprt; + mReflectCam=0; + mRefractCam=0; + //wbuf=0; + //ColourValue fade=camera->getViewport()->getBackgroundColour(); + ColourValue fade=gEnv->ogreSceneManager->getFogColour(); + + if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED || mType == WATER_REFLECT) + { + // Check prerequisites first + const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities(); + if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM))) + { + OGRE_EXCEPT(1, "Your card does not support vertex and fragment programs, so cannot " + "run Water effects. Sorry!", + "Water effects"); + } + else + { + if (!GpuProgramManager::getSingleton().isSyntaxSupported("arbfp1") && + !GpuProgramManager::getSingleton().isSyntaxSupported("ps_2_0") && + !GpuProgramManager::getSingleton().isSyntaxSupported("ps_1_4") + ) + { + OGRE_EXCEPT(1, "Your card does not support advanced fragment programs, " + "so cannot run Water effects. Sorry!", + "Water effects"); + } + } + // Ok + // Define a floor plane mesh + reflectionPlane.normal = Vector3::UNIT_Y; + reflectionPlane.d = -wheight+0.15; + refractionPlane.normal = -Vector3::UNIT_Y; + refractionPlane.d = wheight+0.15; + waterPlane.normal = Vector3::UNIT_Y; + waterPlane.d = -wheight; + + if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED) + { + TexturePtr rttTex1Ptr = TextureManager::getSingleton().createManual("Refraction", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); + rttTex1 = rttTex1Ptr->getBuffer()->getRenderTarget(); + { + mRefractCam = gEnv->ogreSceneManager->createCamera("RefractCam"); + mRefractCam->setNearClipDistance(gEnv->ogreCamera->getNearClipDistance()); + mRefractCam->setFarClipDistance(gEnv->ogreCamera->getFarClipDistance()); + mRefractCam->setAspectRatio( + (Real)gEnv->ogreRenderWindow->getViewport(0)->getActualWidth() / + (Real)gEnv->ogreRenderWindow->getViewport(0)->getActualHeight()); + + vRtt1 = rttTex1->addViewport( mRefractCam ); + vRtt1->setClearEveryFrame( true ); + vRtt1->setBackgroundColour( fade ); + // v->setBackgroundColour( ColourValue::Black ); + + + MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); + mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction"); + + vRtt1->setOverlaysEnabled(false); + + rttTex1->addListener(&mRefractionListener); + + //optimisation + rttTex1->setAutoUpdated(false); + + // Also clip + mRefractCam->enableCustomNearClipPlane(refractionPlane); + } + } + + TexturePtr rttTex2Ptr = TextureManager::getSingleton().createManual("Reflection", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); + rttTex2 = rttTex2Ptr->getBuffer()->getRenderTarget(); + { + mReflectCam = gEnv->ogreSceneManager->createCamera("ReflectCam"); + mReflectCam->setNearClipDistance(gEnv->ogreCamera->getNearClipDistance()); + mReflectCam->setFarClipDistance(gEnv->ogreCamera->getFarClipDistance()); + mReflectCam->setAspectRatio( + (Real)gEnv->ogreRenderWindow->getViewport(0)->getActualWidth() / + (Real)gEnv->ogreRenderWindow->getViewport(0)->getActualHeight()); + + vRtt2 = rttTex2->addViewport( mReflectCam ); + vRtt2->setClearEveryFrame( true ); + vRtt2->setBackgroundColour( fade ); + // v->setBackgroundColour( ColourValue::Black ); + + + MaterialPtr mat ; + if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED) mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); + else mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflection"); + mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection"); + + vRtt2->setOverlaysEnabled(false); + + rttTex2->addListener(&mReflectionListener); + + //optimisation + rttTex2->setAutoUpdated(false); + + // set up linked reflection + mReflectCam->enableReflection(waterPlane); + // Also clip + mReflectCam->enableCustomNearClipPlane(reflectionPlane); + } + + mprt=MeshManager::getSingleton().createPlane("ReflectPlane", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + waterPlane, + gEnv->terrainManager->getMax().x * mScale,gEnv->terrainManager->getMax().z * mScale,WAVEREZ,WAVEREZ,true,1,50,50,Vector3::UNIT_Z, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); + pPlaneEnt = gEnv->ogreSceneManager->createEntity( "plane", "ReflectPlane" ); + if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED) pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction"); + else pPlaneEnt->setMaterialName("Examples/FresnelReflection"); + // gEnv->ogreSceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); + //position + pTestNode = gEnv->ogreSceneManager->getRootSceneNode()->createChildSceneNode("WaterPlane"); + pTestNode->attachObject(pPlaneEnt); + pTestNode->setPosition( Vector3((gEnv->terrainManager->getMax().x * mScale)/2,0,(gEnv->terrainManager->getMax().z * mScale)/2) ); + } + else + { + //basic Water + waterPlane.normal = Vector3::UNIT_Y; + waterPlane.d = -wheight; + mprt=MeshManager::getSingleton().createPlane("WaterPlane", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + waterPlane, + gEnv->terrainManager->getMax().x * mScale,gEnv->terrainManager->getMax().z * mScale,WAVEREZ,WAVEREZ,true,1,50,50,Vector3::UNIT_Z, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); + pPlaneEnt = gEnv->ogreSceneManager->createEntity( "plane", "WaterPlane" ); + pPlaneEnt->setMaterialName("tracks/basicwater"); + //position + pTestNode = gEnv->ogreSceneManager->getRootSceneNode()->createChildSceneNode("WaterPlane"); + pTestNode->attachObject(pPlaneEnt); + pTestNode->setPosition( Vector3((gEnv->terrainManager->getMax().x * mScale)/2,0,(gEnv->terrainManager->getMax().z * mScale)/2) ); + } + //bottom + bottomPlane.normal = Vector3::UNIT_Y; + bottomPlane.d = -wheight+30.0; //30m below waterline + MeshManager::getSingleton().createPlane("BottomPlane", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, + bottomPlane, + gEnv->terrainManager->getMax().x * mScale,gEnv->terrainManager->getMax().z * mScale,1,1,true,1,1,1,Vector3::UNIT_Z); + Entity *pE = gEnv->ogreSceneManager->createEntity( "bplane", "BottomPlane" ); + pE->setMaterialName("tracks/seabottom"); + //position + pBottomNode = gEnv->ogreSceneManager->getRootSceneNode()->createChildSceneNode("BottomWaterPlane"); + pBottomNode->attachObject(pE); + pBottomNode->setPosition( Vector3((gEnv->terrainManager->getMax().x * mScale)/2,0,(gEnv->terrainManager->getMax().z * mScale)/2) ); + //setup for waves + wbuf=mprt->sharedVertexData->vertexBufferBinding->getBuffer(0); + if (wbuf->getSizeInBytes()==(WAVEREZ+1)*(WAVEREZ+1)*32) + { + wbuffer=(float*)malloc(wbuf->getSizeInBytes()); + wbuf->readData(0, wbuf->getSizeInBytes(), wbuffer); + } else wbuffer=0; +} + +bool Water::allowUnderWater() +{ + return false; +} + +void Water::setVisible(bool value) +{ + visible = value; + if(pPlaneEnt) + pPlaneEnt->setVisible(value); + if(pTestNode) + pTestNode->setVisible(value); + if(pBottomNode) + pBottomNode->setVisible(value); + +} + +void Water::setFadeColour(ColourValue ambient) +{ + // update the viewports background colour! + if(vRtt1) vRtt1->setBackgroundColour(ambient); + if(vRtt2) vRtt2->setBackgroundColour(ambient); +} + + +void Water::moveTo(Camera *cam, float centerheight) +{ + if (pTestNode) + { + Vector3 pos=cam->getPosition(); + Vector3 offset=cam->getDirection(); + offset.y=0; + offset.normalise(); + pos = pos + offset * gEnv->terrainManager->getMax().x * mScale * 0.46666; + pos.y=orgheight - height; + pos.x=((int)pos.x/60)*60; + pos.z=((int)pos.z/60)*60; + pTestNode->setPosition(pos); + pBottomNode->setPosition(pos); + if (haswaves) showWave(pos); + if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED || mType==WATER_REFLECT) updateReflectionPlane(centerheight); + } +} + +void Water::showWave(Vector3 refpos) +{ + int px,pz; + if (!wbuffer) return; + for (px=0; px<WAVEREZ+1; px++) + { + for (pz=0; pz<WAVEREZ+1; pz++) + { + wbuffer[(pz*(WAVEREZ+1)+px)*8+1]=getHeightWaves(refpos+Vector3((gEnv->terrainManager->getMax().x * mScale)/2-(float)px*(gEnv->terrainManager->getMax().x * mScale)/WAVEREZ, 0, (float)pz*(gEnv->terrainManager->getMax().z * mScale)/WAVEREZ-(gEnv->terrainManager->getMax().z * mScale)/2)); + } + } + //normals + for (px=0; px<WAVEREZ+1; px++) + { + for (pz=0; pz<WAVEREZ+1; pz++) + { + int left=px-1; if (left<0) left=0; + int right=px+1; if (right>WAVEREZ) right=WAVEREZ; + int up=pz-1; if (up<0) up=0; + int down=pz+1; if (down>WAVEREZ) down=WAVEREZ; + Vector3 normal=(Vector3(wbuffer+((pz*(WAVEREZ+1)+left)*8))-Vector3(wbuffer+((pz*(WAVEREZ+1)+right)*8))).crossProduct(Vector3(wbuffer+((up*(WAVEREZ+1)+px)*8))-Vector3(wbuffer+((down*(WAVEREZ+1)+px)*8))); + normal.normalise(); + wbuffer[(pz*(WAVEREZ+1)+px)*8+3]=normal.x; + wbuffer[(pz*(WAVEREZ+1)+px)*8+4]=normal.y; + wbuffer[(pz*(WAVEREZ+1)+px)*8+5]=normal.z; + } + } +// wbuf->lock(HardwareBuffer::HBL_DISCARD); + wbuf->writeData(0, (WAVEREZ+1)*(WAVEREZ+1)*32, wbuffer, true); +// if(wbuf->isLocked()) +// wbuf->unlock(); +} + +void Water::update() +{ + if(!visible) + return; + framecounter++; + if (mType==WATER_FULL_SPEED) + { + if (framecounter%2) + { + mReflectCam->setOrientation(gEnv->ogreCamera->getOrientation()); + mReflectCam->setPosition(gEnv->ogreCamera->getPosition()); + mReflectCam->setFOVy(gEnv->ogreCamera->getFOVy()); + rttTex2->update(); + } + else + { + mRefractCam->setOrientation(gEnv->ogreCamera->getOrientation()); + mRefractCam->setPosition(gEnv->ogreCamera->getPosition()); + mRefractCam->setFOVy(gEnv->ogreCamera->getFOVy()); + rttTex1->update(); + } + } else if (mType==WATER_FULL_QUALITY) + { + mReflectCam->setOrientation(gEnv->ogreCamera->getOrientation()); + mReflectCam->setPosition(gEnv->ogreCamera->getPosition()); + mReflectCam->setFOVy(gEnv->ogreCamera->getFOVy()); + rttTex2->update(); + mRefractCam->setOrientation(gEnv->ogreCamera->getOrientation()); + mRefractCam->setPosition(gEnv->ogreCamera->getPosition()); + mRefractCam->setFOVy(gEnv->ogreCamera->getFOVy()); + rttTex1->update(); + } + else if (mType==WATER_REFLECT) + { + mReflectCam->setOrientation(gEnv->ogreCamera->getOrientation()); + mReflectCam->setPosition(gEnv->ogreCamera->getPosition()); + mReflectCam->setFOVy(gEnv->ogreCamera->getFOVy()); + rttTex2->update(); + } +} + +void Water::prepareShutdown() +{ + if (rttTex1) rttTex1->removeListener(&mRefractionListener); + if (rttTex2) rttTex2->removeListener(&mReflectionListener); +} + +float Water::getHeight() {return height;}; + +void Water::setHeight(float value) +{ + height = value; + update(); +} + +float Water::getHeightWaves(Vector3 pos) +{ + // no waves? + if(!haswaves) + { + // constant height, sea is flat as pancake + return height; + } + + // uh, some upper limit?! + if (pos.y > height + maxampl) + return height; + + // calculate how high the waves should be at this point + // (gEnv->terrainManager->getMax().x * mScale) / 2 = terrain width / 2 + // (gEnv->terrainManager->getMax().z * mScale) / 2 = terrain height / 2 + // calculates the distance to the center of the terrain and dives it through 3.000.000 + float waveheight = (pos - Vector3((gEnv->terrainManager->getMax().x * mScale) / 2, height, (gEnv->terrainManager->getMax().z * mScale) / 2)).squaredLength() / 3000000.0; + // we will store the result in this variable, init it with the default height + float result = height; + // now walk through all the wave trains. One 'train' is one sin/cos set that will generate once wave. All the trains together will sum up, so that they generate a 'rough' sea + for (int i=0; i<free_wavetrain; i++) + { + // calculate the amplitude that this wave will have. wavetrains[i].amplitude is read from the config + float amp = wavetrains[i].amplitude * waveheight; + // upper limit: prevent too big waves by setting an upper limit + if (amp > wavetrains[i].maxheight) + amp = wavetrains[i].maxheight; + // now the main thing: + // calculate the sinus with the values of the config file and add it to the result + result += amp * sin(Math::TWO_PI * ( \ + (mrtime * wavetrains[i].wavespeed \ + + sin(wavetrains[i].direction) * pos.x \ + + cos(wavetrains[i].direction) * pos.z \ + ) \ + / wavetrains[i].wavelength) \ + ); + } + // return the summed up waves + return result; +} + +Vector3 Water::getVelocity(Vector3 pos) +{ + if(!haswaves) return Vector3::ZERO; + + if (pos.y>height+maxampl) return Vector3::ZERO; + int i; + float waveheight=(pos-Vector3((gEnv->terrainManager->getMax().x * mScale)/2, height, (gEnv->terrainManager->getMax().z * mScale)/2)).squaredLength()/3000000.0; + Vector3 result=Vector3::ZERO; + for (i=0; i<free_wavetrain; i++) + { + float amp=wavetrains[i].amplitude*waveheight; + if (amp>wavetrains[i].maxheight) amp=wavetrains[i].maxheight; + float speed=6.28318*amp/(wavetrains[i].wavelength/wavetrains[i].wavespeed); + result.y+=speed*cos(6.28318*((mrtime*wavetrains[i].wavespeed+sin(wavetrains[i].direction)*pos.x+cos(wavetrains[i].direction)*pos.z)/wavetrains[i].wavelength)); + result+=Vector3(sin(wavetrains[i].direction), 0, cos(wavetrains[i].direction))*speed*sin(6.28318*((mrtime*wavetrains[i].wavespeed+sin(wavetrains[i].direction)*pos.x+cos(wavetrains[i].direction)*pos.z)/wavetrains[i].wavelength)); + } + return result; +} + + + +void Water::updateReflectionPlane(float h) +{ + //Ray ra=gEnv->ogreCamera->getCameraToViewportRay(0.5,0.5); + //std::pair<bool, Real> mpair=ra.intersects(Plane(Vector3::UNIT_Y, -height)); + //if (mpair.first) h=ra.getPoint(mpair.second).y; + reflectionPlane.d = -h+0.15; + refractionPlane.d = h+0.15; + waterPlane.d = -h; + if (mRefractCam) mRefractCam->enableCustomNearClipPlane(refractionPlane); + if (mReflectCam) + { + mReflectCam->enableReflection(waterPlane); + mReflectCam->enableCustomNearClipPlane(reflectionPlane); + }; + +} + + +void Water::setSunPosition(Vector3) +{ + // not used here! +} + +void Water::framestep(float dt) +{ + update(); +} Copied: trunk/source/main/gfx/Water.h (from rev 2703, trunk/source/main/gfx/WaterOld.h) =================================================================== --- trunk/source/main/gfx/Water.h (rev 0) +++ trunk/source/main/gfx/Water.h 2012-05-26 19:21:09 UTC (rev 2708) @@ -0,0 +1,90 @@ +/* +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 __Water_H_ +#define __Water_H_ + +#include "RoRPrerequisites.h" + +#include "Ogre.h" +#include "IWater.h" + +extern float mrtime; + +class Water : public IWater +{ +public: + + Water(const Ogre::ConfigFile &mTerrainConfig); + + float getHeight(); + float getHeightWaves(Ogre::Vector3 pos); + Ogre::Vector3 getVelocity(Ogre::Vector3 pos); + + void setFadeColour(Ogre::ColourValue ambient); + void setHeight(float value); + void setSunPosition(Ogre::Vector3); + void setVisible(bool value); + + bool allowUnderWater(); + void framestep(float dt); + void moveTo(Ogre::Camera *cam, float centerheight); + void prepareShutdown(); + void showWave(Ogre::Vector3 refpos); + void update(); + void updateReflectionPlane(float h); + + enum water_quality {WATER_FULL_QUALITY, WATER_FULL_SPEED, WATER_REFLECT, WATER_BASIC}; + +private: + + typedef struct + { + float amplitude; + float maxheight; + float wavelength; + float wavespeed; + float direction; + } wavetrain_t; + + static const int WAVEREZ = 100; + static const int MAX_WAVETRAINS = 10; + + bool haswaves; + bool visible; + float *wbuffer; + float wheight; + float height, orgheight; + float maxampl; + float mScale; + int framecounter; + int free_wavetrain; + int mType; + Ogre::Camera *mReflectCam; + Ogre::Camera *mRefractCam; + Ogre::HardwareVertexBufferSharedPtr wbuf; + Ogre::RenderTexture* rttTex1; + Ogre::RenderTexture* rttTex2; + Ogre::SceneNode *pBottomNode; + Ogre::SceneNode *pTestNode; + Ogre::Viewport *vRtt1, *vRtt2; + wavetrain_t wavetrains[MAX_WAVETRAINS]; +}; + +#endif // __Water_H_ Deleted: trunk/source/main/gfx/WaterOld.cpp =================================================================== --- trunk/source/main/gfx/WaterOld.cpp 2012-05-26 18:49:59 UTC (rev 2707) +++ trunk/source/main/gfx/WaterOld.cpp 2012-05-26 19:21:09 UTC (rev 2708) @@ -1,506 +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 "WaterOld.h" - -#include "ResourceBuffer.h" -#include "RoRFrameListener.h" -#include "Settings.h" - -using namespace Ogre; - -Entity* pPlaneEnt; - -Plane waterPlane; -Plane bottomPlane; -Plane reflectionPlane; -Plane refractionPlane; -SceneManager *waterSceneMgr; - -class RefractionTextureListener : public RenderTargetListener -{ -public: - void preRenderTargetUpdate(const RenderTargetEvent& evt) - { - waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(false); - // Hide plane - pPlaneEnt->setVisible(false); - //hide WaterOld spray - if (RoRFrameListener::eflsingleton) RoRFrameListener::eflsingleton->showspray(false); - } - void postRenderTargetUpdate(const RenderTargetEvent& evt) - { - // Show plane - pPlaneEnt->setVisible(true); - waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(true); - //restore WaterOld spray - if (RoRFrameListener::eflsingleton) RoRFrameListener::eflsingleton->showspray(true); - } - -}; -class ReflectionTextureListener : public RenderTargetListener -{ -public: - void preRenderTargetUpdate(const RenderTargetEvent& evt) - { - waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(false); - // Hide plane - pPlaneEnt->setVisible(false); - - } - void postRenderTargetUpdate(const RenderTargetEvent& evt) - { - // Show plane - pPlaneEnt->setVisible(true); - waterSceneMgr->getRenderQueue()->getQueueGroup(RENDER_QUEUE_MAIN)->setShadowsEnabled(true); - } -}; - -RefractionTextureListener mRefractionListener; -ReflectionTextureListener mReflectionListener; - -WaterOld::WaterOld(int type, Camera *camera, SceneManager *mSceneMgr, RenderWindow *mWindow, float wheight, float *_mapsizex, float *_mapsizez, bool usewaves) -{ - vRtt1 = vRtt2 = 0; - mapsizex = _mapsizex; - mapsizez = _mapsizez; - mScale = 1.0f; - if(*mapsizex < 1500) - mScale = 1.5f; - //reading wavefield - visible=true; - haswaves=usewaves; - free_wavetrain=0; - maxampl=0; - - if(haswaves) - { - char line[1024] = {}; - FILE *fd = fopen((SSETTING("Config Root", "")+"wavefield.cfg").c_str(), "r"); - if (fd) - { - while (!feof(fd)) - { - int res = fscanf(fd," %[^\n\r]",line); - if (line[0] == ';') continue; - float wl,amp,mx,dir; - res = sscanf(line,"%f, %f, %f, %f",&wl,&,&mx,&dir); - if(res < 4) continue; - wavetrains[free_wavetrain].wavelength=wl; - wavetrains[free_wavetrain].amplitude=amp; - wavetrains[free_wavetrain].maxheight=mx; - wavetrains[free_wavetrain].direction=dir/57.0; - free_wavetrain++; - } - fclose(fd); - } - for (int i=0; i<free_wavetrain; i++) - { - wavetrains[i].wavespeed=1.25*sqrt(wavetrains[i].wavelength); - maxampl+=wavetrains[i].maxheight; - } - } - //theCam=camera; - pTestNode=0; - waterSceneMgr=mSceneMgr; - framecounter=0; - mCamera=camera; - height=wheight; - orgheight=wheight; - mType=type; - rttTex1=0; - rttTex2=0; - MeshPtr mprt; - mReflectCam=0; - mRefractCam=0; - //wbuf=0; - //ColourValue fade=camera->getViewport()->getBackgroundColour(); - ColourValue fade=mSceneMgr->getFogColour(); - - if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED || mType == WATER_REFLECT) - { - // Check prerequisites first - const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities(); - if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM))) - { - OGRE_EXCEPT(1, "Your card does not support vertex and fragment programs, so cannot " - "run WaterOld effects. Sorry!", - "WaterOld effects"); - } - else - { - if (!GpuProgramManager::getSingleton().isSyntaxSupported("arbfp1") && - !GpuProgramManager::getSingleton().isSyntaxSupported("ps_2_0") && - !GpuProgramManager::getSingleton().isSyntaxSupported("ps_1_4") - ) - { - OGRE_EXCEPT(1, "Your card does not support advanced fragment programs, " - "so cannot run WaterOld effects. Sorry!", - "WaterOld effects"); - } - } - // Ok - // Define a floor plane mesh - reflectionPlane.normal = Vector3::UNIT_Y; - reflectionPlane.d = -wheight+0.15; - refractionPlane.normal = -Vector3::UNIT_Y; - refractionPlane.d = wheight+0.15; - waterPlane.normal = Vector3::UNIT_Y; - waterPlane.d = -wheight; - - if (mType == WATER_FULL_QUALITY || mType == WATER_FULL_SPEED) - { - TexturePtr rttTex1Ptr = TextureManager::getSingleton().createManual("Refraction", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); - rttTex1 = rttTex1Ptr->getBuffer()->getRenderTarget(); - { - mRefractCam = mSceneMgr->createCamera("RefractCam"); - mRefractCam->setNearClipDistance(mCamera->getNearClipDistance()); - mRefractCam->setFarClipDistance(mCamera->getFarClipDistance()); - mRefractCam->setAspectRatio( - (Real)mWindow->getViewport(0)->getActualWidth() / - (Real)mWindow->getViewport(0)->getActualHeight()); - - vRtt1 = rttTex1->addViewport( mRefractCam ); - vRtt1->setClearEveryFrame( true ); - vRtt1->setBackgroundColour( fade ); - // v->setBackgroundColour( ColourValue::Black ); - - - MaterialPtr mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); - mat->getTechnique(0)->getPass(0)->getTextureUnitState(2)->setTextureName("Refraction"); - - vRtt1->setOverlaysEnabled(false); - - rttTex1->addListener(&mRefractionListener); - - //optimisation - rttTex1->setAutoUpdated(false); - - // Also clip - mRefractCam->enableCustomNearClipPlane(refractionPlane); - } - } - - TexturePtr rttTex2Ptr = TextureManager::getSingleton().createManual("Reflection", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, 512, 512, 0, PF_R8G8B8, TU_RENDERTARGET, new ResourceBuffer()); - rttTex2 = rttTex2Ptr->getBuffer()->getRenderTarget(); - { - mReflectCam = mSceneMgr->createCamera("ReflectCam"); - mReflectCam->setNearClipDistance(mCamera->getNearClipDistance()); - mReflectCam->setFarClipDistance(mCamera->getFarClipDistance()); - mReflectCam->setAspectRatio( - (Real)mWindow->getViewport(0)->getActualWidth() / - (Real)mWindow->getViewport(0)->getActualHeight()); - - vRtt2 = rttTex2->addViewport( mReflectCam ); - vRtt2->setClearEveryFrame( true ); - vRtt2->setBackgroundColour( fade ); - // v->setBackgroundColour( ColourValue::Black ); - - - MaterialPtr mat ; - if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED) mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflectionRefraction"); - else mat = MaterialManager::getSingleton().getByName("Examples/FresnelReflection"); - mat->getTechnique(0)->getPass(0)->getTextureUnitState(1)->setTextureName("Reflection"); - - vRtt2->setOverlaysEnabled(false); - - rttTex2->addListener(&mReflectionListener); - - //optimisation - rttTex2->setAutoUpdated(false); - - // set up linked reflection - mReflectCam->enableReflection(waterPlane); - // Also clip - mReflectCam->enableCustomNearClipPlane(reflectionPlane); - } - - mprt=MeshManager::getSingleton().createPlane("ReflectPlane", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - waterPlane, - *mapsizex * mScale,*mapsizez * mScale,WAVEREZ,WAVEREZ,true,1,50,50,Vector3::UNIT_Z, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); - pPlaneEnt = mSceneMgr->createEntity( "plane", "ReflectPlane" ); - if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED) pPlaneEnt->setMaterialName("Examples/FresnelReflectionRefraction"); - else pPlaneEnt->setMaterialName("Examples/FresnelReflection"); - // mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); - //position - pTestNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("WaterPlane"); - pTestNode->attachObject(pPlaneEnt); - pTestNode->setPosition( Vector3((*mapsizex * mScale)/2,0,(*mapsizez * mScale)/2) ); - } - else - { - //basic WaterOld - waterPlane.normal = Vector3::UNIT_Y; - waterPlane.d = -wheight; - mprt=MeshManager::getSingleton().createPlane("WaterPlane", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - waterPlane, - *mapsizex * mScale,*mapsizez * mScale,WAVEREZ,WAVEREZ,true,1,50,50,Vector3::UNIT_Z, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); - pPlaneEnt = mSceneMgr->createEntity( "plane", "WaterPlane" ); - pPlaneEnt->setMaterialName("tracks/basicwater"); - //position - pTestNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("WaterPlane"); - pTestNode->attachObject(pPlaneEnt); - pTestNode->setPosition( Vector3((*mapsizex * mScale)/2,0,(*mapsizez * mScale)/2) ); - } - //bottom - bottomPlane.normal = Vector3::UNIT_Y; - bottomPlane.d = -wheight+30.0; //30m below waterline - MeshManager::getSingleton().createPlane("BottomPlane", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, - bottomPlane, - *mapsizex * mScale,*mapsizez * mScale,1,1,true,1,1,1,Vector3::UNIT_Z); - Entity *pE = mSceneMgr->createEntity( "bplane", "BottomPlane" ); - pE->setMaterialName("tracks/seabottom"); - //position - pBottomNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BottomWaterPlane"); - pBottomNode->attachObject(pE); - pBottomNode->setPosition( Vector3((*mapsizex * mScale)/2,0,(*mapsizez * mScale)/2) ); - //setup for waves - wbuf=mprt->sharedVertexData->vertexBufferBinding->getBuffer(0); - if (wbuf->getSizeInBytes()==(WAVEREZ+1)*(WAVEREZ+1)*32) - { - wbuffer=(float*)malloc(wbuf->getSizeInBytes()); - wbuf->readData(0, wbuf->getSizeInBytes(), wbuffer); - } else wbuffer=0; -} - -bool WaterOld::allowUnderWater() -{ - return false; -} - -void WaterOld::setVisible(bool value) -{ - visible = value; - if(pPlaneEnt) - pPlaneEnt->setVisible(value); - if(pTestNode) - pTestNode->setVisible(value); - if(pBottomNode) - pBottomNode->setVisible(value); - -} - -void WaterOld::setFadeColour(ColourValue ambient) -{ - // update the viewports background colour! - if(vRtt1) vRtt1->setBackgroundColour(ambient); - if(vRtt2) vRtt2->setBackgroundColour(ambient); -} - - -void WaterOld::moveTo(Camera *cam, float centerheight) -{ - if (pTestNode) - { - Vector3 pos=cam->getPosition(); - Vector3 offset=cam->getDirection(); - offset.y=0; - offset.normalise(); - pos = pos + offset * *mapsizex * mScale * 0.46666; - pos.y=orgheight - height; - pos.x=((int)pos.x/60)*60; - pos.z=((int)pos.z/60)*60; - pTestNode->setPosition(pos); - pBottomNode->setPosition(pos); - if (haswaves) showWave(pos); - if (mType==WATER_FULL_QUALITY || mType==WATER_FULL_SPEED || mType==WATER_REFLECT) updateReflectionPlane(centerheight); - } -} - -void WaterOld::showWave(Vector3 refpos) -{ - int px,pz; - if (!wbuffer) return; - for (px=0; px<WAVEREZ+1; px++) - { - for (pz=0; pz<WAVEREZ+1; pz++) - { - wbuffer[(pz*(WAVEREZ+1)+px)*8+1]=getHeightWaves(refpos+Vector3((*mapsizex * mScale)/2-(float)px*(*mapsizex * mScale)/WAVEREZ, 0, (float)pz*(*mapsizez * mScale)/WAVEREZ-(*mapsizez * mScale)/2)); - } - } - //normals - for (px=0; px<WAVEREZ+1; px++) - { - for (pz=0; pz<WAVEREZ+1; pz++) - { - int left=px-1; if (left<0) left=0; - int right=px+1; if (right>WAVEREZ) right=WAVEREZ; - int up=pz-1; if (up<0) up=0; - int down=pz+1; if (down>WAVEREZ) down=WAVEREZ; - Vector3 normal=(Vector3(wbuffer+((pz*(WAVEREZ+1)+left)*8))-Vector3(wbuffer+((pz*(WAVEREZ+1)+right)*8))).crossProduct(Vector3(wbuffer+((up*(WAVEREZ+1)+px)*8))-Vector3(wbuffer+((down*(WAVEREZ+1)+px)*8))); - normal.normalise(); - wbuffer[(pz*(WAVEREZ+1)+px)*8+3]=normal.x; - wbuffer[(pz*(WAVEREZ+1)+px)*8+4]=normal.y; - wbuffer[(pz*(WAVEREZ+1)+px)*8+5]=normal.z; - } - } -// wbuf->lock(HardwareBuffer::HBL_DISCARD); - wbuf->writeData(0, (WAVEREZ+1)*(WAVEREZ+1)*32, wbuffer, true); -// if(wbuf->isLocked()) -// wbuf->unlock(); -} - -void WaterOld::update() -{ - if(!visible) - return; - framecounter++; - if (mType==WATER_FULL_SPEED) - { - if (framecounter%2) - { - mReflectCam->setOrientation(mCamera->getOrientation()); - mReflectCam->setPosition(mCamera->getPosition()); - mReflectCam->setFOVy(mCamera->getFOVy()); - rttTex2->update(); - } - else - { - mRefractCam->setOrientation(mCamera->getOrientation()); - mRefractCam->setPosition(mCamera->getPosition()); - mRefractCam->setFOVy(mCamera->getFOVy()); - rttTex1->update(); - } - } else if (mType==WATER_FULL_QUALITY) - { - mReflectCam->setOrientation(mCamera->getOrientation()); - mReflectCam->setPosition(mCamera->getPosition()); - mReflectCam->setFOVy(mCamera->getFOVy()); - rttTex2->update(); - mRefractCam->setOrientation(mCamera->getOrientation()); - mRefractCam->setPosition(mCamera->getPosition()); - mRefractCam->setFOVy(mCamera->getFOVy()); - rttTex1->update(); - } - else if (mType==WATER_REFLECT) - { - mReflectCam->setOrientation(mCamera->getOrientation()); - mReflectCam->setPosition(mCamera->getPosition()); - mReflectCam->setFOVy(mCamera->getFOVy()); - rttTex2->update(); - } -} - -void WaterOld::prepareShutdown() -{ - if (rttTex1) rttTex1->removeListener(&mRefractionListener); - if (rttTex2) rttTex2->removeListener(&mReflectionListener); -} - -float WaterOld::getHeight() {return height;}; - -void WaterOld::setHeight(float value) -{ - height = value; - update(); -} - -float WaterOld::getHeightWaves(Vector3 pos) -{ - // no waves? - if(!haswaves) - { - // constant height, sea is flat as pancake - return height; - } - - // uh, some upper limit?! - if (pos.y > height + maxampl) - return height; - - // calculate how high the waves should be at this point - // (*mapsizex * mScale) / 2 = terrain width / 2 - // (*mapsizez * mScale) / 2 = terrain height / 2 - // calculates the distance to the center of the terrain and dives it through 3.000.000 - float waveheight = (pos - Vector3((*mapsizex * mScale) / 2, height, (*mapsizez * mScale) / 2)).squaredLength() / 3000000.0; - // we will store the result in this variable, init it with the default height - float result = height; - // now walk through all the wave trains. One 'train' is one sin/cos set that will generate once wave. All the trains together will sum up, so that they generate a 'rough' sea - for (int i=0; i<free_wavetrain; i++) - { - // calculate the amplitude that this wave will have. wavetrains[i].amplitude is read from the config - float amp = wavetrains[i].amplitude * waveheight; - // upper limit: prevent too big waves by setting an upper limit - if (amp > wavetrains[i].maxheight) - amp = wavetrains[i].maxheight; - // now the main thing: - // calculate the sinus with the values of the config file and add it to the result - result += amp * sin(Math::TWO_PI * ( \ - (mrtime * wavetrains[i].wavespeed \ - + sin(wavetrains[i].direction) * pos.x \ - + cos(wavetrains[i].direction) * pos.z \ - ) \ - / wavetrains[i].wavelength) \ - ); - } - // return the summed up waves - return result; -} - -Vector3 WaterOld::getVelocity(Vector3 pos) -{ - if(!haswaves) return Vector3::ZERO; - - if (pos.y>height+maxampl) return Vector3::ZERO; - int i; - float waveheight=(pos-Vector3((*mapsizex * mScale)/2, height, (*mapsizez * mScale)/2)).squaredLength()/3000000.0; - Vector3 result=Vector3::ZERO; - for (i=0; i<free_wavetrain; i++) - { - float amp=wavetrains[i].amplitude*waveheight; - if (amp>wavetrains[i].maxheight) amp=wavetrains[i].maxheight; - float speed=6.28318*amp/(wavetrains[i].wavelength/wavetrains[i].wavespeed); - result.y+=speed*cos(6.28318*((mrtime*wavetrains[i].wavespeed+sin(wavetrains[i].direction)*pos.x+cos(wavetrains[i].direction)*pos.z)/wavetrains[i].wavelength)); - result+=Vector3(sin(wavetrains[i].direction), 0, cos(wavetrains[i].direction))*speed*sin(6.28318*((mrtime*wavetrains[i].wavespeed+sin(wavetrains[i].direction)*pos.x+cos(wavetrains[i].direction)*pos.z)/wavetrains[i].wavelength)); - } - return result; -} - - - -void WaterOld::updateReflectionPlane(float h) -{ - //Ray ra=mCamera->getCameraToViewportRay(0.5,0.5); - //std::pair<bool, Real> mpair=ra.intersects(Plane(Vector3::UNIT_Y, -height)); - //if (mpair.first) h=ra.getPoint(mpair.second).y; - reflectionPlane.d = -h+0.15; - refractionPlane.d = h+0.15; - waterPlane.d = -h; - if (mRefractCam) mRefractCam->enableCustomNearClipPlane(refractionPlane); - if (mReflectCam) - { - mReflectCam->enableReflection(waterPlane); - mReflectCam->enableCustomNearClipPlane(reflectionPlane); - }; - -} - - -void WaterOld::setSunPosition(Vector3) -{ - // not used here! -} - -void WaterOld::framestep(float dt) -{ - update(); -} Deleted: trunk/source/main/gfx/WaterOld.h =================================================================== --- trunk/source/main/gfx/WaterOld.h 2012-05-26 18:49:59 UTC (rev 2707) +++ trunk/source/main/gfx/WaterOld.h 2012-05-26 19:21:09 UTC (rev 2708) @@ -1,90 +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 __WaterOld_H__ -#define __WaterOld_H__ - -#include "RoRPrerequisites.h" - -#include "Ogre.h" -#include "IWater.h" - -extern float mrtime; - -class WaterOld : public Water -{ -public: - WaterOld(const Ogre::ConfigFile &mTerrainConfig); - - float getHeight(); - float getHeightWaves(Ogre::Vector3 pos); - Ogre::Vector3 getVelocity(Ogre::Vector3 pos); - - void setFadeColour(Ogre::ColourValue ambient); - void setHeight(float value); - void setSunPosition(Ogre::Vector3); - void setVisible(bool value); - - bool allowUnderWater(); - void framestep(float dt); - void moveTo(Ogre::Camera *cam, float centerheight); - void prepareShutdown(); - void showWave(Ogre::Vector3 refpos); - void update(); - void updateReflectionPlane(float h); - - enum water_quality {WATER_FULL_QUALITY, WATER_FULL_SPEED, WATER_REFLECT, WATER_BASIC}; - -private: - - typedef struct - { - float amplitude; - float maxheight; - float wavelength; - float wavespeed; - float direction; - } wavetrain_t; - - static const int WAVEREZ = 100; - static const int MAX_WAVETRAINS = 10; - - bool haswaves; - bool visible; - Ogre::Camera *mCamera; - Ogre::Camera *mReflectCam; - Ogre::Camera *mRefractCam; - float *mapsizex, *mapsizez; - float *wbuffer; - float height, orgheight; - float maxampl; - float mScale; - Ogre::HardwareVertexBufferSharedPtr wbuf; - int framecounter; - int free_wavetrain; - int mType; - Ogre::Viewport *vRtt1, *vRtt2; - Ogre::RenderTexture* rttTex1; - Ogre::RenderTexture* rttTex2; - Ogre::SceneNode *pBottomNode; - Ogre::SceneNode *pTestNode; - wavetrain_t wavetrains[MAX_WAVETRAINS]; -}; - -#endif // __WaterOld_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