[Python-ogre-commit] SF.net SVN: python-ogre:[688] trunk/python-ogre
Brought to you by:
andy_miller,
roman_yakovenko
From: <and...@us...> - 2008-08-15 08:08:02
|
Revision: 688 http://python-ogre.svn.sourceforge.net/python-ogre/?rev=688&view=rev Author: andy_miller Date: 2008-08-15 08:08:10 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Adding Hydrax 0.3 to the svn Added Paths: ----------- trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.cpp trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.h trunk/python-ogre/ThirdParty/Hydrax/Enums.cpp trunk/python-ogre/ThirdParty/Hydrax/Enums.h trunk/python-ogre/ThirdParty/Hydrax/Help.cpp trunk/python-ogre/ThirdParty/Hydrax/Help.h trunk/python-ogre/ThirdParty/Hydrax/Hydrax.cpp trunk/python-ogre/ThirdParty/Hydrax/Hydrax.h trunk/python-ogre/ThirdParty/Hydrax/Image.cpp trunk/python-ogre/ThirdParty/Hydrax/Image.h trunk/python-ogre/ThirdParty/Hydrax/MaterialManager.cpp trunk/python-ogre/ThirdParty/Hydrax/MaterialManager.h trunk/python-ogre/ThirdParty/Hydrax/Mesh.cpp trunk/python-ogre/ThirdParty/Hydrax/Mesh.h trunk/python-ogre/ThirdParty/Hydrax/Module.cpp trunk/python-ogre/ThirdParty/Hydrax/Module.h trunk/python-ogre/ThirdParty/Hydrax/Noise.cpp trunk/python-ogre/ThirdParty/Hydrax/Noise.h trunk/python-ogre/ThirdParty/Hydrax/Perlin.cpp trunk/python-ogre/ThirdParty/Hydrax/Perlin.h trunk/python-ogre/ThirdParty/Hydrax/Prerequisites.cpp trunk/python-ogre/ThirdParty/Hydrax/Prerequisites.h trunk/python-ogre/ThirdParty/Hydrax/ProjectedGrid.cpp trunk/python-ogre/ThirdParty/Hydrax/ProjectedGrid.h trunk/python-ogre/ThirdParty/Hydrax/SimpleGrid.cpp trunk/python-ogre/ThirdParty/Hydrax/SimpleGrid.h trunk/python-ogre/ThirdParty/Hydrax/Structs.cpp trunk/python-ogre/ThirdParty/Hydrax/Structs.h trunk/python-ogre/ThirdParty/Hydrax/TextureManager.cpp trunk/python-ogre/ThirdParty/Hydrax/TextureManager.h trunk/python-ogre/code_generators/hydrax/ trunk/python-ogre/code_generators/hydrax/customization_data.py trunk/python-ogre/code_generators/hydrax/generate_code.py trunk/python-ogre/code_generators/hydrax/hand_made_wrappers.py trunk/python-ogre/code_generators/hydrax/python_hydrax.h trunk/python-ogre/code_generators/hydrax/python_hydrax_aliases.h trunk/python-ogre/code_generators/hydrax/python_hydrax_sizeof.h Added: trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.cpp =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.cpp 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,271 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#include "DecalsManager.h" + +#include "Hydrax.h" + +namespace Hydrax +{ + Decal::Decal(Hydrax *h, const Ogre::String &TextureName, const int& Id) + : mHydrax(h) + , mTextureName(TextureName) + , mId(Id) + , mRegisteredPass(0) + , mPosition(Ogre::Vector2(0,0)) + , mSize(Ogre::Vector2(1,1)) + , mOrientation(Ogre::Radian(0)) + , mTransparency(1) + , mVisible(true) + { + mProjector = new Ogre::Frustum(); + mProjector->setProjectionType(Ogre::PT_ORTHOGRAPHIC); + + mSceneNode = mHydrax->getSceneManager()->getRootSceneNode()->createChildSceneNode(); + mSceneNode->attachObject(mProjector); + mSceneNode->setPosition(Ogre::Vector3(0,0,0)); + mSceneNode->setOrientation(Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::NEGATIVE_UNIT_X)); + + setPosition(mPosition); + setSize(mSize); + setOrientation(mOrientation); + } + + Decal::~Decal() + { + if (mRegisteredPass) + { + mRegisteredPass->getParent()->removePass(mRegisteredPass->getIndex()); + mRegisteredPass = static_cast<Ogre::Pass*>(NULL); + } + + mSceneNode->getParentSceneNode()->removeAndDestroyChild(mSceneNode->getName()); + + delete mProjector; + } + + void Decal::registerPass(Ogre::Pass* _Pass) + { + if (mRegisteredPass) + { + mRegisteredPass->getParent()->removePass(mRegisteredPass->getIndex()); + mRegisteredPass = static_cast<Ogre::Pass*>(NULL); + } + + _Pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); + _Pass->setDepthBias(1,1); + _Pass->setLightingEnabled(false); + _Pass->setDepthWriteEnabled(false); + + Ogre::TextureUnitState *DecalTexture = _Pass->createTextureUnitState(mTextureName); + DecalTexture->setProjectiveTexturing(true, mProjector); + DecalTexture->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); + DecalTexture->setTextureFiltering(Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE); + DecalTexture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, mTransparency); + + mRegisteredPass = _Pass; + } + + void Decal::unregister() + { + if (mRegisteredPass) + { + mRegisteredPass->getParent()->removePass(mRegisteredPass->getIndex()); + mRegisteredPass = static_cast<Ogre::Pass*>(NULL); + } + } + + void Decal::setPosition(const Ogre::Vector2& Position) + { + mPosition = Position; + + mSceneNode->setPosition(Position.x, 0, Position.y); + } + + void Decal::setSize(const Ogre::Vector2& Size) + { + mSize = Size; + + // This method is only available in the CVS HEAD, + // if you have problems compiling, just comment the + // following line: + mProjector->setOrthoWindow(Size.x, Size.y); + } + + void Decal::setOrientation(const Ogre::Radian& Orientation) + { + mSceneNode->rotate(Ogre::Vector3::UNIT_Z, -mOrientation + Orientation); + + mOrientation = Orientation; + } + + void Decal::setTransparency(const Ogre::Real& Transparency) + { + mTransparency = Transparency; + + if (mRegisteredPass) + { + mRegisteredPass->getTextureUnitState(0) + ->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, mTransparency); + } + } + + void Decal::setVisible(const bool& Visible) + { + mVisible = Visible; + + unregister(); + } + + // -------------------------------------------------------------------- + + DecalsManager::DecalsManager(Hydrax *h) + : mHydrax(h) + , mNextId(0) + , mWaterStrength(5) + { + } + + DecalsManager::~DecalsManager() + { + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + delete (*DecalIt); + } + + mDecals.clear(); + } + + void DecalsManager::update() + { + if (mHydrax->getCamera()->getPosition() == mLastPosition && + mHydrax->getCamera()->getOrientation() == mLastOrientation) + { + return; + } + + Ogre::Vector2 DPos; + Ogre::Real HHeight = mHydrax->getPosition().y; + Ogre::Vector2 DSize; + Ogre::AxisAlignedBox DecalBox; + + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + if (!(*DecalIt)->isVisible()) + { + continue; + } + + DPos = (*DecalIt)->getPosition(); + DSize = (*DecalIt)->getSize()/2; + + DecalBox = Ogre::AxisAlignedBox(DPos.x - DSize.x, HHeight - mWaterStrength, DPos.y - DSize.y, + DPos.x + DSize.x, HHeight + mWaterStrength, DPos.y + DSize.y); + + if (mHydrax->getCamera()->isVisible(DecalBox)) + { + if (!(*DecalIt)->getRegisteredPass()) + { + (*DecalIt)->registerPass( + mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_WATER)-> + getTechnique(0)->createPass()); + } + } + else + { + (*DecalIt)->unregister(); + } + } + + mLastPosition = mHydrax->getCamera()->getPosition(); + mLastOrientation = mHydrax->getCamera()->getOrientation(); + } + + Decal* DecalsManager::add(const Ogre::String& TextureName) + { + Decal* NewDecal = new Decal(mHydrax, TextureName, mNextId); + + mDecals.push_back(NewDecal); + + if (mHydrax->getMaterialManager()->isCreated()) + { + NewDecal->registerPass( + mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_WATER)-> + getTechnique(0)->createPass()); + } + + mNextId++; + + return NewDecal; + } + + Decal* DecalsManager::get(const int& Id) + { + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + if((*DecalIt)->getId() == Id) + { + return (*DecalIt); + } + } + + return static_cast<Decal*>(NULL); + } + + void DecalsManager::remove(const int& Id) + { + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + if((*DecalIt)->getId() == Id) + { + delete (*DecalIt); + mDecals.erase(DecalIt); + + return; + } + } + } + + void DecalsManager::removeAll() + { + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + delete (*DecalIt); + } + + mDecals.clear(); + + mNextId = 0; + } + + void DecalsManager::registerAll() + { + for(DecalIt = mDecals.begin(); DecalIt != mDecals.end(); DecalIt++) + { + (*DecalIt)->registerPass( + mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_WATER)-> + getTechnique(0)->createPass()); + } + } +} Added: trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.h =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.h (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/DecalsManager.h 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,283 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#ifndef _Hydrax_DecalsManager_H_ +#define _Hydrax_DecalsManager_H_ + +#include "Prerequisites.h" + +namespace Hydrax +{ + class Hydrax; + + /** Decal class. + */ + class DllExport Decal + { + public: + /** Constructor + @param h Hydrax parent pointer + @param TextureName Texture name + @param Id Decal Id + */ + Decal(Hydrax *h, const Ogre::String &TextureName, const int& Id); + + /** Destructor + */ + ~Decal(); + + /** Register the decal int the specified pass + @param _Pass Pass to be registred + */ + void registerPass(Ogre::Pass* _Pass); + + /** Unregister from current technique + */ + void unregister(); + + /** Get decal texture name + @return Decal texture name + */ + inline const Ogre::String& getTextureName() const + { + return mTextureName; + } + + /** Get the decal Id + @return Decal Id + */ + inline const int& getId() const + { + return mId; + } + + /** Get the decal projector + @return Projector frustum + */ + inline Ogre::Frustum* getProjector() + { + return mProjector; + } + + /** Get the decal scene node + @return Decal scene node + */ + inline Ogre::SceneNode* getSceneNode() + { + return mSceneNode; + } + + /** Get the pass the decal is in + @return Registered pass + @remarks return NULL if decal isn't registered + */ + inline Ogre::Pass *getRegisteredPass() + { + return mRegisteredPass; + } + + /** Get decal position + @return Decal position + */ + inline const Ogre::Vector2& getPosition() const + { + return mPosition; + } + + /** Get decal size + @return Decal size + */ + inline const Ogre::Vector2& getSize() const + { + return mSize; + } + + /** Get decal orientation + @return Decal orientation + */ + inline const Ogre::Radian& getOrientation() const + { + return mOrientation; + } + + /** Get decal transparency + @return Decal transparency + */ + inline const Ogre::Real& getTransparency() const + { + return mTransparency; + } + + /** Is decal visile? + @return true if decal is visible + */ + inline const bool& isVisible() const + { + return mVisible; + } + + /** Set decal position + @param Position Decal position + */ + void setPosition(const Ogre::Vector2& Position); + + /** Set decal size + @param Size Decal size in world coordinates + */ + void setSize(const Ogre::Vector2& Size); + + /** Set decal orientation + @param Orientation Decal orientation + */ + void setOrientation(const Ogre::Radian& Orientation); + + /** Set decal transparency + @param Transparency Decal transparency in [0,1] range + @remarks 0 = Full transparent, 1 = Full opacity + */ + void setTransparency(const Ogre::Real& Transparency); + + /** Set decal visibile or not + @param Visible true if yes, false if not + */ + void setVisible(const bool& Visible); + + private: + /// Decal texture name + Ogre::String mTextureName; + /// Decal Id + int mId; + /// Decal projector + Ogre::Frustum *mProjector; + /// Decal scene node + Ogre::SceneNode *mSceneNode; + /// Registered pass + Ogre::Pass *mRegisteredPass; + + /// Position + Ogre::Vector2 mPosition; + /// Size + Ogre::Vector2 mSize; + /// Orientation + Ogre::Radian mOrientation; + /// Transparency + Ogre::Real mTransparency; + /// Is decal visible? + bool mVisible; + + /// Hydrax parent pointer + Hydrax *mHydrax; + }; + + /** Decals manager class. Use it for place any kind of texture + over the water! Like ship trails, overwater vegetables, ... + */ + class DllExport DecalsManager + { + public: + /** Constructor + @param h Hydrax parent pointer + */ + DecalsManager(Hydrax *h); + + /** Destructor + */ + ~DecalsManager(); + + /** Update decal manager + @remarks Call each frame + */ + void update(); + + /** Add decal + @param TextureName Texture name + @return Hydrax::Decal* Use it as a usual Ogre::SceneNode(Decal::getSceneNode()) for position, rotate...etc! + */ + Decal* add(const Ogre::String& TextureName); + + /** Get decal + @param Id Decal Id + @return Hydrax::Decal* + */ + Decal* get(const int& Id); + + /** Remove decal + @param Id Decal Id + */ + void remove(const int& Id); + + /** Remove all decals + */ + void removeAll(); + + /** Register all decals + @remarks Use it when water material is (re)created + */ + void registerAll(); + + /** Get decals std::vector + @return std::vector<Decal*> list + */ + inline std::vector<Decal*> getDecals() + { + return mDecals; + } + + /** Get water strength (used for decals culling) + @return Water strength + */ + inline const Ogre::Real _getWaterStrength() const + { + return mWaterStrength; + } + + /** Set water strength (used for decals culling) + @param WaterStrength Water strength + */ + inline void _setWaterStrength(const Ogre::Real &WaterStrength) + { + mWaterStrength = WaterStrength; + } + + private: + /// Decals std::vector + std::vector<Decal*> mDecals; + /// Decal iterator + std::vector<Decal*>::iterator DecalIt; + /// Next Id + int mNextId; + + /// Water strength (For decals culling) + Ogre::Real mWaterStrength; + + /// Last camera position, orientation + Ogre::Vector3 mLastPosition; + Ogre::Quaternion mLastOrientation; + + /// Hydrax parent pointer + Hydrax *mHydrax; + }; +}; + +#endif \ No newline at end of file Added: trunk/python-ogre/ThirdParty/Hydrax/Enums.cpp =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/Enums.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/Enums.cpp 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,30 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#include "Enums.h" + +namespace Hydrax +{ + +} Added: trunk/python-ogre/ThirdParty/Hydrax/Enums.h =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/Enums.h (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/Enums.h 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,66 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#ifndef _Hydrax_Enums_H_ +#define _Hydrax_Enums_H_ + +#include "Prerequisites.h" + +namespace Hydrax +{ + /** Texture quality enumeration(2^n) + */ + DllExport enum TextureQuality + { + TEX_QUA_2 = 2, + TEX_QUA_4 = 4, + TEX_QUA_8 = 8, + TEX_QUA_16 = 16, + TEX_QUA_32 = 32, + TEX_QUA_64 = 64, + TEX_QUA_128 = 128, + TEX_QUA_256 = 256, + TEX_QUA_512 = 512, + TEX_QUA_1024 = 1024 + }; + + /** Hydrax flags for select the components + that we want to use. + 0 for none, 1 for all. + */ + DllExport enum HydraxComponent + { + HYDRAX_COMPONENT_SUN = 1 << 0, + HYDRAX_COMPONENT_FOAM = 1 << 1, + HYDRAX_COMPONENT_DEPTH = 1 << 2, + /// Smooth transitions and caustics components need depth component + HYDRAX_COMPONENT_SMOOTH = 1 << 3, + HYDRAX_COMPONENT_CAUSTICS = 1 << 4, + + HYDRAX_COMPONENTS_NONE = 0x0000, + HYDRAX_COMPONENTS_ALL = 0x001F, + }; +} + +#endif Added: trunk/python-ogre/ThirdParty/Hydrax/Help.cpp =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/Help.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/Help.cpp 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,74 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#include "Help.h" + +namespace Hydrax +{ + Ogre::Vector2 Math::intersectionOfTwoLines(const Ogre::Vector2 &a, const Ogre::Vector2 &b, + const Ogre::Vector2 &c, const Ogre::Vector2 &d) + { + float r, s, denominator = (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x); + + // If the denominator in above is zero, AB & CD are colinear + if (denominator == 0) + { + return Ogre::Vector2::ZERO; + } + + float numeratorR = (a.y - c.y) * (d.x - c.x) - (a.x - c.x) * (d.y - c.y); + // If the numerator above is also zero, AB & CD are collinear. + // If they are collinear, then the segments may be projected to the x- + // or y-axis, and overlap of the projected intervals checked. + + r = numeratorR / denominator; + + float numeratorS = (a.y - c.y) * (b.x - a.x) - (a.x - c.x) * (b.y - a.y); + + s = numeratorS / denominator; + + // If 0<=r<=1 & 0<=s<=1, intersection exists + // r<0 or r>1 or s<0 or s>1 line segments do not intersect + if (r < 0 || r > 1 || s < 0 || s > 1) + { + return Ogre::Vector2::ZERO; + } + + ///* + // Note: + // If the intersection point of the 2 lines are needed (lines in this + // context mean infinite lines) regardless whether the two line + // segments intersect, then + // + // If r>1, P is located on extension of AB + // If r<0, P is located on extension of BA + // If s>1, P is located on extension of CD + // If s<0, P is located on extension of DC + //*/ + + // Find intersection point + return Ogre::Vector2((a.x + (r * (b.x - a.x))), + (a.y + (r * (b.y - a.y)))); + } +} Added: trunk/python-ogre/ThirdParty/Hydrax/Help.h =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/Help.h (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/Help.h 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,118 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#ifndef _Hydrax_Help_H_ +#define _Hydrax_Help_H_ + +#include "Prerequisites.h" + +namespace Hydrax +{ + /** Struct wich contains an especific width and height value + */ + struct DllExport Size + { + /// Width value + int Width; + /// Height value + int Height; + + /** Default constructor + */ + Size() + { + Width = 0; + Height = 0; + } + + /** Constructor + @param size The width and height values + */ + Size(const int &size) + { + Width = size; + Height = size; + } + + /** Constructor + @param width Width value + @param height Height value + */ + Size(const int &width, const int &height) + { + Width = width; + Height = height; + } + + /** Destructor + */ + ~Size() + { + } + + /** Sets the same width and height value + @param size The width and height values + */ + void setSize(const int &size) + { + Width = size; + Height = size; + } + + /** Sets the especified values + @param width Width value + @param height Height value + */ + void setSize(const int &width, const int &height) + { + Width = width; + Height = height; + } + }; + + /** Math class with some help funtions + */ + class Math + { + public: + /** Constructor + */ + Math(){}; + /** Destructor + */ + ~Math(){}; + + /** Find the intersection point of two lines + @param a First line origin + @param b First line final + @param c First line origin + @param d First line final + @return Ogre::Vector2::ZERO if there isn't intersection, intersection point + */ + static Ogre::Vector2 intersectionOfTwoLines(const Ogre::Vector2 &a, const Ogre::Vector2 &b, + const Ogre::Vector2 &c, const Ogre::Vector2 &d); + }; +} + +#endif Added: trunk/python-ogre/ThirdParty/Hydrax/Hydrax.cpp =================================================================== --- trunk/python-ogre/ThirdParty/Hydrax/Hydrax.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/Hydrax/Hydrax.cpp 2008-08-15 08:08:10 UTC (rev 688) @@ -0,0 +1,1210 @@ +/* +-------------------------------------------------------------------------------- +This source file is part of Hydrax. +Visit --- + +Copyright (C) 2008 Xavier Vergu\xEDn Gonz\xE1lez <xav...@ho...> + <xa...@gm...> + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program 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 Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place - Suite 330, Boston, MA 02111-1307, USA, or go to +http://www.gnu.org/copyleft/lesser.txt. +-------------------------------------------------------------------------------- +*/ + +#pragma warning(disable:4355) + +#include "Hydrax.h" + +namespace Hydrax +{ + + Hydrax::Hydrax(Ogre::SceneManager *sm, Ogre::Camera *c) + : mSceneManager(sm) + , mCamera(c) + , mCreated(false) + , mPolygonMode(0) + , mShaderMode(MaterialManager::SM_HLSL) + , mPosition(Ogre::Vector3(0,0,0)) + , mPlanesError(0) + , mFullReflectionDistance(99999997952.0) + , mGlobalTransparency(0.05) + , mNormalDistortion(0.09) + , mSunPosition(Ogre::Vector3(5000,3000,1)) + , mSunStrength(1.75) + , mSunArea(150) + , mSunColor(Ogre::Vector3(1,0.75,0.25)) + , mFoamMaxDistance(75000000.0) + , mFoamScale(0.0075) + , mFoamStart(0) + , mFoamTransparency(1) + , mDepthLimit(0) + , mDepthColor(Ogre::Vector3(0,0.1,0.172)) + , mSmoothPower(30) + , mCausticsScale(20) + , mCausticsPower(15) + , mCausticsEnd(0.55) + , mMesh(new Mesh(this)) + , mTextureManager(new TextureManager(this)) + , mMaterialManager(new MaterialManager(this)) + , mDecalsManager(new DecalsManager(this)) + , mModule(0) + , mSceneNode(0) + , mRefractionPlane(0) + , mReflectionPlane(0) + , mDepthPlane(0) + , mTextureRefraction(0) + , mTextureReflection(0) + , mTextureDepth(0) + , mPlanesSceneNode(0) + , mComponents(HYDRAX_COMPONENTS_NONE) + { + HydraxLOG("Hydrax object created."); + } + + Hydrax::~Hydrax() + { + if (mModule) + { + delete mModule; + } + + if (mSceneNode) + { + mSceneNode->detachAllObjects(); + mSceneNode->getParentSceneNode()->removeAndDestroyChild(mSceneNode->getName()); + + delete mTextureManager; + delete mMaterialManager; + delete mDecalsManager; + delete mMesh; + } + + if (mPlanesSceneNode) + { + mPlanesSceneNode->detachAllObjects(); + mPlanesSceneNode->getParentSceneNode()->removeAndDestroyChild(mPlanesSceneNode->getName()); + + Ogre::RenderTarget* mRT_TextureRefraction = mTextureRefraction->getBuffer()->getRenderTarget(); + mRT_TextureRefraction->removeAllListeners(); + mRT_TextureRefraction->removeAllViewports(); + + Ogre::RenderTarget* mRT_TextureReflection = mTextureReflection->getBuffer()->getRenderTarget(); + mRT_TextureReflection->removeAllListeners(); + mRT_TextureReflection->removeAllViewports(); + + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + Ogre::RenderTarget* mRT_TextureDepth = mTextureDepth->getBuffer()->getRenderTarget(); + mRT_TextureDepth->removeAllListeners(); + mRT_TextureDepth->removeAllViewports(); + + Ogre::TextureManager::getSingleton().remove("HydraxDepthMap"); + + Ogre::MeshManager::getSingleton().remove("DepthClipPlane"); + } + + Ogre::TextureManager::getSingleton().remove("HydraxReflectionMap"); + Ogre::TextureManager::getSingleton().remove("HydraxRefractionMap"); + + Ogre::MeshManager::getSingleton().remove("RefractionClipPlane"); + Ogre::MeshManager::getSingleton().remove("ReflectionClipPlane"); + } + + HydraxLOG("Hydrax object removed."); + } + + void Hydrax::create() + { + if (mModule == NULL) + { + HydraxLOG("Module isn't set, skipping..."); + + return; + } + + if (mCreated) + { + HydraxLOG("Hydrax alredy created, skipping..."); + + return; + } + + HydraxLOG("Creating module."); + mModule->create(); + HydraxLOG("Module created."); + + HydraxLOG("Creating RTListeners."); + _createRttListeners(); + HydraxLOG("RTListeners created"); + + HydraxLOG("Registring device restored listener"); + mDeviceRestoredListener.mHydrax = this; + Ogre::Root::getSingleton().getRenderSystem()->addListener(&mDeviceRestoredListener); + HydraxLOG("Device restored listener registred"); + + HydraxLOG("Creating materials,"); + mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode())); + mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName()); + HydraxLOG("Materials created."); + + HydraxLOG("Creating water mesh."); + mSceneNode = mSceneManager->getRootSceneNode()->createChildSceneNode(); + mMesh->setOptions(mModule->getMeshOptions()); + mMesh->create(mSceneNode); + HydraxLOG("Water mesh created"); + + mCreated = true; + } + + void Hydrax::DeviceRestoredListener::eventOccurred(const Ogre::String& eventName, const Ogre::NameValuePairList *parameters) + { + if (eventName == "DeviceRestored") + { + // Restore mesh + HydraxLOG("Restoring water mesh."); + if (mHydrax->mMesh->isCreated()) + { + Ogre::String MaterialNameTmp = mHydrax->mMesh->getMaterialName(); + Mesh::Options MeshOptionsTmp = mHydrax->mMesh->getOptions(); + + HydraxLOG("Updating water mesh."); + + HydraxLOG("Deleting water mesh."); + delete mHydrax->mMesh; + HydraxLOG("Water mesh deleted."); + + HydraxLOG("Creating water mesh."); + mHydrax->mMesh = new Mesh(mHydrax); + mHydrax->mMesh->setOptions(MeshOptionsTmp); + mHydrax->mMesh->setMaterialName(MaterialNameTmp); + mHydrax->mMesh->create(mHydrax->mSceneNode); + mHydrax->setPosition(mHydrax->mPosition); + mHydrax->mModule->update(0); // ??? + HydraxLOG("Water mesh created"); + } + HydraxLOG("Water mesh restored."); + } + } + + void Hydrax::_createRttListeners() + { + if (!mCreated) + { + mRefractionPlane = new Ogre::MovablePlane("RefractionPlane"); + mReflectionPlane = new Ogre::MovablePlane("ReflectionPlane"); + + mRefractionPlane->d = 0; + mReflectionPlane->d = 0; + + mRefractionPlane->normal = Ogre::Vector3::NEGATIVE_UNIT_Y; + mReflectionPlane->normal = Ogre::Vector3::UNIT_Y; + + Ogre::MeshManager::getSingleton().createPlane( + "RefractionClipPlane",HYDRAX_RESOURCE_GROUP, + *mRefractionPlane, + mMesh->getSize().Width,mMesh->getSize().Height, + 10,10,true,1,5,5,Ogre::Vector3::UNIT_Z); + + Ogre::MeshManager::getSingleton().createPlane( + "ReflectionClipPlane",HYDRAX_RESOURCE_GROUP, + *mReflectionPlane, + mMesh->getSize().Width,mMesh->getSize().Height, + 10,10,true,1,5,5,Ogre::Vector3::UNIT_Z); + + mRefractionPlane->setCastShadows(false); + mReflectionPlane->setCastShadows(false); + + mPlanesSceneNode = mSceneManager->getRootSceneNode()->createChildSceneNode(); + mPlanesSceneNode->attachObject(mRefractionPlane); + mPlanesSceneNode->attachObject(mReflectionPlane); + + mReflectionListener.mHydrax = this; + mRefractionListener.mHydrax = this; + + mReflectionListener.mCReflectionQueueListener.mHydrax = this; + mReflectionListener.mCReflectionQueueListener.mActive = false; + mSceneManager->addRenderQueueListener(&mReflectionListener.mCReflectionQueueListener); + } + + Ogre::TextureManager::getSingleton().remove("HydraxReflectionMap"); + Ogre::TextureManager::getSingleton().remove("HydraxRefractionMap"); + + mTextureRefraction = Ogre::TextureManager::getSingleton().createManual( + "HydraxRefractionMap", + HYDRAX_RESOURCE_GROUP, + Ogre::TEX_TYPE_2D, + mRttOptions.RefractionQuality, mRttOptions.RefractionQuality, 0, + Ogre::PF_R8G8B8, + Ogre::TU_RENDERTARGET); + + Ogre::RenderTarget* mRT_TextureRefraction = mTextureRefraction->getBuffer()->getRenderTarget(); + { + Ogre::Viewport *v = mRT_TextureRefraction->addViewport(mCamera); + v->setClearEveryFrame(true); + v->setBackgroundColour(Ogre::ColourValue::White); + v->setOverlaysEnabled(false); + + mRT_TextureRefraction->addListener(&mRefractionListener); + } + + mTextureReflection = Ogre::TextureManager::getSingleton().createManual( + "HydraxReflectionMap", + HYDRAX_RESOURCE_GROUP, + Ogre::TEX_TYPE_2D, + mRttOptions.ReflectionQuality, mRttOptions.ReflectionQuality, 0, + Ogre::PF_R8G8B8, + Ogre::TU_RENDERTARGET); + + Ogre::RenderTarget* mRT_TextureReflection = mTextureReflection->getBuffer()->getRenderTarget(); + { + Ogre::Viewport *v = mRT_TextureReflection->addViewport(mCamera); + v->setClearEveryFrame(true); + v->setBackgroundColour(Ogre::ColourValue::White); + v->setOverlaysEnabled(false); + + mRT_TextureReflection->addListener(&mReflectionListener); + } + + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + _createDepthRttListener(); + } + + getMaterialManager()->reload(MaterialManager::MAT_WATER); + } + + void Hydrax::_createDepthRttListener(const bool &Create, const bool &Delete) + { + if (Create) + { + Ogre::TextureManager::getSingleton().remove("HydraxDepthMap"); + + if (!mCreated) + { + mDepthPlane = new Ogre::MovablePlane("DepthPlane"); + + mDepthPlane->d = 0; + mDepthPlane->normal = Ogre::Vector3::NEGATIVE_UNIT_Y; + + Ogre::MeshManager::getSingleton().createPlane( + "DepthClipPlane",HYDRAX_RESOURCE_GROUP, + *mDepthPlane, + mMesh->getSize().Width,mMesh->getSize().Height, + 10,10,true,1,5,5,Ogre::Vector3::UNIT_Z); + + mDepthPlane->setCastShadows(false); + + mPlanesSceneNode->attachObject(mDepthPlane); + + mDepthListener.mHydrax = this; + } + + mTextureDepth = Ogre::TextureManager::getSingleton().createManual( + "HydraxDepthMap", + HYDRAX_RESOURCE_GROUP, + Ogre::TEX_TYPE_2D, + mRttOptions.DepthQuality, mRttOptions.DepthQuality, 0, + Ogre::PF_R8G8B8, + Ogre::TU_RENDERTARGET); + + Ogre::RenderTarget* mRT_TextureDepth = mTextureDepth->getBuffer()->getRenderTarget(); + { + Ogre::Viewport *v = mRT_TextureDepth->addViewport(mCamera); + v->setClearEveryFrame(true); + v->setBackgroundColour(Ogre::ColourValue::Black); + v->setOverlaysEnabled(false); + v->setMaterialScheme("HydraxDepth"); + v->setSkiesEnabled(false); + + mRT_TextureDepth->addListener(&mDepthListener); + } + + getMaterialManager()->reload(MaterialManager::MAT_WATER); + } + if (Delete) + { + Ogre::RenderTarget* mRT_TextureDepth = mTextureDepth->getBuffer()->getRenderTarget(); + mRT_TextureDepth->removeAllListeners(); + mRT_TextureDepth->removeAllViewports(); + + Ogre::TextureManager::getSingleton().remove("HydraxDepthMap"); + + Ogre::MeshManager::getSingleton().remove("DepthClipPlane"); + } + } + + void Hydrax::CReflectionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + mCReflectionQueueListener.mActive = true; + + mHydrax->mMesh->getEntity()->setVisible(false); + mHydrax->mReflectionPlane->getParentNode()->translate(0,mHydrax->mPlanesError,0); + + if (mHydrax->mCamera->getPosition().y < mHydrax->mReflectionPlane->getParentNode()->getPosition().y) + { + mCameraPlaneDiff = mHydrax->mReflectionPlane->getParentNode()->getPosition().y-mHydrax->mCamera->getPosition().y+0.05; + mHydrax->mReflectionPlane->getParentNode()->translate(0,-mCameraPlaneDiff,0); + } + else + { + mCameraPlaneDiff = 0; + } + + mHydrax->mCamera->enableReflection(mHydrax->mReflectionPlane); + mHydrax->mCamera->enableCustomNearClipPlane(mHydrax->mReflectionPlane); + } + + void Hydrax::CReflectionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + mHydrax->mMesh->getEntity()->setVisible(true); + + if (mCameraPlaneDiff != 0) + { + mHydrax->mReflectionPlane->getParentNode()->translate(0,mCameraPlaneDiff,0); + } + + mHydrax->mReflectionPlane->getParentNode()->translate(0,-mHydrax->mPlanesError,0); + + mHydrax->mCamera->disableReflection(); + mHydrax->mCamera->disableCustomNearClipPlane(); + + mCReflectionQueueListener.mActive = false; + } + + void Hydrax::CRefractionListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + mHydrax->mMesh->getEntity()->setVisible(false); + mHydrax->mRefractionPlane->getParentNode()->translate(0,mHydrax->mPlanesError,0); + + if (mHydrax->mCamera->getPosition().y < mHydrax->mRefractionPlane->getParentNode()->getPosition().y) + { + mCameraPlaneDiff = mHydrax->mRefractionPlane->getParentNode()->getPosition().y-mHydrax->mCamera->getPosition().y+0.05; + mHydrax->mRefractionPlane->getParentNode()->translate(0,-mCameraPlaneDiff,0); + } + else + { + mCameraPlaneDiff = 0; + } + + mHydrax->mCamera->enableCustomNearClipPlane(mHydrax->mRefractionPlane); + } + + void Hydrax::CRefractionListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + mHydrax->mMesh->getEntity()->setVisible(true); + mHydrax->mRefractionPlane->getParentNode()->translate(0,-mHydrax->mPlanesError,0); + + if (mCameraPlaneDiff != 0) + { + mHydrax->mRefractionPlane->getParentNode()->translate(0,mCameraPlaneDiff,0); + } + + mHydrax->mCamera->disableCustomNearClipPlane(); + } + + void Hydrax::CDepthListener::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + mHydrax->mMesh->getEntity()->setVisible(false); + + Ogre::SceneManager::MovableObjectIterator EntityIterator = + mHydrax->mSceneManager->getMovableObjectIterator("Entity"); + Ogre::Entity* CurrentEntity; + unsigned int k; + + mMaterials.empty(); + + while (EntityIterator.hasMoreElements()) + { + CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue()); + + for(k = 0; k < CurrentEntity->getNumSubEntities(); k++) + { + mMaterials.push(CurrentEntity->getSubEntity(k)->getMaterialName()); + + CurrentEntity->getSubEntity(k)->setMaterialName(mHydrax->getMaterialManager()->getMaterial(MaterialManager::MAT_DEPTH)->getName()); + } + + EntityIterator.moveNext(); + } + + mHydrax->mDepthPlane->getParentNode()->translate(0,mHydrax->mPlanesError,0); + + if (mHydrax->mCamera->getPosition().y < mHydrax->mDepthPlane->getParentNode()->getPosition().y) + { + mCameraPlaneDiff = mHydrax->mDepthPlane->getParentNode()->getPosition().y-mHydrax->mCamera->getPosition().y+0.05; + mHydrax->mDepthPlane->getParentNode()->translate(0,-mCameraPlaneDiff,0); + } + else + { + mCameraPlaneDiff = 0; + } + + mHydrax->mCamera->enableCustomNearClipPlane(mHydrax->mDepthPlane); + } + + void Hydrax::CDepthListener::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt) + { + Ogre::SceneManager::MovableObjectIterator EntityIterator = + mHydrax->mSceneManager->getMovableObjectIterator("Entity"); + Ogre::Entity* CurrentEntity; + unsigned int k; + + while (EntityIterator.hasMoreElements()) + { + CurrentEntity = static_cast<Ogre::Entity*>(EntityIterator.peekNextValue()); + + for(k = 0; k < CurrentEntity->getNumSubEntities(); k++) + { + CurrentEntity->getSubEntity(k)->setMaterialName(mMaterials.front()); + + mMaterials.pop(); + } + + EntityIterator.moveNext(); + } + + mHydrax->mMesh->getEntity()->setVisible(true); + + mHydrax->mCamera->disableCustomNearClipPlane(); + + if (mCameraPlaneDiff != 0) + { + mHydrax->mDepthPlane->getParentNode()->translate(0,mCameraPlaneDiff,0); + } + + mHydrax->mDepthPlane->getParentNode()->translate(0,-mHydrax->mPlanesError,0); + } + + void Hydrax::setRttOptions(const RttOptions &RttOptions) + { + mRttOptions = RttOptions; + + if (mCreated) + { + HydraxLOG("Updating Rtt options."); + + Ogre::RenderTarget* mRT_TextureRefraction = mTextureRefraction->getBuffer()->getRenderTarget(); + mRT_TextureRefraction->removeAllListeners(); + mRT_TextureRefraction->removeAllViewports(); + + Ogre::RenderTarget* mRT_TextureReflection = mTextureReflection->getBuffer()->getRenderTarget(); + mRT_TextureReflection->removeAllListeners(); + mRT_TextureReflection->removeAllViewports(); + + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + Ogre::RenderTarget* mRT_TextureDepth = mTextureDepth->getBuffer()->getRenderTarget(); + mRT_TextureDepth->removeAllListeners(); + mRT_TextureDepth->removeAllViewports(); + + Ogre::TextureManager::getSingleton().remove("HydraxDepthMap"); + } + + Ogre::TextureManager::getSingleton().remove("HydraxReflectionMap"); + Ogre::TextureManager::getSingleton().remove("HydraxRefractionMap"); + + _createRttListeners(); + + mMaterialManager->reload(MaterialManager::MAT_WATER); + + HydraxLOG("Rtt options updated."); + } + } + + void Hydrax::setPolygonMode(const int &Tipe) + { + Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(mMesh->getMaterialName()); + + if (Tipe == 0) + { + mat->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_SOLID); + } + else if (Tipe == 1) + { + mat->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); + } + else if (Tipe == 2) + { + mat->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_POINTS); + } + } + + void Hydrax::setShaderMode(const MaterialManager::ShaderMode& ShaderMode) + { + mShaderMode = ShaderMode; + + if (mCreated && mModule) + { + mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode())); + + mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName()); + } + } + + void Hydrax::update(const Ogre::Real &timeSinceLastFrame) + { + if (mCreated && mModule) + { + mModule->update(timeSinceLastFrame); + mDecalsManager->update(); + } + } + + void Hydrax::setComponents(const HydraxComponent &Components) + { + // Create/Delete depth rtt listeners if it's necesary + if (mCreated) + { + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + if (!(Components & HYDRAX_COMPONENT_DEPTH)) + { + _createDepthRttListener(false, true); + } + } + else + { + if (Components & HYDRAX_COMPONENT_DEPTH) + { + _createDepthRttListener(); + } + } + } + + mComponents = Components; + + if (isComponent(HYDRAX_COMPONENT_SMOOTH) || isComponent(HYDRAX_COMPONENT_CAUSTICS)) + { + if (!isComponent(HYDRAX_COMPONENT_DEPTH)) + { + // Delete smooth or caustics components + HydraxComponent s = HYDRAX_COMPONENTS_NONE, + f = HYDRAX_COMPONENTS_NONE; + + if(isComponent(HYDRAX_COMPONENT_SUN)) + { + s = HYDRAX_COMPONENT_SUN; + } + if(isComponent(HYDRAX_COMPONENT_FOAM)) + { + f = HYDRAX_COMPONENT_FOAM; + } + + if(isComponent(HYDRAX_COMPONENT_SMOOTH)) + { + HydraxLOG("Smooth component needs depth component... smooth component desactivated."); + } + if(isComponent(HYDRAX_COMPONENT_CAUSTICS)) + { + HydraxLOG("Caustics component needs depth component... cautics component desactivated."); + } + + mComponents = static_cast<HydraxComponent>(s|f); + } + } + + if (!mCreated || !mModule) + { + return; + } + + mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, mModule->getNormalMode())); + + mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName()); + } + + void Hydrax::setModule(Module::Module* Module) + { + if (mModule) + { + if (mModule->getNormalMode() != Module->getNormalMode()) + { + mMaterialManager->createMaterials(mComponents, MaterialManager::Options(mShaderMode, Module->getNormalMode())); + + mMesh->setMaterialName(mMaterialManager->getMaterial(MaterialManager::MAT_WATER)->getName()); + } + + delete mModule; + } + + mModule = Module; + + if (mCreated) + { + HydraxLOG("Updating water mesh."); + Ogre::String MaterialNameTmp = mMesh->getMaterialName(); + + HydraxLOG("Deleting water mesh."); + delete mMesh; + HydraxLOG("Water mesh deleted."); + + HydraxLOG("Creating water mesh."); + mMesh = new Mesh(this); + mMesh->setOptions(mModule->getMeshOptions()); + mMesh->setMaterialName(MaterialNameTmp); + mMesh->create(mSceneNode); + setPosition(mPosition); + HydraxLOG("Water mesh created"); + + HydraxLOG("Module set."); + } + } + + bool Hydrax::isComponent(const HydraxComponent &Component) + { + if (mComponents & Component) + { + return true; + } + + if (Component == HYDRAX_COMPONENTS_NONE && mComponents == HYDRAX_COMPONENTS_NONE) + { + return true; + } + + if (Component == HYDRAX_COMPONENTS_ALL && mComponents == HYDRAX_COMPONENTS_ALL) + { + return true; + } + + return false; + } + + void Hydrax::saveCfg(const Ogre::String &FileName) + { + FILE *cfgFile = fopen(FileName.c_str(), "w"); + + if (cfgFile) + { + Ogre::String tmpStr = ""; + + // Hydrax version + tmpStr += "#Version\n"; + tmpStr += "HydraxVersion="+ + // Major + Ogre::StringConverter::toString(HYDRAX_VERSION_MAJOR)+"."+ + // Minor + Ogre::StringConverter::toString(HYDRAX_VERSION_MINOR)+"."+ + // Patch + Ogre::StringConverter::toString(HYDRAX_VERSION_PATCH)+"\n\n"; + + /* // Mesh field + tmpStr += "#Mesh\n"; + tmpStr += "MeshSize="+ + // X + Ogre::StringConverter::toString(mMesh->getSize().Width)+"x"+ + // Z + Ogre::StringConverter::toString(mMesh->getSize().Height)+"\n"; + tmpStr += "MeshComplexity="+Ogre::StringConverter::toString(mMesh->getComplexity())+"\n\n"; +*/ + // Components field + tmpStr += "#Components\n"; + tmpStr += "ComponentSun=" +Ogre::StringConverter::toString(isComponent(HYDRAX_COMPONENT_SUN ))+"\n"; + tmpStr += "ComponentFoam=" +Ogre::StringConverter::toString(isComponent(HYDRAX_COMPONENT_FOAM ))+"\n"; + tmpStr += "ComponentDepth=" +Ogre::StringConverter::toString(isComponent(HYDRAX_COMPONENT_DEPTH ))+"\n"; + tmpStr += "ComponentSmooth=" +Ogre::StringConverter::toString(isComponent(HYDRAX_COMPONENT_SMOOTH ))+"\n"; + tmpStr += "ComponentCaustics="+Ogre::StringConverter::toString(isComponent(HYDRAX_COMPONENT_CAUSTICS))+"\n\n"; + + // Rtt quality field + tmpStr += "#Rtt quality\n"; + tmpStr += "RttReflection="+Ogre::StringConverter::toString(static_cast<int>(getRttOptions().ReflectionQuality))+"\n"; + tmpStr += "RttRefraction="+Ogre::StringConverter::toString(static_cast<int>(getRttOptions().RefractionQuality))+"\n"; + tmpStr += "RttDepth=" +Ogre::StringConverter::toString(static_cast<int>(getRttOptions().DepthQuality)) +"\n\n"; + + // Params fields + // Main + tmpStr += "#Main parameters\n"; + tmpStr += "FullReflectionDistance="+Ogre::StringConverter::toString(getFullReflectionDistance())+"\n"; + tmpStr += "GlobalTransparency=" +Ogre::StringConverter::toString(getGlobalTransparency() )+"\n"; + tmpStr += "NormalDistortion=" +Ogre::StringConverter::toString(getNormalDistortion() )+"\n\n"; + // Sun + if (isComponent(HYDRAX_COMPONENT_SUN)) + { + tmpStr += "#Sun parameters\n"; + tmpStr += "Sun_Position=" + + Ogre::StringConverter::toString(getSunPosition().x)+"x"+ + Ogre::StringConverter::toString(getSunPosition().y)+"x"+ + Ogre::StringConverter::toString(getSunPosition().z)+"\n"; + tmpStr += "Sun_Strength="+Ogre::StringConverter::toString(getSunStrength())+"\n"; + tmpStr += "Sun_Area=" +Ogre::StringConverter::toString(getSunArea() )+"\n"; + tmpStr += "Sun_Color=" + + Ogre::StringConverter::toString(getSunColor().x)+"x"+ + Ogre::StringConverter::toString(getSunColor().y)+"x"+ + Ogre::StringConverter::toString(getSunColor().z)+"\n\n"; + } + // Foam + if (isComponent(HYDRAX_COMPONENT_FOAM)) + { + tmpStr += "#Foam parameters\n"; + tmpStr += "Foam_MaxDistance=" +Ogre::StringConverter::toString(getFoamMaxDistance() )+"\n"; + tmpStr += "Foam_Scale=" +Ogre::StringConverter::toString(getFoamScale() )+"\n"; + tmpStr += "Foam_Start=" +Ogre::StringConverter::toString(getFoamStart() )+"\n"; + tmpStr += "Foam_Transparency="+Ogre::StringConverter::toString(getFoamTransparency())+"\n\n"; + } + // Depth + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + tmpStr += "#Depth parameters\n"; + tmpStr += "Depth_Limit=" +Ogre::StringConverter::toString(getDepthLimit())+"\n"; + tmpStr += "Depth_Color=" + + Ogre::StringConverter::toString(getDepthColor().x)+"x"+ + Ogre::StringConverter::toString(getDepthColor().y)+"x"+ + Ogre::StringConverter::toString(getDepthColor().z)+"\n\n"; + } + // Smooth + if (isComponent(HYDRAX_COMPONENT_SMOOTH)) + { + tmpStr += "#Smooth parameters\n"; + tmpStr += "Smooth_Power=" +Ogre::StringConverter::toString(getSmoothPower())+"\n\n"; + } + // Caustics + if (isComponent(HYDRAX_COMPONENT_CAUSTICS)) + { + tmpStr += "#Caustics parameters\n"; + tmpStr += "Caustics_Scale=" +Ogre::StringConverter::toString(getCausticsScale())+"\n"; + tmpStr += "Caustics_Power=" +Ogre::StringConverter::toString(getCausticsPower())+"\n"; + tmpStr += "Caustics_End=" +Ogre::StringConverter::toString(getCausticsEnd()) +"\n\n"; + } + + // Save module config + if (mModule) + { + mModule->saveCfg(tmpStr); + } + + fprintf(cfgFile, "%s", tmpStr.c_str()); + fclose(cfgFile); + + try + { + Ogre::ResourceGroupManager::getSingleton().removeResourceLocation(FileName, HYDRAX_RESOURCE_GROUP); + } + catch(...) + { + } + + Ogre::ResourceGroupManager::getSingleton().addResourceLocation(FileName, "FileSystem", HYDRAX_RESOURCE_GROUP); + } + + HydraxLOG(FileName + " saved."); + } + + void Hydrax::loadCfg(const Ogre::String &FileName) + { + Ogre::ConfigFile CfgFile; + + CfgFile.load(FileName); + + // Check version + if(CfgFile.getSetting("HydraxVersion") != ( + // Major + Ogre::StringConverter::toString(HYDRAX_VERSION_MAJOR)+"."+ + // Minor + Ogre::StringConverter::toString(HYDRAX_VERSION_MINOR)+"."+ + // Patch + Ogre::StringConverter::toString(HYDRAX_VERSION_PATCH))) + { + HydraxLOG("Config file version doesn't correspond with Hydrax version."); + + return; + } + + // Load components + HydraxComponent s = HYDRAX_COMPONENTS_NONE, + f = HYDRAX_COMPONENTS_NONE, + d = HYDRAX_COMPONENTS_NONE, + sm = HYDRAX_COMPONENTS_NONE, + c = HYDRAX_COMPONENTS_NONE; + + if (Ogre::StringConverter::parseBool(CfgFile.getSetting("ComponentSun"))) + { + s = HYDRAX_COMPONENT_SUN; + } + if (Ogre::StringConverter::parseBool(CfgFile.getSetting("ComponentFoam"))) + { + f = HYDRAX_COMPONENT_FOAM; + } + if (Ogre::StringConverter::parseBool(CfgFile.getSetting("ComponentDepth"))) + { + d = HYDRAX_COMPONENT_DEPTH; + } + if (Ogre::StringConverter::parseBool(CfgFile.getSetting("ComponentSmooth"))) + { + sm = HYDRAX_COMPONENT_SMOOTH; + } + if (Ogre::StringConverter::parseBool(CfgFile.getSetting("ComponentCaustics"))) + { + c = HYDRAX_COMPONENT_CAUSTICS; + } + + setComponents(static_cast<HydraxComponent>(s | f | d | sm | c)); + + // Load Rtt options + setRttOptions( + RttOptions( + // Reflection + static_cast<TextureQuality>(Ogre::StringConverter::parseInt(CfgFile.getSetting("RttReflection"))), + // Refraction + static_cast<TextureQuality>(Ogre::StringConverter::parseInt(CfgFile.getSetting("RttRefraction"))), + // Depth + static_cast<TextureQuality>(Ogre::StringConverter::parseInt(CfgFile.getSetting("RttDepth"))))); + + // Load params options + // Main + setFullReflectionDistance(Ogre::StringConverter::parseReal(CfgFile.getSetting("FullReflectionDistance"))); + setGlobalTransparency(Ogre::StringConverter::parseReal(CfgFile.getSetting("GlobalTransparency"))); + setNormalDistortion(Ogre::StringConverter::parseReal(CfgFile.getSetting("NormalDistortion"))); + // Sun + if (isComponent(HYDRAX_COMPONENT_SUN)) + { + setSunPosition( + Ogre::Vector3( + // X + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Position"), "x")[0]), + // Y + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Position"), "x")[1]), + // Z + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Position"), "x")[2]))); + + setSunStrength(Ogre::StringConverter::parseReal(CfgFile.getSetting("Sun_Strength"))); + setSunArea(Ogre::StringConverter::parseReal(CfgFile.getSetting("Sun_Area"))); + + setSunColor( + Ogre::Vector3( + // X + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Color"), "x")[0]), + // Y + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Color"), "x")[1]), + // Z + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Sun_Color"), "x")[2]))); + } + // Foam + if (isComponent(HYDRAX_COMPONENT_FOAM)) + { + setFoamMaxDistance(Ogre::StringConverter::parseReal(CfgFile.getSetting("Foam_MaxDistance"))); + setFoamScale(Ogre::StringConverter::parseReal(CfgFile.getSetting("Foam_Scale"))); + setFoamStart(Ogre::StringConverter::parseReal(CfgFile.getSetting("Foam_Start"))); + setFoamTransparency(Ogre::StringConverter::parseReal(CfgFile.getSetting("Foam_Transparency"))); + } + // Depth + if (isComponent(HYDRAX_COMPONENT_DEPTH)) + { + setDepthLimit(Ogre::StringConverter::parseReal(CfgFile.getSetting("Depth_Limit"))); + + setDepthColor( + Ogre::Vector3( + // X + Ogre::StringConverter::parseReal( + Ogre::StringUtil::split(CfgFile.getSetting("Depth_Color"), "x")[0]), + // Y + Ogre::StringConverter::... [truncated message content] |