[Python-ogre-commit] SF.net SVN: python-ogre: [410] trunk/python-ogre
Brought to you by:
andy_miller,
roman_yakovenko
From: <and...@us...> - 2007-10-05 13:07:51
|
Revision: 410 http://python-ogre.svn.sourceforge.net/python-ogre/?rev=410&view=rev Author: andy_miller Date: 2007-10-05 06:06:34 -0700 (Fri, 05 Oct 2007) Log Message: ----------- Added support for Caelum (Thanks again to Dermont) a cool sky system... Modified Paths: -------------- trunk/python-ogre/PythonOgreConfig_nt.py trunk/python-ogre/PythonOgreConfig_posix.py trunk/python-ogre/SConstruct trunk/python-ogre/setup.py Added Paths: ----------- trunk/python-ogre/ThirdParty/caelum/ trunk/python-ogre/ThirdParty/caelum/Caelum.h trunk/python-ogre/ThirdParty/caelum/CaelumExceptions.h trunk/python-ogre/ThirdParty/caelum/CaelumListener.h trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.cpp trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.h trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h trunk/python-ogre/ThirdParty/caelum/CameraBoundElement.h trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.cpp trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.h trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.cpp trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.h trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp trunk/python-ogre/ThirdParty/caelum/SkyDome.h trunk/python-ogre/ThirdParty/caelum/Starfield.cpp trunk/python-ogre/ThirdParty/caelum/Starfield.h trunk/python-ogre/ThirdParty/caelum/StoredImageElvBasedSkyColourModel.cpp trunk/python-ogre/ThirdParty/caelum/StoredImageElvBasedSkyColourModel.h trunk/python-ogre/ThirdParty/caelum/StoredImageSkyColourModel.cpp trunk/python-ogre/ThirdParty/caelum/StoredImageSkyColourModel.h trunk/python-ogre/ThirdParty/caelum/Sun.cpp trunk/python-ogre/ThirdParty/caelum/Sun.h trunk/python-ogre/ThirdParty/caelum/SunPositionModel.h trunk/python-ogre/ThirdParty/caelum/UniversalClock.cpp trunk/python-ogre/ThirdParty/caelum/UniversalClock.h trunk/python-ogre/code_generators/caelum/ trunk/python-ogre/code_generators/caelum/customization_data.py trunk/python-ogre/code_generators/caelum/generate_code.py trunk/python-ogre/code_generators/caelum/generate_code.py.org trunk/python-ogre/code_generators/caelum/hand_made_wrappers.py trunk/python-ogre/code_generators/caelum/python_caelum.h trunk/python-ogre/code_generators/caelum/python_caelum_aliases.h trunk/python-ogre/code_generators/caelum/python_caelum_sizeof.h trunk/python-ogre/demos/caelum/ trunk/python-ogre/demos/caelum/Demo_Caelum01.py trunk/python-ogre/demos/caelum/SampleFramework.py trunk/python-ogre/demos/caelum/media/ trunk/python-ogre/demos/caelum/media/AltocumulusDetail.png trunk/python-ogre/demos/caelum/media/AltostratusDetail.png trunk/python-ogre/demos/caelum/media/AtmosphereDepth.png trunk/python-ogre/demos/caelum/media/CaelumShaders.cg trunk/python-ogre/demos/caelum/media/CirrostratusDetail.png trunk/python-ogre/demos/caelum/media/CirrusDetail.png trunk/python-ogre/demos/caelum/media/CloudLayer.png trunk/python-ogre/demos/caelum/media/CloudNoise1.png trunk/python-ogre/demos/caelum/media/EarthClearSky.png trunk/python-ogre/demos/caelum/media/EarthClearSky2.png trunk/python-ogre/demos/caelum/media/EarthClearSkyFog.png trunk/python-ogre/demos/caelum/media/LayeredCloud.cg trunk/python-ogre/demos/caelum/media/LayeredClouds.material trunk/python-ogre/demos/caelum/media/SkyLightAbsorption.cg trunk/python-ogre/demos/caelum/media/Starfield.jpg trunk/python-ogre/demos/caelum/media/Terrain.cfg trunk/python-ogre/demos/caelum/media/Terrain.material trunk/python-ogre/demos/caelum/media/noise1.png trunk/python-ogre/demos/caelum/media/noise2.png trunk/python-ogre/demos/caelum/media/noise3.png trunk/python-ogre/demos/caelum/media/noise4.png trunk/python-ogre/demos/caelum/plugins.cfg trunk/python-ogre/demos/caelum/resources.cfg trunk/python-ogre/packages_2.5/ogre/addons/caelum/ trunk/python-ogre/packages_2.5/ogre/addons/caelum/__init__.py Modified: trunk/python-ogre/PythonOgreConfig_nt.py =================================================================== --- trunk/python-ogre/PythonOgreConfig_nt.py 2007-10-05 08:20:21 UTC (rev 409) +++ trunk/python-ogre/PythonOgreConfig_nt.py 2007-10-05 13:06:34 UTC (rev 410) @@ -42,6 +42,8 @@ PATH_ogredshow = os.path.join(PATH_THIRDPARTY,'dshow') PATH_plib = os.path.join(PATH_THIRDPARTY, 'plib') PATH_et = os.path.join(PATH_THIRDPARTY, 'et') +PATH_caelum = os.path.join(PATH_THIRDPARTY, 'caelum') + PATH_ogrevideoffmpeg = os.path.join(PATH_THIRDPARTY,'ffmpeg') PATH_NxOgre= os.path.join(BASE_DIR, 'nxogre/NxOgre') PATH_Bullet= os.path.join(BASE_DIR, 'bullet-2.62') Modified: trunk/python-ogre/PythonOgreConfig_posix.py =================================================================== --- trunk/python-ogre/PythonOgreConfig_posix.py 2007-10-05 08:20:21 UTC (rev 409) +++ trunk/python-ogre/PythonOgreConfig_posix.py 2007-10-05 13:06:34 UTC (rev 410) @@ -49,6 +49,7 @@ PATH_ogredshow = os.path.join(PATH_THIRDPARTY,'dshow') PATH_plib = os.path.join(PATH_THIRDPARTY, 'plib') PATH_et = os.path.join(PATH_THIRDPARTY, 'et') +PATH_caelum = os.path.join(PATH_THIRDPARTY, 'caelum') PATH_ogrevideoffmpeg = os.path.join(PATH_THIRDPARTY,'ffmpeg') PATH_NxOgre= os.path.join(BASE_DIR, 'nxogre/NxOgre') Modified: trunk/python-ogre/SConstruct =================================================================== --- trunk/python-ogre/SConstruct 2007-10-05 08:20:21 UTC (rev 409) +++ trunk/python-ogre/SConstruct 2007-10-05 13:06:34 UTC (rev 410) @@ -91,11 +91,11 @@ possible_projects = ['ogre' , 'ois', 'ogrerefapp', 'ogrenewt', 'cegui', 'ode',\ 'ogreode', 'ogreal', 'quickgui', 'opcode', 'nxogre', 'bullet', 'physx', 'betagui','theora',\ 'ogrevideoffmpeg', 'ogredshow', 'plib', 'ogrebulletc', 'ogrebulletd', - 'ogreforests', 'et', 'navi' ] # , 'raknet' + 'ogreforests', 'et', 'navi', 'caelum' ] # , 'raknet' default_projects = ['ogre' , 'ois', 'ogrerefapp', 'ogrenewt', 'cegui', 'ode',\ 'ogreode', 'ogreal', 'quickgui', 'opcode', 'nxogre', 'bullet', 'physx', 'betagui','theora',\ 'ogrevideoffmpeg', 'ogredshow', 'plib', 'ogrebulletc', 'ogrebulletd', - 'ogreforests', 'et'] # 'navi', + 'ogreforests', 'et', 'caelum' ] # 'navi', # This lets you call scons like: 'scons PROJECTS=ogre,cegui' opts = Options('custom.py') Added: trunk/python-ogre/ThirdParty/caelum/Caelum.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/Caelum.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/Caelum.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,21 @@ +#ifndef CAELUM_H +#define CAELUM_H + +#include "CaelumPrerequisites.h" + +#include "CaelumExceptions.h" +#include "CaelumListener.h" +#include "CaelumSystem.h" +#include "CameraBoundElement.h" +#include "EarthSunPositionModel.h" +#include "GeometryFactory.h" +#include "SimpleSunPositionModel.h" +#include "SkyColourModel.h" +#include "SkyDome.h" +#include "StoredImageSkyColourModel.h" +#include "StoredImageElvBasedSkyColourModel.h" +#include "Sun.h" +#include "SunPositionModel.h" +#include "UniversalClock.h" + +#endif //CAELUM_H Added: trunk/python-ogre/ThirdParty/caelum/CaelumExceptions.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumExceptions.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumExceptions.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,21 @@ +#ifndef CAELUMEXCEPTIONS_H +#define CAELUMEXCEPTIONS_H + +#include "CaelumPrerequisites.h" + +namespace caelum { + +/** Exception class for unsupported features. + * @author Jesús Alonso Abad. + */ +class DllExport UnsupportedException : public Ogre::Exception { + public: + /** Constructor. + */ + UnsupportedException (int number, const Ogre::String &description, const Ogre::String &source, const char *file, long line) + : Ogre::Exception (number, description, source, "UnsupportedException", file, line) { } +}; + +} // namespace caelum + +#endif // CAELUMEXCEPTIONS_H Added: trunk/python-ogre/ThirdParty/caelum/CaelumListener.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumListener.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumListener.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,50 @@ +#ifndef CAELUMLISTENER_H +#define CAELUMLISTENER_H + +#include "CaelumPrerequisites.h" + +namespace caelum { + +// Predefinition of the system for the crossed reference. +class CaelumSystem; + +/** The Caelum listener interface. + Allows to register its subclasses to Caelum so that it receives notifications each frame + before it's started or finished. Useful, for instance, to prototype certain functionality + like passing the sun direction to a shader/material that isn't defined inside Caelum + itself. + @author Jesús Alonso Abad + @version 1.0 + */ +class DllExport CaelumListener { +// Methods -------------------------------------------------------------------- + public: + /** Destructor. + */ + virtual ~CaelumListener () {}; + /** Trigger fired just before Caelum is about to do its work. + @param e The Ogre FrameEvent object, in case it's desired to use this as a + FrameListener as well. + @param caelumSystem A reference to the invoker (the Caelum system) itself in case some + operations on it are wanted to be done. + @return True if it's desired to continue running Caelum. + */ + virtual bool caelumStarted (const Ogre::FrameEvent &e, CaelumSystem *caelumSystem) { + return true; + } + + /** Trigger fired just after Caelum is about to do its work. + @param e The Ogre FrameEvent object, in case it's desired to use this as a + FrameListener as well. + @param caelumSystem A reference to the invoker (the Caelum system) itself in case some + operations on it are wanted to be done. + @return True if it's desired to continue running after Caelum finished. + */ + virtual bool caelumFinished (const Ogre::FrameEvent &e, CaelumSystem *caelumSystem) { + return true; + } +}; + +} // namespace caelum + +#endif //CAELUMLISTENER_H Added: trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1 @@ +#include "CaelumPrecompiled.h" Added: trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumPrecompiled.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1 @@ +#include "Ogre.h" Added: trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,37 @@ +#ifndef CAELUMPREREQUISITES_H +#define CAELUMPREREQUISITES_H + +// Include external headers +#include "Ogre.h" + +// Define the dll export qualifier if compiling for Windows +// // #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 +// // #ifdef CAELUM_LIB +// // #define DllExport __declspec (dllexport) +// // #else +// // #ifdef __MINGW32__ +// // #define DllExport +// // #else +// // #define DllExport __declspec (dllimport) +// // #endif +// // #endif +// // #else + #define DllExport +// // #endif + +// Define the version code +#define CAELUM_VERSION_MAIN 0 +#define CAELUM_VERSION_SEC 2 +#define CAELUM_VERSION_TER 1 +#define CAELUM_VERSION = (CAELUM_VERSION_MAIN << 16) | (CAELUM_VERSION_SEC << 8) | CAELUM_VERSION_TER + +/* Set a global camera distances modifier for the clipping distance. + This threshold will be substracted from the far clipping distance if applicable, else it will be + added to the near clipping distance (ie, if infinite far clipping distance is used). + */ +#define CAMERA_DISTANCE_MODIFIER 0.1 + +// Log macro +#define LOG(msg) Ogre::LogManager::getSingleton().logMessage(msg); + +#endif //CAELUMPREREQUISITES_H Added: trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,292 @@ +#include "CaelumPrecompiled.h" +#include "CaelumSystem.h" + +namespace caelum { + +Ogre::String CaelumSystem::RESOURCE_GROUP_NAME = "Caelum"; + +CaelumSystem::CaelumSystem (Ogre::Root *root, + Ogre::SceneManager *sceneMgr, + bool manageResGroup, + const Ogre::String &resGroupName, + bool createSkyDome, bool createSun, bool createStarfield) { + LOG ("Initialising Caelum system..."); + mOgreRoot = root; + mSceneMgr = sceneMgr; + + mCleanup = false; + + RESOURCE_GROUP_NAME = resGroupName; + + // Create resource group + if (manageResGroup) { + // Search for the resource group + Ogre::StringVector resGroups = Ogre::ResourceGroupManager::getSingleton ().getResourceGroups (); + Ogre::StringVector::iterator it = resGroups.begin (), iend = resGroups.end (); + while (it != iend && *it != resGroupName) + ++it; + + if (it == iend) { + Ogre::ResourceGroupManager::getSingleton ().createResourceGroup (RESOURCE_GROUP_NAME); + mManageResourceGroup = true; + LOG (Ogre::String ("Created Caelum resource group (") + RESOURCE_GROUP_NAME + ")"); + } + else { + mManageResourceGroup = false; + } + } + else { + mManageResourceGroup = false; + } + + // Clock + mUniversalClock = new UniversalClock (); + + // Set-up attributes + mManageFog = false; + + mSkyDome = 0; + mSun = 0; + mStarfield = 0; + LOG ("System attributes set up."); + + // Create basic elements + if (createSkyDome) + this->createSkyDome (); + if (createSun) + this->createSun (); + if (createStarfield) + this->createStarfield (); + + // Auto-register itself as a frame listener + mOgreRoot->addFrameListener (this); + + LOG ("DONE"); +} + +CaelumSystem::~CaelumSystem () { + LOG ("Caelum system destroyed."); +} + +void CaelumSystem::shutdown (const bool cleanup) { + LOG ("Shutting down Caelum system..."); + // Remove itself as a frame listener + mOgreRoot->removeFrameListener (this); + + // Unregister all the caelum listeners + mListeners.clear (); + + // Destroy the elements + destroySkyDome (); + destroySun (); + destroyStarfield (); + + // Destroy the clock + if (mUniversalClock) { + delete mUniversalClock; + mUniversalClock = 0; + } + + // Remove resource group + if (mManageResourceGroup) { + Ogre::ResourceGroupManager::getSingleton ().destroyResourceGroup (RESOURCE_GROUP_NAME); + LOG ("Destroyed Caelum resource group"); + } + + if (cleanup) + delete this; + else + mCleanup = true; +} + +void CaelumSystem::addListener (CaelumListener *listener) { + mListeners.insert (listener); +} + +void CaelumSystem::removeListener (CaelumListener *listener) { + mListeners.erase (listener); +} + +void CaelumSystem::preViewportUpdate (const Ogre::RenderTargetViewportEvent &e) { + Ogre::Camera *cam = e.source->getCamera (); + + if (mSkyDome) { + mSkyDome->notifyCameraChanged (cam); + } + + if (mSun) { + mSun->notifyCameraChanged (cam); + } + + if (mStarfield) { + mStarfield->notifyCameraChanged (cam); + } +} + +UniversalClock *CaelumSystem::getUniversalClock () const { + return mUniversalClock; +} + +bool CaelumSystem::frameStarted (const Ogre::FrameEvent &e) { + // First of all, check if a cleanup has been requested or not, and if so, self-destruction + if (mCleanup) { + delete this; + return true; + } + + if (mUniversalClock->update (e.timeSinceLastFrame)) { + // Call every listener before doing anything + if (!fireStartedEvent (e)) + return false; + + if (mSun) { + mSun->update (mUniversalClock->getCurrentRelativeDayTime ()); + } + + if (mStarfield) { + mStarfield->update (mUniversalClock->getCurrentRelativeDayTime ()); + } + + if (mSkyDome) { + mSkyDome->updateSkyDomeMaterialTime (mSkyColourModel, mUniversalClock->getCurrentRelativeDayTime (), mSun); + + mSkyDome->setSunDirection (mSun->getSunDirection ()); + } + + if (mManageFog) { + // TODO: Fog stuff here!!! + if (mSkyColourModel) { + mSceneMgr->setFog (Ogre::FOG_EXP2, + mSkyColourModel->getFogColour (mUniversalClock->getCurrentRelativeDayTime (), mSun ? mSun->getSunDirection() : Ogre::Vector3::UNIT_Y) * 0.7, + mSkyColourModel->getFogDensity (mUniversalClock->getCurrentRelativeDayTime (), mSun ? mSun->getSunDirection() : Ogre::Vector3::UNIT_Y)); + } + } + + if (mSun) { + if (mSkyColourModel) + mSun->setSunColour (mSkyColourModel->getSunColour (mUniversalClock->getCurrentRelativeDayTime (), mSun->getSunDirection ())); + else + mSun->setSunColour (mSceneMgr->getFogColour ()); + } + + // Call every listener before quiting + if (!fireFinishedEvent (e)) + return false; + } + + return true; +} + +SkyDome *CaelumSystem::createSkyDome () { + if (!mSkyDome) { + mSkyDome = new SkyDome (mSceneMgr); + LOG ("Sky Dome created."); + } + + return mSkyDome; +} + +SkyDome *CaelumSystem::getSkyDome () const { + return mSkyDome; +} + +void CaelumSystem::destroySkyDome () { + if (mSkyDome) { + delete mSkyDome; + mSkyDome = 0; + LOG ("Sky Dome destroyed."); + } +} + +Sun *CaelumSystem::createSun () { + if (!mSun) { + mSun = new Sun (mSceneMgr); + LOG ("Sun created."); + } + + return mSun; +} + +Sun *CaelumSystem::getSun () const { + return mSun; +} + +void CaelumSystem::destroySun () { + if (mSun) { + delete mSun; + mSun = 0; + LOG ("Sun destroyed."); + } +} + +Starfield *CaelumSystem::createStarfield (const Ogre::String &mapName) { + if (!mStarfield) { + mStarfield = new Starfield (mSceneMgr); + LOG ("Starfield created."); + } + + mStarfield->updateMaterial (mapName); + + return mStarfield; +} + +Starfield *CaelumSystem::getStarfield () const { + return mStarfield; +} + +void CaelumSystem::destroyStarfield () { + if (mStarfield) { + delete mStarfield; + mStarfield = 0; + LOG ("Starfield destroyed."); + } +} + +void CaelumSystem::setSkyColourModel (SkyColourModel *model) { + mSkyColourModel = model; + if (mSkyDome) { + Ogre::TextureUnitState *temp = mSkyDome->getTextureUnitState (); + if (temp) + mSkyColourModel->setSkyGradientsTextureUnitState (temp); + } +} + +void CaelumSystem::setManageFog (bool manage) { + mManageFog = manage; +} + +bool CaelumSystem::isFogManaged () const { + return mManageFog; +} + +bool CaelumSystem::fireStartedEvent (const Ogre::FrameEvent &e) { + std::set<CaelumListener *>::iterator it, iend = mListeners.end (); + bool flag = true; + + it = mListeners.begin (); + + while (it != iend && flag) { + flag &= (*it)->caelumStarted (e, this); + + ++it; + } + + return flag; +} + +bool CaelumSystem::fireFinishedEvent (const Ogre::FrameEvent &e) { + std::set<CaelumListener *>::iterator it, iend = mListeners.end (); + bool flag = true; + + it = mListeners.begin (); + + while (it != iend && flag) { + flag &= (*it)->caelumFinished (e, this); + + ++it; + } + + return flag; +} + +} // namespace caelum Added: trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,205 @@ +#ifndef CAELUMSYSTEM_H +#define CAELUMSYSTEM_H + +#include "CaelumPrerequisites.h" + +#include "UniversalClock.h" +#include "CaelumListener.h" +#include "SkyColourModel.h" +#include "SkyDome.h" +#include "Starfield.h" +#include "Sun.h" + +namespace caelum { + +/** Root of the Caelum system. + This class is the root of the Caelum system. + @author Jes\xFAs Alonso Abad + */ +class DllExport CaelumSystem : public Ogre::FrameListener, public Ogre::RenderTargetListener { +// Attributes ----------------------------------------------------------------- + public: + /** Common resource group name. + */ + static Ogre::String RESOURCE_GROUP_NAME; + + private: + /** Root of the Ogre engine. + */ + Ogre::Root *mOgreRoot; + + /** Scene manager. + */ + Ogre::SceneManager *mSceneMgr; + + /** Cleanup requested flag. + */ + bool mCleanup; + + /** Flag to let Caelum manage the creation and destruction of the resource group. + */ + bool mManageResourceGroup; + + /** List of listeners registered. + */ + std::set<CaelumListener *> mListeners; + + /// Reference to the universal clock. + UniversalClock *mUniversalClock; + + /** The sky dome. + */ + SkyDome *mSkyDome; + + /** Reference to the sky colour model in use. + */ + SkyColourModel *mSkyColourModel; + + /** Flag to indicate if Caelum should manage the fog or not. + */ + bool mManageFog; + + /** Reference to the sun. + */ + Sun *mSun; + + /** Reference to the starfield. + */ + Starfield *mStarfield; + +// Methods -------------------------------------------------------------------- + public: + /** Constructor. + Registers itself in the Ogre engine and initialises the system. + @param root The Ogre rool. + @param sceneMgr The Ogre scene manager. + @param manageResGroup Tells the system if the resource group has been created externally (true) or if it's to be managed by the system. + @param resGroupName The resource group name, if it's desired to use an existing one or just a different name. + @param createSkyDome Whether if the sky dome should be created or not. + @param createSun Whether if the sun should be created or not. + @param createStarfield Whether if the starfield should be created or not. + */ + CaelumSystem (Ogre::Root *root, + Ogre::SceneManager *sceneMgr, + bool manageResGroup = true, + const Ogre::String &resGroupName = RESOURCE_GROUP_NAME, + bool createSkyDome = true, bool createSun = true, bool createStarfield = true); + + /** Destructor. + */ + ~CaelumSystem (); + + /** Shuts down the system and detaches itself from the Ogre engine. + @param cleanup True if we want the shutdown to also delete the system. It's dangerous if + it's intended to be rendered another frame later on, and thus turned off by default. + @remarks The model used in this system <b>won't be deleted here</b>. + This is the shutdown function to be called, and not the destructor itself. + */ + void shutdown (const bool cleanup = false); + + /** Registers a listener in the system. + This listener will be called each frame, before and after Caelum does its work. + @param listener The listener to register. + */ + void addListener (CaelumListener *listener); + + /** Unregisters a listener in the system. + @note The listener must be destroyed out of Caelum. + @param listener The listener to be removed. + */ + void removeListener (CaelumListener *listener); + + /** Event trigger called just before rendering a viewport in a render target Caelum is attached to. + Useful to make objects follow every camera that renders a viewport in a certain render target. + @param e The viewport event, containing the viewport (and camera) to be rendered right now. + */ + void preViewportUpdate (const Ogre::RenderTargetViewportEvent &e); + + /** Gets the universal clock. + * @return A reference to the universal clock attached to this system. + */ + UniversalClock *getUniversalClock () const; + + /** Updates the system. + @param e The frame event (contains the elapsed time since the last update). + */ + bool frameStarted (const Ogre::FrameEvent &e); + + /** Creates the sky dome, or returns the existing one if any yet. + */ + SkyDome *createSkyDome (); + + /** Returns the current sky dome. + @return The current sky dome. + */ + SkyDome *getSkyDome () const; + + /** Destroys the sky dome. + @remarks Remember to detach the sky dome from every viewport it is attached to before destroying it! + */ + void destroySkyDome (); + + /** Creates the sun. + @return The sun. + */ + Sun *createSun (); + + /** Gets the current sun. + @return The sun in use. + */ + Sun *getSun () const; + + /** Destroys the sun. + */ + void destroySun (); + + /** Create the starfield. + @note Returns the existing one if there's one already in use. + @note The old texture will be replaced by the passed one. + @param mapName Name of the starfield texture bitmap. + @return The new or current starfield. + */ + Starfield *createStarfield (const Ogre::String &mapName = "Starfield.jpg"); + + /** Gets the starfield. + @return The starfield. + */ + Starfield *getStarfield () const; + + /** Destroys the current starfield. + @remark Remember to detach it from every viewport before deleting! + */ + void destroyStarfield (); + + /** Sets the sky colour model to be used. + @param model The sky colour model. + */ + void setSkyColourModel (SkyColourModel *model); + + /** Enables/disables the Caelum fog management. + @param manage True if you want Caelum to manage the fog for you. + */ + void setManageFog (bool manage); + + /** Tells if Caelum is managing the fog or not. + @return True if Caelum manages the fog. + */ + bool isFogManaged () const; + + private: + /** Fires the start event to all the registered listeners. + @param e The Ogre FrameEvent object passed this frame. + @return True if all the listeners returned true. + */ + bool fireStartedEvent (const Ogre::FrameEvent &e); + + /** Fires the finish event to all the registered listeners. + @param e The Ogre FrameEvent object passed this frame. + @return True if all the listeners returned true. + */ + bool fireFinishedEvent (const Ogre::FrameEvent &e); +}; + +} // namespace caelum + +#endif //CAELUMSYSTEM_H Added: trunk/python-ogre/ThirdParty/caelum/CameraBoundElement.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/CameraBoundElement.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/CameraBoundElement.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,41 @@ +#ifndef CAMERABOUNDELEMENT_H +#define CAMERABOUNDELEMENT_H + +#include "CaelumPrerequisites.h" + +namespace caelum { + +/** A camera-bound element. + This interface serves as the base class for all the elements that must follow cameras, adjust its size, and such operations. + @author Jesús Alonso Abad + */ +class DllExport CameraBoundElement { +// Attributes ----------------------------------------------------------------- + protected: + /** Defines if the element has an automatic "far" radius or not. + */ + bool mAutoRadius; + +// Methods -------------------------------------------------------------------- + public: + /** Destructor. + */ + virtual ~CameraBoundElement () {}; + + /** Notify new camera conditions. + This method notifies that a new camera is about to be used, so this element can follow it or perform other operations. + @param cam The new camera. + */ + virtual void notifyCameraChanged (Ogre::Camera *cam) = 0; + + /** Forces the "far" size of the element to a specific radius. + In other words: The distance considered the furthest locally to this element. + If the parameter is negative or zero, the radius is set automatically. + @param radius The positive radius of the element, or a negative/zero value to let Caelum to resize it. + */ + virtual void setFarRadius (float radius) = 0; +}; + +} // namespace caelum + +#endif // CAMERABOUNDELEMENT_H Added: trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,68 @@ +#include "CaelumPrecompiled.h" +#include "EarthSunPositionModel.h" + +namespace caelum { + +EarthSunPositionModel::EarthSunPositionModel (const Ogre::Radian lat, const Ogre::Real date) { + setLatitude (lat); + setJulianDate (date); +} + +void EarthSunPositionModel::setLatitude (const Ogre::Radian lat) { + mLatitude = lat; +} + +Ogre::Radian EarthSunPositionModel::getLatitude () const { + return mLatitude; +} + +void EarthSunPositionModel::setJulianDate (const Ogre::Real date) { + mJulianDate = date; +} + +Ogre::Real EarthSunPositionModel::getJulianDate () const { + return mJulianDate; +} + +Ogre::Vector3 EarthSunPositionModel::update (const float time) { + Ogre::Radian declination, zenith, azimuth; // Variables + Ogre::Real x, y, sinL, sinDelta, sinTime, cosL, cosDelta, cosTime, twoPi; // Recurrent values (speed up calculations) + + twoPi = 2 * Ogre::Math::PI; + + declination = Ogre::Radian (0.4093 * Ogre::Math::Sin ((twoPi * (mJulianDate * 365 - 81)) / 368.0)); + + sinL = Ogre::Math::Sin (mLatitude); + cosL = Ogre::Math::Cos (mLatitude); + sinDelta = Ogre::Math::Sin (declination); + cosDelta = Ogre::Math::Cos (declination); + sinTime = Ogre::Math::Sin (twoPi * time); + cosTime = Ogre::Math::Cos (twoPi * time); + + x = (cosL * sinDelta - sinL * cosDelta * cosTime); + y = -cosDelta * sinTime; + + zenith = Ogre::Radian (Ogre::Math::PI * 0.5) - Ogre::Math::ASin (sinL * sinDelta + cosL * cosDelta * cosTime); + azimuth = Ogre::Math::ATan (y / x); + + if (x < 0) + azimuth += Ogre::Radian (Ogre::Math::PI); + else if (y < 0 && x > 0) + azimuth += Ogre::Radian (twoPi); + + Ogre::Vector3 dir = Ogre::Vector3::UNIT_Y; + Ogre::Quaternion rotZen, rotAzi; + + rotZen = Ogre::Quaternion (zenith, Ogre::Vector3::UNIT_X); + rotAzi = Ogre::Quaternion (azimuth, Ogre::Vector3::UNIT_Y); + + dir = rotAzi * (rotZen * dir); + + mSunPosition = dir.normalisedCopy () * -1; + + mSunPosition.z *= -1; + + return mSunPosition; +} + +} // namespace caelum Added: trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/EarthSunPositionModel.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,60 @@ +#ifndef EARTHSUNPOSITIONMODEL_H +#define EARTHSUNPOSITIONMODEL_H + +#include "CaelumPrerequisites.h" +#include "SunPositionModel.h" + +namespace caelum { + +/** The simplified Sun position model for the earth. + Based on experimental data and some simplifications (forumlas taken from the paper + "A Practical Analytic Model for Daylight", by Preetham et al.) + @author Jesús Alonso Abad. + */ +class DllExport EarthSunPositionModel : public SunPositionModel { +// Attributes ----------------------------------------------------------------- + protected: + /// Latitude + Ogre::Radian mLatitude; + + /// Julian date + Ogre::Real mJulianDate; + +// Methods -------------------------------------------------------------------- + public: + /** Basic constructor. + * @param lat The latitude (in radians). + * @param date The Julian date in the range [0, 1] (Jan 1st - Dec 31st respectively). + * Values above will be wrapped and below will be treated as positive. + */ + EarthSunPositionModel (const Ogre::Radian lat, const Ogre::Real date); + + /** Changes the current latitude. + * @param lat The new latitude in radians. + */ + void setLatitude (const Ogre::Radian lat); + + /** Gets the current latitude. + * @return The latitude in radians. + */ + Ogre::Radian getLatitude () const; + + /** Changes the Julian date. + * @param date The current Julian date in the range [0, 1] (Jan 1st - Dec 31st Respectively). + * Values above will be wrapped and below will be treated as positive. + */ + void setJulianDate (const Ogre::Real date); + + /** Gets the Julian date. + * @return The Julian date in the range [0, 1]. + */ + Ogre::Real getJulianDate () const; + + /** @copydoc SunPositionModel::update(). + */ + Ogre::Vector3 update (const float time); +}; + +} // namespace caelum + +#endif // EARTHSUNPOSITIONMODEL_H Added: trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,202 @@ +#include "CaelumPrecompiled.h" +#include "GeometryFactory.h" +#include "CaelumSystem.h" + +namespace caelum { + +void GeometryFactory::generateSphericDome (const Ogre::String &name, const unsigned int segments, DomeType type) { + // Return now if already exists + if (Ogre::MeshManager::getSingleton ().resourceExists (name)) + return; + + LOG ("Creating " + name + " sphere mesh resource..."); + + // Use the mesh manager to create the mesh + Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton ().createManual (name, CaelumSystem::RESOURCE_GROUP_NAME); + // Create a submesh + Ogre::SubMesh *sub = msh->createSubMesh (); + + // Create the shared vertex data + Ogre::VertexData *vertexData = new Ogre::VertexData (); + msh->sharedVertexData = vertexData; + + // Define the vertices' format + Ogre::VertexDeclaration *vertexDecl = vertexData->vertexDeclaration; + size_t currOffset = 0; + // Position + vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION); + currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3); + // Normal + vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL); + currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT3); + // Texture coordinates + vertexDecl->addElement (0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0); + currOffset += Ogre::VertexElement::getTypeSize (Ogre::VET_FLOAT2); + + // Allocate the vertex buffer + switch (type) { + case DT_GRADIENTS: + vertexData->vertexCount = segments * (segments - 1) + 2; + break; + case DT_STARFIELD: + vertexData->vertexCount = (segments + 1) * (segments + 1); + break; + }; + Ogre::HardwareVertexBufferSharedPtr vBuf = Ogre::HardwareBufferManager::getSingleton ().createVertexBuffer (vertexDecl->getVertexSize (0), vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); + Ogre::VertexBufferBinding *binding = vertexData->vertexBufferBinding; + binding->setBinding (0, vBuf); + + float *pVertex = static_cast<float *>(vBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD)); + + // Allocate the index buffer + switch (type) { + case DT_GRADIENTS: + sub->indexData->indexCount = 2 * segments * (segments - 1) * 3; + break; + case DT_STARFIELD: + // TODO + sub->indexData->indexCount = 2 * (segments + 1) * segments * 3; + break; + }; + sub->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton ().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_16BIT, sub->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); + Ogre::HardwareIndexBufferSharedPtr iBuf = sub->indexData->indexBuffer; + unsigned short *pIndices = static_cast<unsigned short *>(iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD)); + + // Fill the buffers + switch (type) { + case DT_GRADIENTS: + fillGradientsDomeBuffers (pVertex, pIndices, segments); + break; + case DT_STARFIELD: + fillStarfieldDomeBuffers (pVertex, pIndices, segments); + break; + }; + + // Close the vertex buffer + vBuf->unlock (); + + // Close the index buffer + iBuf->unlock (); + + // Finishing it... + sub->useSharedVertices = true; + msh->_setBounds (Ogre::AxisAlignedBox (-1, -1, -1, 1, 1, 1), false); + msh->_setBoundingSphereRadius (1); + msh->load (); + + LOG ("DONE"); +} + +void GeometryFactory::fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments) { + const float deltaLatitude = Ogre::Math::PI / (float )segments; + const float deltaLongitude = Ogre::Math::PI * 2.0 / (float )segments; + + // Generate the rings + for (int i = 1; i < segments; i++) { + float r0 = Ogre::Math::Sin (Ogre::Radian (i * deltaLatitude)); + float y0 = Ogre::Math::Cos (Ogre::Radian (i * deltaLatitude)); + + for (int j = 0; j < segments; j++) { + float x0 = r0 * Ogre::Math::Sin (Ogre::Radian (j * deltaLongitude)); + float z0 = r0 * Ogre::Math::Cos (Ogre::Radian (j * deltaLongitude)); + + *pVertex++ = x0; + *pVertex++ = y0; + *pVertex++ = z0; + + *pVertex++ = -x0; + *pVertex++ = -y0; + *pVertex++ = -z0; + + *pVertex++ = 0; + *pVertex++ = 1 - y0; + } + } + + // Generate the "north pole" + *pVertex++ = 0; // Position + *pVertex++ = 1; + *pVertex++ = 0; + *pVertex++ = 0; // Normal + *pVertex++ = -1; + *pVertex++ = 0; + *pVertex++ = 0; // UV + *pVertex++ = 0; + + // Generate the "south pole" + *pVertex++ = 0; // Position + *pVertex++ = -1; + *pVertex++ = 0; + *pVertex++ = 0; // Normal + *pVertex++ = 1; + *pVertex++ = 0; + *pVertex++ = 0; // UV + *pVertex++ = 2; + + // Generate the mid segments + for (int i = 0; i < segments - 2; i++) { + for (int j = 0; j < segments; j++) { + *pIndices++ = segments * i + j; + *pIndices++ = segments * i + (j + 1) % segments; + *pIndices++ = segments * (i + 1) + (j + 1) % segments; + *pIndices++ = segments * i + j; + *pIndices++ = segments * (i + 1) + (j + 1) % segments; + *pIndices++ = segments * (i + 1) + j; + } + } + + // Generate the upper cap + for (int i = 0; i < segments; i++) { + *pIndices++ = segments * (segments - 1); + *pIndices++ = (i + 1) % segments; + *pIndices++ = i; + } + + // Generate the lower cap + for (int i = 0; i < segments; i++) { + *pIndices++ = segments * (segments - 1) + 1; + *pIndices++ = segments * (segments - 2) + i; + *pIndices++ = segments * (segments - 2) + (i + 1) % segments; + } +} + +void GeometryFactory::fillStarfieldDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments) { + const float deltaLatitude = Ogre::Math::PI / (float )segments; + const float deltaLongitude = Ogre::Math::PI * 2.0 / (float )segments; + + // Generate the rings + for (int i = 0; i <= segments; i++) { + float r0 = Ogre::Math::Sin (Ogre::Radian (i * deltaLatitude)); + float y0 = Ogre::Math::Cos (Ogre::Radian (i * deltaLatitude)); + + for (int j = 0; j <= segments; j++) { + float x0 = r0 * Ogre::Math::Sin (Ogre::Radian (j * deltaLongitude)); + float z0 = r0 * Ogre::Math::Cos (Ogre::Radian (j * deltaLongitude)); + + *pVertex++ = x0; + *pVertex++ = y0; + *pVertex++ = z0; + + *pVertex++ = -x0; + *pVertex++ = -y0; + *pVertex++ = -z0; + + *pVertex++ = (float )j / (float )segments; + *pVertex++ = 1 - (y0 * 0.5 + 0.5); + } + } + + // Generate the mid segments + for (int i = 0; i <= segments; i++) { + for (int j = 0; j < segments; j++) { + *pIndices++ = segments * i + j; + *pIndices++ = segments * i + (j + 1) % segments; + *pIndices++ = segments * (i + 1) + (j + 1) % segments; + *pIndices++ = segments * i + j; + *pIndices++ = segments * (i + 1) + (j + 1) % segments; + *pIndices++ = segments * (i + 1) + j; + } + } +} + +} // namespace caelum Added: trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,47 @@ +#ifndef GEOMETRYFACTORY_H +#define GEOMETRYFACTORY_H + +#include "CaelumPrerequisites.h" + +namespace caelum { + +/** A constructor for a number of caelum geometric objects. + @author Jes\xFAs Alonso Abad. + @version 0.1 + */ +class DllExport GeometryFactory { +// Types and enums ------------------------------------------------------------ + public: + /** Enumeration of types of sky domes. + */ + enum DomeType {DT_GRADIENTS, DT_STARFIELD}; + +// Methods -------------------------------------------------------------------- + public: + /** Creates a longitude-latitude sky dome. + @note Does nothing if the sphere already exists. + @param name The name of the mesh to be created. + @param segments The number of sphere segments. + @param type The type of sky dome to create. + */ + static void generateSphericDome (const Ogre::String &name, const unsigned int segments, DomeType type = DT_GRADIENTS); + + private: + /** Fills the vertex and index buffers for a sky gradients type dome. + @param pVertex Pointer to the vertex buffer. + @param pIndices Pointer to the index buffer. + @param segments Subdivision detail. + */ + static void fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments); + + /** Fills the vertex and index buffers for a stardield type dome. + @param pVertex Pointer to the vertex buffer. + @param pIndices Pointer to the index buffer. + @param segments Subdivision detail. + */ + static void fillStarfieldDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments); +}; + +} // namespace caelum + +#endif //GEOMETRYFACTORY_H Added: trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,32 @@ +#include "CaelumPrecompiled.h" +#include "SimpleSunPositionModel.h" + +namespace caelum { + +SimpleSunPositionModel::SimpleSunPositionModel (Ogre::Degree inc) { + setInclination (inc); +} + +void SimpleSunPositionModel::setInclination (Ogre::Degree inc) { + mInclination = inc; +} + +Ogre::Degree SimpleSunPositionModel::getInclination () const { + return mInclination; +} + +Ogre::Vector3 SimpleSunPositionModel::update (const float time) { + // Get the inclinated axis + Ogre::Vector3 axis = Ogre::Vector3::UNIT_Z; + axis = Ogre::Quaternion (mInclination, Ogre::Vector3::UNIT_X) * axis; + + // Get the inclinated light direction, according to the day time + Ogre::Vector3 dir = Ogre::Vector3::UNIT_Y; + dir = Ogre::Quaternion (Ogre::Radian (time * 2 * Ogre::Math::PI), axis) * dir; + + mSunPosition = dir.normalisedCopy () * -1; + + return mSunPosition * -1; +} + +} // namespace caelum Added: trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/SimpleSunPositionModel.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,44 @@ +#ifndef SIMPLESUNPOSITIONMODEL_H +#define SIMPLESUNPOSITIONMODEL_H + +#include "CaelumPrerequisites.h" +#include "SunPositionModel.h" + +namespace caelum { + +/** A simple circular sun position model. + It just creates an inclinated circular orbit. + @author Jesús Alonso Abad. + */ +class DllExport SimpleSunPositionModel : public SunPositionModel { +// Attributes ----------------------------------------------------------------- + protected: + /** The sun trajectory inclination. This is similar to the earth's rotation axis inclination. + */ + Ogre::Degree mInclination; + +// Methods -------------------------------------------------------------------- + public: + /** Basic constructor. + @param inc The orbit inclination. + */ + SimpleSunPositionModel (Ogre::Degree inc); + + /** Changes the orbit inclination. + @param inc The inclination in degrees. + */ + void setInclination (Ogre::Degree inc); + + /** Gets the orbit inclination. + @return The orbit inclination in degrees. + */ + Ogre::Degree getInclination () const; + + /** @copydoc SunPositionModel::update(). + */ + Ogre::Vector3 update (const float time); +}; + +} // namespace caelum + +#endif // SIMPLESUNPOSITIONMODEL_H Added: trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,76 @@ +#ifndef SKYCOLOURMODEL_H +#define SKYCOLOURMODEL_H + +#include "CaelumPrerequisites.h" + +namespace caelum { + +/** Sky colour model interface. + @author Jes\xFAs Alonso Abad + @version 0.1 + */ +class DllExport SkyColourModel { +// Attributes ----------------------------------------------------------------- + protected: + /** A reference to the sky gradients texture unit state. + */ + Ogre::TextureUnitState *mSkyGradientsTextureUnitState; + + /** The sky gradients image (for lookups). + */ + Ogre::Image *mSkyGradientsImage; + +// Methods -------------------------------------------------------------------- + public: + /** Constructor method. + */ + SkyColourModel () { + mSkyGradientsTextureUnitState = 0; + mSkyGradientsImage = 0; + } + + /** Destructor. + */ + virtual ~SkyColourModel () {} + + /** Sets the sky gradients texture unit in use. + @param tus The TextureUnitState to be modified. + */ + void setSkyGradientsTextureUnitState (Ogre::TextureUnitState *tus) { + mSkyGradientsTextureUnitState = tus; + } + + /** Gets the fog colour for a certain daytime. + @param time The current time. + @param sunDir The sun direction. + @return The fog colour. + */ + virtual Ogre::ColourValue getFogColour (float time, const Ogre::Vector3 &sunDir) = 0; + + /** Gets the fog density for a certain daytime. + @param time The current time. + @param sunDir The sun direction. + @return The fog density. + */ + virtual float getFogDensity (float time, const Ogre::Vector3 &sunDir) = 0; + + /** Gets the sun colour for a certain daytime. + @param time The current time. + @param sunDir The sun direction. + @return The sun colour. + */ + virtual Ogre::ColourValue getSunColour (float time, const Ogre::Vector3 &sunDir) = 0; + + /** Updates the sky colour material, according to various factors. + @param fpp The material fragment program parameters (null if it's not supported) + @param vpp The material vertex program parameters (null if it's not supported) + @param time The local daytime, ranging [0, 1] + @param sunDir The sun light direction. + @return True if everything went fine. + */ + virtual bool updateMaterial (Ogre::GpuProgramParametersSharedPtr fpp, Ogre::GpuProgramParametersSharedPtr vpp, float time, const Ogre::Vector3 &sunDir) = 0; +}; + +} // namespace caelum + +#endif //SKYCOLOURMODEL_H Added: trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,209 @@ +#include "CaelumPrecompiled.h" +#include "SkyDome.h" +#include "CaelumSystem.h" +#include "GeometryFactory.h" +#include "CaelumExceptions.h" + +namespace caelum { + +const Ogre::String SkyDome::mSphericDomeResourceName = "CaelumSphericDome"; +const Ogre::String SkyDome::SKY_DOME_MATERIAL_NAME = "CaelumSkyDomeMaterial"; + +SkyDome::SkyDome (Ogre::SceneManager *sceneMgr) { + mAutoRadius = true; + + createSkyDomeMaterial (); + + GeometryFactory::generateSphericDome (mSphericDomeResourceName, 32); + Ogre::Entity *ent = sceneMgr->createEntity ("Dome", mSphericDomeResourceName); + ent->setMaterialName (SKY_DOME_MATERIAL_NAME); + ent->setRenderQueueGroup (Ogre::RENDER_QUEUE_SKIES_EARLY + 2); + ent->setCastShadows (false); + + mNode = sceneMgr->getRootSceneNode ()->createChildSceneNode (); + mNode->attachObject (ent); +} + +SkyDome::~SkyDome () { + if (mNode) { + // Detach and destroy attached entity. + Ogre::Entity *ent = static_cast<Ogre::Entity *>(mNode->detachObject ("Dome")); + ent->_getManager ()->destroyEntity (ent); + + // Destroy the node + static_cast<Ogre::SceneNode *>(mNode->getParent ())->removeAndDestroyChild (mNode->getName ()); + mNode = 0; + } + + destroySkyDomeMaterial (); +} + +void SkyDome::notifyCameraChanged (Ogre::Camera *cam) { + mNode->setPosition (cam->getRealPosition ()); + if (mAutoRadius) { + if (cam->getFarClipDistance () > 0) + mNode->setScale (Ogre::Vector3::UNIT_SCALE * (cam->getFarClipDistance () - CAMERA_DISTANCE_MODIFIER)); + else + mNode->setScale (Ogre::Vector3::UNIT_SCALE * (cam->getNearClipDistance () + CAMERA_DISTANCE_MODIFIER)); + } +} + +void SkyDome::setFarRadius (float radius) { + if (radius > 0) { + mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius); + mAutoRadius = false; + } + else { + mAutoRadius = true; + } +} + +void SkyDome::setSunDirection (Ogre::Vector3 dir) { + if (!mSkyDomeMaterial.isNull ()) { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + mSkyDomeMaterial->getTechnique (0)->getPass (0)->getVertexProgramParameters ()->setNamedConstant ("sunDirection", dir); + } + } +} + +void SkyDome::setLightAbsorption (float absorption) const { + if (absorption > 1) + absorption = 1; + else if (absorption < 0) + absorption = 0; + + if (!mSkyDomeMaterial.isNull ()) { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + mSkyDomeMaterial->getTechnique (0)->getPass (0)->getVertexProgramParameters ()->setNamedConstant ("lightAbsorption", absorption); + } + } +} + +void SkyDome::setLightScattering (float scattering) const { + if (scattering <= 0) + scattering = 0.00001; + + if (!mSkyDomeMaterial.isNull ()) { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + mSkyDomeMaterial->getTechnique (0)->getPass (0)->getFragmentProgramParameters ()->setNamedConstant ("lightInvScattering", 1.0f / scattering); + } + } +} + +void SkyDome::setAtmosphereHeight (float height) const { + if (height <= 0) + height = 0.00001; + else if (height > 1) + height = 1; + + if (!mSkyDomeMaterial.isNull ()) { + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + mSkyDomeMaterial->getTechnique (0)->getPass (0)->getFragmentProgramParameters ()->setNamedConstant ("atmosphereInvHeight", 1.0f / height); + } + } +} + +void SkyDome::updateSkyDomeMaterialTime (SkyColourModel *skyColourModel, float time, Sun *sun) { + skyColourModel->updateMaterial (mSkyDomeMaterial->getTechnique (0)->getPass (0)->getFragmentProgramParameters (), + mSkyDomeMaterial->getTechnique (0)->getPass (0)->getVertexProgramParameters (), + time, + sun ? sun->getSunDirection () : Ogre::Vector3::UNIT_Y); +} + +Ogre::TextureUnitState *SkyDome::getTextureUnitState () { + if (mSkyDomeMaterial.isNull ()) + return 0; + + return mSkyDomeMaterial->getTechnique (0)->getPass (0)->getTextureUnitState (0); +} + +void SkyDome::createSkyDomeMaterial () { + Ogre::MaterialPtr mat; + + // Check support + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_FRAGMENT_PROGRAM)) { + // TODO: Check if the profiles used are supported + } + else { + throw new UnsupportedException (0, "The card doesn't support the sky dome material. Fragment programs are used.", "SkyDome", "SkyDome.cpp", -1); + } + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + // TODO: Check if the profiles used are supported + } + else { + throw new UnsupportedException (0, "The card doesn't support the sky dome material. Vertex programs are used.", "SkyDome", "SkyDome.cpp", -1); + } + + LOG ("Generating sky dome material..."); + if (!Ogre::MaterialManager::getSingleton ().resourceExists (SKY_DOME_MATERIAL_NAME)) { + LOG ("\tMaterial not found; creating..."); + mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton ().create (SKY_DOME_MATERIAL_NAME, CaelumSystem::RESOURCE_GROUP_NAME)); + mat->setReceiveShadows (false); + LOG ("\t\tMaterial [OK]"); + Ogre::Pass *pass = mat->getTechnique (0)->getPass (0); + pass->setSceneBlending (Ogre::SBT_TRANSPARENT_ALPHA); + pass->setDepthCheckEnabled (false); + pass->setDepthWriteEnabled (false); + pass->setLightingEnabled (false); + pass->setFog (true); + // Bind the sky light absorption shader if capable to + // TODO + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_FRAGMENT_PROGRAM)) { + Ogre::HighLevelGpuProgramPtr fp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram ("SkyDomeFP", CaelumSystem::RESOURCE_GROUP_NAME, "cg", Ogre::GPT_FRAGMENT_PROGRAM); + fp->setSourceFile ("CaelumShaders.cg"); + fp->setParameter ("entry_point", "SkyDome_fp"); + fp->setParameter ("profiles", "ps_2_0 arbfp1"); + pass->setFragmentProgram ("SkyDomeFP"); + Ogre::GpuProgramParametersSharedPtr parameters = pass->getFragmentProgramParameters(); + parameters->setNamedConstant ("offset", 0.0f); + parameters->setNamedAutoConstant ("hazeColour", Ogre::GpuProgramParameters::ACT_FOG_COLOUR); + } + if (Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_VERTEX_PROGRAM)) { + Ogre::HighLevelGpuProgramPtr vp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram ("SkyDomeVP", CaelumSystem::RESOURCE_GROUP_NAME, "cg", Ogre::GPT_VERTEX_PROGRAM); + vp->setSourceFile ("CaelumShaders.cg"); + vp->setParameter ("entry_point", "SkyDome_vp"); + vp->setParameter ("profiles", "vs_2_0 arbvp1"); + pass->setVertexProgram ("SkyDomeVP"); + Ogre::GpuProgramParametersSharedPtr parameters = pass->getVertexProgramParameters(); + parameters->setNamedAutoConstant ("worldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX); + parameters->setNamedConstant ("sunDirection", Ogre::Vector3 (1, 0, 0)); + } + LOG ("\t\tPass [OK]"); + Ogre::TextureUnitState *tus = pass->createTextureUnitState (); + tus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_WRAP, Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_CLAMP); + LOG ("\t\tTextureUnit - Sky gradient [OK]"); + tus = pass->createTextureUnitState (); + tus->setTextureName ("AtmosphereDepth.png", Ogre::TEX_TYPE_1D); + tus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_WRAP, Ogre::TextureUnitState::TAM_WRAP); + LOG ("\t\tTextureUnit - Atmosphere depth [OK]"); + mat->load (); + LOG ("\tDONE"); + } + else { + mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton ().getByName (SKY_DOME_MATERIAL_NAME)); + } + LOG ("DONE"); + + mSkyDomeMaterial = mat; +} + +void SkyDome::destroySkyDomeMaterial () { + LOG ("Removing sky dome material..."); + if ((Ogre::HighLevelGpuProgramManager::getSingletonPtr()->resourceExists("SkyLightAbsorptionFP"))) { + LOG ("Removing sky dome SkyLightAbsorptionFP..."); + Ogre::HighLevelGpuProgramManager::getSingletonPtr()->remove("SkyLightAbsorptionFP"); + } + + if ((Ogre::HighLevelGpuProgramManager::getSingletonPtr()->resourceExists("SkyLightAbsorptionVP"))) { + LOG ("Removing sky dome SkyLightAbsorptionVP..."); + Ogre::HighLevelGpuProgramManager::getSingletonPtr()->remove("SkyLightAbsorptionVP"); + } + + if (!Ogre::MaterialManager::getSingleton ().resourceExists (SKY_DOME_MATERIAL_NAME)) { + Ogre::MaterialManager::getSingleton ().remove (SKY_DOME_MATERIAL_NAME); + } + mSkyDomeMaterial.setNull (); + LOG ("DONE"); +} + +} // namespace caelum Added: trunk/python-ogre/ThirdParty/caelum/SkyDome.h =================================================================== --- trunk/python-ogre/ThirdParty/caelum/SkyDome.h (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/SkyDome.h 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,97 @@ +#ifndef SKYDOME_H +#define SKYDOME_H + +#include "CaelumPrerequisites.h" +#include "CameraBoundElement.h" +#include "SkyColourModel.h" +#include "Sun.h" + +namespace caelum { + +/** A sky dome element. + @author Jes\xFAs Alonso Abad + */ +class DllExport SkyDome : public CameraBoundElement { +// Attributes ----------------------------------------------------------------- + protected: + /** Control scene node. + */ + Ogre::SceneNode *mNode; + + /** Name of the spheric dome resource. + */ + static const Ogre::String mSphericDomeResourceName; + + /** Name of the dome material. + */ + static const Ogre::String SKY_DOME_MATERIAL_NAME; + + /** Reference to the sky dome material. + */ + Ogre::MaterialPtr mSkyDomeMaterial; + +// Methods -------------------------------------------------------------------- + public: + /** Constructor (DO NOT USE! Use CaelumSystem::createSkyDome instead). + @param sceneMgr The scene manager where this sky dome will be created. + */ + SkyDome (Ogre::SceneManager *sceneMgr); + + /** Destructor (DO NOT USE! Use CaelumSystem::destroySkyDome instead). + */ + virtual ~SkyDome (); + + /** @copydoc CameraBoundElement::notifyCameraChanged(). + */ + void notifyCameraChanged (Ogre::Camera *cam); + + /** @copydoc CameraBoundElement::setFarRadius(). + */ + void setFarRadius (float radius); + + /** Sets the sun direction. + @param dir The sun light direction. + */ + void setSunDirection (Ogre::Vector3 dir); + + /** Sets the new light absorption factor. + @param absorption The light absorption factor; a number in the range [0, 1], the lower, the less light the atmosphere will absorb. + */ + void setLightAbsorption (float absorption) const; + + /** Sets the light scattering factor. + @param scattering The light scattering factor; a number major than zero. + */ + void setLightScattering (float scattering) const; + + /** Sets the atmosphere height factor. + @param height The atmosphere height factor; a number in the range (0, 1]. + */ + void setAtmosphereHeight (float height) const; + + /** Updates the sky dome material to match the local time. + @param skyColourModel The sky colour model in use. + @param time The local time. + @param sun The sun. + */ + void updateSkyDomeMaterialTime (SkyColourModel *skyColourModel, float time, Sun *sun); + + /** Returns the sky dome texture unit state. + @return The texture unit state of the sky dome material. + */ + Ogre::TextureUnitState *getTextureUnitState (); + + private: + /** Internal method to create the sky dome material. + * @throws UnsupportedException if the material isn't supported. + */ + void createSkyDomeMaterial (); + + /** Internal method to destroy the sky dome material. + */ + void destroySkyDomeMaterial (); +}; + +} // namespace caelum + +#endif //SKYDOME_H Added: trunk/python-ogre/ThirdParty/caelum/Starfield.cpp =================================================================== --- trunk/python-ogre/ThirdParty/caelum/Starfield.cpp (rev 0) +++ trunk/python-ogre/ThirdParty/caelum/Starfield.cpp 2007-10-05 13:06:34 UTC (rev 410) @@ -0,0 +1,116 @@ +#include "CaelumPrecompiled.h" +#include "Starfield.h" +#include "CaelumSystem.h" +#include "GeometryFactory.h" + +namespace caelum { + +const Ogre::String Starfield::mStarfieldDomeResourceName = "CaelumStarfieldDome"; +const Ogre::String Starfield::STARFIELD_MATERIAL_NAME = "CaelumStarfieldMaterial"; + +Starfield::Starfield (Ogre::SceneManager *sceneMgr) { + mAutoRadius = true; + mInclination = Ogre::Degree (0); + + createStarfieldMaterial (); + + GeometryFactory::generateSphericDome (mStarfieldDomeResourceName, 32, GeometryFactory::DT_STARFIELD); + Ogre::Entity *ent = sceneMgr->createEntity ("StarfieldDome", mStarfieldDomeResourceName); + ent->setMaterialName (STARFIELD_MATERIAL_NAME); + ent->setRenderQueueGroup (Ogre::RENDER... [truncated message content] |