[Python-ogre-commit] SF.net SVN: python-ogre: [415] trunk/python-ogre
Brought to you by:
andy_miller,
roman_yakovenko
|
From: <and...@us...> - 2007-10-11 13:13:32
|
Revision: 415
http://python-ogre.svn.sourceforge.net/python-ogre/?rev=415&view=rev
Author: andy_miller
Date: 2007-10-11 06:13:35 -0700 (Thu, 11 Oct 2007)
Log Message:
-----------
Updated Caelum
Modified Paths:
--------------
trunk/python-ogre/ThirdParty/caelum/Caelum.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/GeometryFactory.cpp
trunk/python-ogre/ThirdParty/caelum/GeometryFactory.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/Sun.cpp
trunk/python-ogre/ThirdParty/caelum/Sun.h
trunk/python-ogre/code_generators/caelum/generate_code.py
trunk/python-ogre/code_generators/caelum/hand_made_wrappers.py
Added Paths:
-----------
trunk/python-ogre/ThirdParty/caelum/LayeredClouds.cpp
trunk/python-ogre/ThirdParty/caelum/LayeredClouds.h
trunk/python-ogre/ThirdParty/caelum/SkyColourModel.cpp
Removed Paths:
-------------
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
Modified: trunk/python-ogre/ThirdParty/caelum/Caelum.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/Caelum.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/Caelum.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -12,10 +12,9 @@
#include "SimpleSunPositionModel.h"
#include "SkyColourModel.h"
#include "SkyDome.h"
-#include "StoredImageSkyColourModel.h"
-#include "StoredImageElvBasedSkyColourModel.h"
#include "Sun.h"
#include "SunPositionModel.h"
+#include "LayeredClouds.h"
#include "UniversalClock.h"
#endif //CAELUM_H
Modified: trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/CaelumPrerequisites.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -4,20 +4,7 @@
// 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 DllExport
// Define the version code
#define CAELUM_VERSION_MAIN 0
@@ -25,12 +12,27 @@
#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
+namespace caelum {
+ /// Resource group name for caelum resources.
+ extern DllExport Ogre::String RESOURCE_GROUP_NAME;
+ /* 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).
+ */
+ const float CAMERA_DISTANCE_MODIFIER = 0;
+
+ // Render grounp for caelum stuff
+ // It's best to have them all together
+ enum CaelumRenderQueueGroupId
+ {
+ CAELUM_RENDER_QUEUE_STARFIELD = Ogre::RENDER_QUEUE_SKIES_EARLY + 0,
+ CAELUM_RENDER_QUEUE_SKYDOME = Ogre::RENDER_QUEUE_SKIES_EARLY + 1,
+ CAELUM_RENDER_QUEUE_SUN = Ogre::RENDER_QUEUE_SKIES_EARLY + 2,
+ CAELUM_RENDER_QUEUE_CLOUDS = Ogre::RENDER_QUEUE_SKIES_EARLY + 3,
+ };
+}
+
// Log macro
#define LOG(msg) Ogre::LogManager::getSingleton().logMessage(msg);
Modified: trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/CaelumSystem.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -3,19 +3,28 @@
namespace caelum {
-Ogre::String CaelumSystem::RESOURCE_GROUP_NAME = "Caelum";
+// Default resource group name is Caelum
+Ogre::String RESOURCE_GROUP_NAME = "Caelum";
-CaelumSystem::CaelumSystem (Ogre::Root *root,
- Ogre::SceneManager *sceneMgr,
- bool manageResGroup,
- const Ogre::String &resGroupName,
- bool createSkyDome, bool createSun, bool createStarfield) {
+CaelumSystem::CaelumSystem
+(
+ Ogre::Root *root,
+ Ogre::SceneManager *sceneMgr,
+ bool createSkyColourModel,
+ bool createSkyDome,
+ bool createSun,
+ bool createStarfield,
+ bool createClouds,
+ bool manageResGroup,
+ const Ogre::String &resGroupName
+):
+ mCleanup(false)
+{
LOG ("Initialising Caelum system...");
mOgreRoot = root;
mSceneMgr = sceneMgr;
mCleanup = false;
-
RESOURCE_GROUP_NAME = resGroupName;
// Create resource group
@@ -23,19 +32,18 @@
// 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)
+ 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 {
+ } else {
mManageResourceGroup = false;
}
- }
- else {
+ } else {
mManageResourceGroup = false;
}
@@ -45,18 +53,26 @@
// Set-up attributes
mManageFog = false;
- mSkyDome = 0;
- mSun = 0;
- mStarfield = 0;
LOG ("System attributes set up.");
+ assert(getSun() == 0);
+ assert(getClouds() == 0);
// Create basic elements
- if (createSkyDome)
- this->createSkyDome ();
- if (createSun)
- this->createSun ();
- if (createStarfield)
- this->createStarfield ();
+ if (createSkyColourModel) {
+ this->setSkyColourModel (new SkyColourModel ());
+ }
+ if (createSkyDome) {
+ this->setSkyDome (new SkyDome (mSceneMgr));
+ }
+ if (createSun) {
+ this->setSun (new Sun (mSceneMgr));
+ }
+ if (createClouds) {
+ this->setClouds (new LayeredClouds (mSceneMgr));
+ }
+ if (createStarfield) {
+ this->setStarfield (new Starfield (mSceneMgr));
+ }
// Auto-register itself as a frame listener
mOgreRoot->addFrameListener (this);
@@ -77,9 +93,10 @@
mListeners.clear ();
// Destroy the elements
- destroySkyDome ();
- destroySun ();
- destroyStarfield ();
+ setSkyDome (0);
+ setSun (0);
+ setStarfield (0);
+ setClouds (0);
// Destroy the clock
if (mUniversalClock) {
@@ -93,10 +110,11 @@
LOG ("Destroyed Caelum resource group");
}
- if (cleanup)
+ if (cleanup) {
delete this;
- else
+ } else {
mCleanup = true;
+ }
}
void CaelumSystem::addListener (CaelumListener *listener) {
@@ -110,17 +128,21 @@
void CaelumSystem::preViewportUpdate (const Ogre::RenderTargetViewportEvent &e) {
Ogre::Camera *cam = e.source->getCamera ();
- if (mSkyDome) {
- mSkyDome->notifyCameraChanged (cam);
+ if (getSkyDome ()) {
+ getSkyDome ()->notifyCameraChanged (cam);
}
- if (mSun) {
- mSun->notifyCameraChanged (cam);
+ if (getSun ()) {
+ getSun ()->notifyCameraChanged (cam);
}
- if (mStarfield) {
- mStarfield->notifyCameraChanged (cam);
+ if (getStarfield ()) {
+ getStarfield ()->notifyCameraChanged (cam);
}
+
+ if (getClouds ()) {
+ getClouds ()->notifyCameraChanged (cam);
+ }
}
UniversalClock *CaelumSystem::getUniversalClock () const {
@@ -139,118 +161,63 @@
if (!fireStartedEvent (e))
return false;
- if (mSun) {
- mSun->update (mUniversalClock->getCurrentRelativeDayTime ());
+ // Get relative time of the day.
+ float relDayTime = mUniversalClock->getCurrentRelativeDayTime ();
+
+ // Get the sun's direction.
+ Ogre::Vector3 sunDir;
+ if (getSun ()) {
+ sunDir = getSun ()->getSunDirection();
+ } else {
+ sunDir = Ogre::Vector3::UNIT_Y;
+ }
+
+ if (getSun ()) {
+ getSun ()->update (relDayTime);
}
- if (mStarfield) {
- mStarfield->update (mUniversalClock->getCurrentRelativeDayTime ());
+ if (getStarfield ()) {
+ getStarfield ()->update (relDayTime);
}
- if (mSkyDome) {
- mSkyDome->updateSkyDomeMaterialTime (mSkyColourModel, mUniversalClock->getCurrentRelativeDayTime (), mSun);
-
- mSkyDome->setSunDirection (mSun->getSunDirection ());
+ if (getSkyDome ()) {
+ getSkyDome ()->setSunDirection (sunDir);
}
if (mManageFog) {
// TODO: Fog stuff here!!!
- if (mSkyColourModel) {
+ if (getSkyColourModel ()) {
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));
+ mSkyColourModel->getFogColour (relDayTime, sunDir) * 0.7,
+ mSkyColourModel->getFogDensity (relDayTime, sunDir));
}
}
- if (mSun) {
- if (mSkyColourModel)
- mSun->setSunColour (mSkyColourModel->getSunColour (mUniversalClock->getCurrentRelativeDayTime (), mSun->getSunDirection ()));
- else
- mSun->setSunColour (mSceneMgr->getFogColour ());
+ // Set sun colours.
+ if (getSun () && getSkyColourModel ()) {
+ mSun->setSunSphereColour (getSkyColourModel ()->getSunSphereColour (relDayTime, sunDir));
+ mSun->setSunLightColour (getSkyColourModel ()->getSunLightColour (relDayTime, sunDir));
}
// Call every listener before quiting
- if (!fireFinishedEvent (e))
+ if (!fireFinishedEvent (e)) {
return false;
+ }
}
- return true;
-}
-
-SkyDome *CaelumSystem::createSkyDome () {
- if (!mSkyDome) {
- mSkyDome = new SkyDome (mSceneMgr);
- LOG ("Sky Dome created.");
+ // This has to be moved out of here, but Universal clock doesn't calculate deltaT
+ if (getClouds()) {
+ double time = mUniversalClock->getCurrentRelativeDayTime ();
+ Ogre::Vector3 sunDir = getSun() ? mSun->getSunDirection() : Ogre::Vector3::UNIT_Y;
+ mClouds->update (e.timeSinceLastFrame * mUniversalClock->getTimeScale(),
+ getSun () ? mSun->getSunDirection() : Ogre::Vector3::UNIT_Y,
+ getSun () ? mSun->getSunLightColour() : Ogre::ColourValue::White,
+ getSkyColourModel() ? mSkyColourModel->getFogColour (time, sunDir) : Ogre::ColourValue::Black);
}
- return mSkyDome;
+ return true;
}
-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;
}
Modified: trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/CaelumSystem.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -8,6 +8,7 @@
#include "SkyColourModel.h"
#include "SkyDome.h"
#include "Starfield.h"
+#include "LayeredClouds.h"
#include "Sun.h"
namespace caelum {
@@ -18,11 +19,6 @@
*/
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.
*/
@@ -46,27 +42,31 @@
/// Reference to the universal clock.
UniversalClock *mUniversalClock;
+
+ /** Flag to indicate if Caelum should manage the fog or not.
+ */
+ bool mManageFog;
/** The sky dome.
*/
- SkyDome *mSkyDome;
+ std::auto_ptr<SkyDome> mSkyDome;
- /** Reference to the sky colour model in use.
+ /** Reference to the sun.
*/
- SkyColourModel *mSkyColourModel;
+ std::auto_ptr<Sun> mSun;
- /** Flag to indicate if Caelum should manage the fog or not.
+ /** Reference to the clouds.
*/
- bool mManageFog;
+ std::auto_ptr<LayeredClouds> mClouds;
- /** Reference to the sun.
+ /** Reference to the starfield.
*/
- Sun *mSun;
+ std::auto_ptr<Starfield> mStarfield;
- /** Reference to the starfield.
+ /** Reference to the sky colour model in use.
*/
- Starfield *mStarfield;
-
+ std::auto_ptr<SkyColourModel> mSkyColourModel;
+
// Methods --------------------------------------------------------------------
public:
/** Constructor.
@@ -75,15 +75,17 @@
@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);
+ CaelumSystem (
+ Ogre::Root *root,
+ Ogre::SceneManager *sceneMgr,
+ bool createSkyColourModel = true,
+ bool createSkyDome = true,
+ bool createSun = true,
+ bool createStarfield = true,
+ bool createClouds = true,
+ bool manageResGroup = true,
+ const Ogre::String &resGroupName = RESOURCE_GROUP_NAME);
/** Destructor.
*/
@@ -125,57 +127,72 @@
*/
bool frameStarted (const Ogre::FrameEvent &e);
- /** Creates the sky dome, or returns the existing one if any yet.
+ /** Set the skydome.
+ * @param dome A new dome or null to disable.
*/
- SkyDome *createSkyDome ();
+ inline void setSkyDome (SkyDome *dome) {
+ mSkyDome.reset(dome);
+ }
/** Returns the current sky dome.
- @return The current sky dome.
*/
- SkyDome *getSkyDome () const;
+ SkyDome *getSkyDome () const {
+ return mSkyDome.get();
+ }
- /** Destroys the sky dome.
- @remarks Remember to detach the sky dome from every viewport it is attached to before destroying it!
+ /** Set the sun.
+ * @param sun A new sun or null to disable.
*/
- void destroySkyDome ();
+ inline void setSun (Sun* sun) {
+ mSun.reset(sun);
+ }
- /** Creates the sun.
- @return The sun.
- */
- Sun *createSun ();
-
/** Gets the current sun.
@return The sun in use.
*/
- Sun *getSun () const;
+ Sun* getSun () const {
+ return mSun.get();
+ }
- /** Destroys the sun.
- */
- void destroySun ();
+ /** Set the starfield.
+ * @param starfield A new starfield or null to disable.
+ */
+ inline void setStarfield (Starfield* starfield) {
+ mStarfield.reset(starfield);
+ }
- /** 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 current starfield.
+ */
+ inline Starfield* getStarfield () const {
+ return mStarfield.get();
+ }
- /** Gets the starfield.
- @return The starfield.
- */
- Starfield *getStarfield () const;
+ /** Set the cloud system
+ * @param clouds A new cloud system or null to disable.
+ */
+ inline void setClouds (LayeredClouds* clouds) {
+ mClouds.reset(clouds);
+ }
- /** Destroys the current starfield.
- @remark Remember to detach it from every viewport before deleting!
- */
- void destroyStarfield ();
+ /** Get the current cloud system.
+ */
+ inline LayeredClouds* getClouds () const {
+ return mClouds.get();
+ }
/** Sets the sky colour model to be used.
- @param model The sky colour model.
+ * @param model The sky colour model, or null to disable
*/
- void setSkyColourModel (SkyColourModel *model);
+ inline void setSkyColourModel (SkyColourModel *model) {
+ mSkyColourModel.reset(model);
+ }
+ /** Get the current sky colour model.
+ */
+ inline SkyColourModel* getSkyColourModel () const {
+ return mSkyColourModel.get();
+ }
+
/** Enables/disables the Caelum fog management.
@param manage True if you want Caelum to manage the fog for you.
*/
Modified: trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/GeometryFactory.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -1,10 +1,9 @@
#include "CaelumPrecompiled.h"
#include "GeometryFactory.h"
-#include "CaelumSystem.h"
namespace caelum {
-void GeometryFactory::generateSphericDome (const Ogre::String &name, const unsigned int segments, DomeType type) {
+void GeometryFactory::generateSphericDome (const Ogre::String &name, int segments, DomeType type) {
// Return now if already exists
if (Ogre::MeshManager::getSingleton ().resourceExists (name))
return;
@@ -12,7 +11,7 @@
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);
+ Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton ().createManual (name, RESOURCE_GROUP_NAME);
// Create a submesh
Ogre::SubMesh *sub = msh->createSubMesh ();
@@ -87,7 +86,7 @@
LOG ("DONE");
}
-void GeometryFactory::fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments) {
+void GeometryFactory::fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, int segments) {
const float deltaLatitude = Ogre::Math::PI / (float )segments;
const float deltaLongitude = Ogre::Math::PI * 2.0 / (float )segments;
@@ -160,7 +159,7 @@
}
}
-void GeometryFactory::fillStarfieldDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments) {
+void GeometryFactory::fillStarfieldDomeBuffers (float *pVertex, unsigned short *pIndices, int segments) {
const float deltaLatitude = Ogre::Math::PI / (float )segments;
const float deltaLongitude = Ogre::Math::PI * 2.0 / (float )segments;
Modified: trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/GeometryFactory.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -24,7 +24,7 @@
@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);
+ static void generateSphericDome (const Ogre::String &name, int segments, DomeType type = DT_GRADIENTS);
private:
/** Fills the vertex and index buffers for a sky gradients type dome.
@@ -32,14 +32,14 @@
@param pIndices Pointer to the index buffer.
@param segments Subdivision detail.
*/
- static void fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, unsigned int segments);
+ static void fillGradientsDomeBuffers (float *pVertex, unsigned short *pIndices, 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);
+ static void fillStarfieldDomeBuffers (float *pVertex, unsigned short *pIndices, int segments);
};
} // namespace caelum
Added: trunk/python-ogre/ThirdParty/caelum/LayeredClouds.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/LayeredClouds.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/caelum/LayeredClouds.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -0,0 +1,199 @@
+#include "CaelumPrecompiled.h"
+#include "LayeredClouds.h"
+#include "CaelumExceptions.h"
+
+namespace
+{
+ /** Extend a Vector2 to a Vector3 by appending a 0
+ */
+ inline Ogre::Vector3 extend(Ogre::Vector2 vec)
+ {
+ return Ogre::Vector3(vec.x, vec.y, 0);
+ }
+}
+
+namespace caelum
+{
+ LayeredClouds::LayeredClouds
+ (
+ Ogre::SceneManager* scene,
+ const Ogre::String &resourceGroupName,
+ const Ogre::String &materialName,
+ const Ogre::String &meshName,
+ const Ogre::String &entityName
+ ):
+ mSceneMgr(scene)
+ {
+ // Create cloud plane mesh if it doesn't exist.
+ if (Ogre::MeshManager::getSingleton ().getByName (meshName).isNull ()) {
+ Ogre::Plane plane = Ogre::Plane(Ogre::Vector3::NEGATIVE_UNIT_Y, -0.1);
+ Ogre::MeshManager::getSingleton ().createCurvedPlane(
+ meshName, resourceGroupName, plane, 2, 2, .4, 16, 16,
+ false, 1, 1, 1, Ogre::Vector3::UNIT_Z);
+ }
+
+ // Create cloud plane entity.
+ mEntity = mSceneMgr->createEntity(entityName, meshName);
+ mEntity->setMaterialName(materialName);
+ mEntity->setCastShadows(false);
+ mEntity->setRenderQueueGroup (CAELUM_RENDER_QUEUE_CLOUDS);
+
+ mNode = mSceneMgr->getRootSceneNode ()->createChildSceneNode ();
+ mNode->attachObject (mEntity);
+
+ // It would be better to create the material at runtime instead.
+ // More consistent with the rest of Caelum.
+ mMaterial = static_cast<Ogre::MaterialPtr>(
+ Ogre::MaterialManager::getSingleton().getByName(materialName));
+ mMaterial->load();
+ if (mMaterial->getBestTechnique() == 0) {
+ throw new UnsupportedException (0, "Layered cloud material not supported.",
+ "LayeredClouds", "LayeredClouds.cpp", -1);
+ }
+ getFpParams()->setIgnoreMissingParams(true);
+ getVpParams()->setIgnoreMissingParams(true);
+
+ // Default parameter values
+ setCloudCover(0.5);
+ setCloudMassOffset(Ogre::Vector2(0, 0));
+ setCloudDetailOffset(Ogre::Vector2(0, 0));
+
+ setAnimating(true);
+ setCloudMassBlend(0.5);
+ setCloudBlendTime(100);
+ setCloudSpeed(Ogre::Vector2(0, 0));
+ }
+
+ LayeredClouds::~LayeredClouds() {
+ mNode->detachObject(mEntity);
+ mSceneMgr->destroyEntity(mEntity);
+ mEntity = 0;
+ static_cast<Ogre::SceneNode*>(mNode->getParent())->
+ removeAndDestroyChild(mNode->getName());
+ mNode = 0;
+ mSceneMgr = 0;
+ }
+
+ void LayeredClouds::notifyCameraChanged (Ogre::Camera *cam) {
+ mNode->setPosition (cam->getRealPosition ());
+ 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));
+ }
+ }
+
+ Ogre::GpuProgramParametersSharedPtr LayeredClouds::getVpParams() {
+ return mMaterial->getBestTechnique()->getPass(0)->getVertexProgramParameters();
+ }
+
+ Ogre::GpuProgramParametersSharedPtr LayeredClouds::getFpParams() {
+ return mMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
+ }
+
+ void LayeredClouds::update(Ogre::Real timePassed,
+ const Ogre::Vector3 &sunDirection,
+ const Ogre::ColourValue &sunColour,
+ const Ogre::ColourValue &fogColour)
+ {
+ // Set sun parameters.
+ setSunDirection(sunDirection);
+ setSunColour(sunColour);
+ setFogColour(fogColour);
+
+ if (isAnimating()) {
+ // Move clouds.
+ setCloudMassOffset(getCloudMassOffset() + timePassed * getCloudSpeed());
+ setCloudDetailOffset(getCloudDetailOffset() - timePassed * getCloudSpeed());
+
+ // Animate cloud blending.
+ double blend = getCloudMassBlend();
+ blend += timePassed / getCloudBlendTime();
+ blend = fmod(blend, 1);
+ if (blend < 0) {
+ blend = 1 - blend;
+ }
+ setCloudMassBlend(blend);
+ }
+ }
+
+ bool LayeredClouds::isAnimating () const {
+ return mAnimating;
+ }
+
+ void LayeredClouds::setAnimating (bool animating) {
+ mAnimating = animating;
+ }
+
+ void LayeredClouds::setCloudSpeed(const Ogre::Vector2 &cloudSpeed) {
+ mCloudSpeed = cloudSpeed;
+ }
+
+ Ogre::Vector2 LayeredClouds::getCloudSpeed() const {
+ return mCloudSpeed;
+ }
+
+ void LayeredClouds::setCloudBlendTime(const Ogre::Real cloudBlendTime) {
+ static const Ogre::String animTextures1[4] = {
+ "Noise1.png", "Noise2.png", "Noise3.png", "Noise4.png"
+ };
+ static const Ogre::String animTextures2[4] = {
+ "Noise2.png", "Noise3.png", "Noise4.png", "Noise1.png"
+ };
+
+ Ogre::Pass* pass = mMaterial->getBestTechnique()->getPass(0);
+ pass->getTextureUnitState(0)->setAnimatedTextureName(animTextures1, 4, cloudBlendTime * 4);
+ pass->getTextureUnitState(1)->setAnimatedTextureName(animTextures2, 4, cloudBlendTime * 4);
+ setCloudMassBlend(0);
+ mCloudBlendTime = cloudBlendTime;
+ }
+
+ Ogre::Real LayeredClouds::getCloudBlendTime() const {
+ return mCloudBlendTime;
+ }
+
+ void LayeredClouds::setSunDirection(const Ogre::Vector3 &sunDirection) {
+ getVpParams()->setNamedConstant("sunDirection", sunDirection);
+ getFpParams()->setNamedConstant("sunDirection", sunDirection);
+ }
+
+ void LayeredClouds::setSunColour(const Ogre::ColourValue &sunColour) {
+ getFpParams()->setNamedConstant("sunColour", sunColour);
+ }
+
+ void LayeredClouds::setFogColour(const Ogre::ColourValue &fogColour) {
+ getFpParams()->setNamedConstant("fogColour", fogColour);
+ }
+
+ void LayeredClouds::setCloudMassOffset(const Ogre::Vector2 &cloudMassOffset) {
+ getFpParams()->setNamedConstant("cloudMassOffset", extend(mCloudMassOffset = cloudMassOffset));
+ }
+
+ Ogre::Vector2 LayeredClouds::getCloudMassOffset() const {
+ return mCloudMassOffset;
+ }
+
+ void LayeredClouds::setCloudMassBlend(const Ogre::Real cloudMassBlend) {
+ getFpParams()->setNamedConstant("cloudMassBlend", mCloudMassBlend = cloudMassBlend);
+ }
+
+ Ogre::Real LayeredClouds::getCloudMassBlend() const {
+ return mCloudMassBlend;
+ }
+
+ void LayeredClouds::setCloudDetailOffset(const Ogre::Vector2 &cloudDetailOffset) {
+ getFpParams()->setNamedConstant("cloudDetailOffset", extend(mCloudDetailOffset = cloudDetailOffset));
+ }
+
+ Ogre::Vector2 LayeredClouds::getCloudDetailOffset() const {
+ return mCloudDetailOffset;
+ }
+
+ void LayeredClouds::setCloudCover(const Ogre::Real cloudCover) {
+ getFpParams()->setNamedConstant("cloudCover", mCloudCover = cloudCover);
+ }
+
+ Ogre::Real LayeredClouds::getCloudCover() const {
+ return mCloudCover;
+ }
+} // namespace caelum
Added: trunk/python-ogre/ThirdParty/caelum/LayeredClouds.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/LayeredClouds.h (rev 0)
+++ trunk/python-ogre/ThirdParty/caelum/LayeredClouds.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -0,0 +1,175 @@
+#ifndef LAYEREDCLOUDS_H
+#define LAYEREDCLOUDS_H
+
+#include "CaelumPrerequisites.h"
+
+namespace caelum {
+
+/** Class for layered clouds.
+ * @note This is tighly integrated with LayeredCloud.cg and LayeredClouds.material.
+ * There are two "cloud mass" layers blended to create animating clouds and an extra
+ * detailLayer.
+ * Most of the parameters in this class are direct wrappers from GPU shader params.
+ *
+ * Cloud offsets and speeds are not in any meaningful world units. Maybe they should
+ * be in radians or something?
+ */
+class DllExport LayeredClouds {
+ public:
+ /** Standard constructor.
+ * @param scene: Scene to add cloud dome to. This class takes control
+ * of the scene's skydome.
+ * @param material: Name of the material to load. It would be a lot
+ * more consistent to generate the material in code.
+ */
+ LayeredClouds (
+ Ogre::SceneManager* scene,
+ const Ogre::String &resourceGroupName="Caelum",
+ const Ogre::String &materialName="CaelumLayeredClouds",
+ const Ogre::String &meshName="CaelumLayeredClouds",
+ const Ogre::String &entityName="CaelumLayeredClouds");
+
+ ~LayeredClouds ();
+
+ /** Update cloud material.
+ * @param timePassed Time passed since last update.
+ * @param sunDirection Vector towards the sun.
+ * @param sunColour Colour of the sun.
+ */
+ void update (
+ Ogre::Real timePassed,
+ const Ogre::Vector3& sunDirection,
+ const Ogre::ColourValue& sunColour,
+ const Ogre::ColourValue& fogColour);
+
+ /// Handle camera change.
+ virtual void notifyCameraChanged (Ogre::Camera *cam);
+
+ /** Sets cloud cover, between 0 (completely clear) and 1 (completely covered)
+ * @param cloudCover Cloud cover between 0 and 1
+ */
+ void setCloudCover (const Ogre::Real cloudCover);
+
+ /** Gets the current cloud cover.
+ * @return Cloud cover, between 0 and 1
+ */
+ Ogre::Real getCloudCover () const;
+
+ /** Sets blending factor between the two cloud mass layers.
+ */
+ void setCloudMassBlend (const Ogre::Real cloudCover);
+
+ /** Gets the current blending factor between the two cloud mass layers
+ */
+ Ogre::Real getCloudMassBlend () const;
+
+ /** Sets current offset(translation) of the cloud mass on the sky.
+ */
+ void setCloudMassOffset (const Ogre::Vector2 &cloudMassOffset);
+
+ /** Gets current offset(translation) of the cloud mass on the sky.
+ */
+ Ogre::Vector2 getCloudMassOffset () const;
+
+ /** Sets current offset(translation) of cloud details on the sky.
+ */
+ void setCloudDetailOffset (const Ogre::Vector2 &cloudMassOffset);
+
+ /** Gets current offset(translation) of cloud details on the sky.
+ */
+ Ogre::Vector2 getCloudDetailOffset () const;
+
+
+ /** If the cloud layer is animating itself.
+ * @note If this is true then parameters like cloudMassBlend and offsets
+ * are set every update().
+ */
+ bool isAnimating () const;
+
+ /** Switch internal animation on/off
+ */
+ void setAnimating (bool animating);
+
+ /** Sets cloud movement speed.
+ * @param cloudSpeed Cloud movement speed.
+ */
+ void setCloudSpeed (const Ogre::Vector2 &cloudSpeed);
+
+ /** Gets cloud movement speed.
+ * @param cloudSpeed Cloud movement speed.
+ */
+ Ogre::Vector2 getCloudSpeed () const;
+
+ /** Sets the time it takes to blend two cloud shaped together, in seconds.
+ * @param cloudCover Cloud shape blend time in seconds
+ */
+ void setCloudBlendTime (const Ogre::Real cloudBlendTime);
+
+ /** Gets the time it takes to blend two cloud shaped together, in seconds.
+ * @return Cloud shape blend time in seconds
+ */
+ Ogre::Real getCloudBlendTime () const;
+
+ private:
+ /// Shortcut function for fragment program parameters
+ Ogre::GpuProgramParametersSharedPtr getFpParams();
+
+ /// Shortcut function for fragment program parameters
+ Ogre::GpuProgramParametersSharedPtr getVpParams();
+
+ /// Set the sunDirection parameter in the shaders.
+ void setSunDirection(const Ogre::Vector3 &sunDirection);
+
+ /// Set the sunColour parameter in the shaders.
+ void setSunColour(const Ogre::ColourValue &sunColour);
+
+ /// Set the fogColour parameter in the shaders.
+ void setFogColour(const Ogre::ColourValue &fogColour);
+
+ /// Sets inverse Haze height.
+ void setInvHazeHeight (const Ogre::Real invHazeHeight);
+
+ /// Current cloud coverage
+ Ogre::Real mCloudCover;
+
+ /// Current cloud blend factor
+ Ogre::Real mCloudMassBlend;
+
+ /// Current cloud layer offset.
+ Ogre::Vector2 mCloudMassOffset;
+
+ /// Current cloud detail layer offset.
+ Ogre::Vector2 mCloudDetailOffset;
+
+
+ /// If this class controls animation for itself.
+ bool mAnimating;
+
+ /// Current cloud blend time.
+ Ogre::Real mCloudBlendTime;
+
+ /** If true then CloudMassBlend is increased in animation; otherwise it's
+ * decreased. This is changed each time it reaches the end.
+ */
+ bool mCloudBlendAnimationDirection;
+
+ /// Current cloud speed
+ Ogre::Vector2 mCloudSpeed;
+
+
+ /// Cloud material
+ Ogre::MaterialPtr mMaterial;
+
+ /// Cloud plane mesh
+ Ogre::SceneNode *mNode;
+
+ /// Cloud plane entity
+ Ogre::Entity *mEntity;
+
+ /// Reference to scene manager.
+ Ogre::SceneManager *mSceneMgr;
+};
+
+}; // namespace caelum
+
+#endif // LAYEREDCLOUDS_H
Added: trunk/python-ogre/ThirdParty/caelum/SkyColourModel.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/SkyColourModel.cpp (rev 0)
+++ trunk/python-ogre/ThirdParty/caelum/SkyColourModel.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -0,0 +1,113 @@
+#include "CaelumPrecompiled.h"
+#include "SkyColourModel.h"
+
+namespace caelum {
+
+SkyColourModel::SkyColourModel
+(
+ const Ogre::String &gradients,
+ const Ogre::String &sunColours
+):
+ mSunColoursImage(0),
+ mSkyGradientsImage(0)
+{
+ mSkyGradientsImage = 0;
+ mFogDensityMultiplier = 1;
+ setSkyGradientsImage(gradients);
+ setSunColoursImage(sunColours);
+}
+
+SkyColourModel::~SkyColourModel () {
+ if (mSkyGradientsImage != 0) {
+ delete mSkyGradientsImage;
+ mSkyGradientsImage = 0;
+ }
+ if (mSunColoursImage != 0) {
+ delete mSunColoursImage;
+ mSunColoursImage = 0;
+ }
+}
+
+void SkyColourModel::setSkyGradientsImage (const Ogre::String &filename) {
+ if (mSkyGradientsImage != 0) {
+ delete mSkyGradientsImage;
+ mSkyGradientsImage = 0;
+ }
+
+ mSkyGradientsImage = new Ogre::Image ();
+ mSkyGradientsImage->load (filename, RESOURCE_GROUP_NAME);
+}
+
+void SkyColourModel::setSunColoursImage (const Ogre::String &filename) {
+ if (mSunColoursImage != 0) {
+ delete mSunColoursImage;
+ mSunColoursImage = 0;
+ }
+
+ mSunColoursImage = new Ogre::Image ();
+ mSunColoursImage->load (filename, RESOURCE_GROUP_NAME);
+}
+
+Ogre::ColourValue SkyColourModel::getFogColour (float time, const Ogre::Vector3 &sunDir) {
+ float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y) * 0.5 + 0.5;
+ Ogre::ColourValue col = getInterpolatedColour (elevation, 1, mSkyGradientsImage, false);
+ return col;
+}
+
+float SkyColourModel::getFogDensity (float time, const Ogre::Vector3 &sunDir) {
+ float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y) * 0.5 + 0.5;
+ Ogre::ColourValue col = getInterpolatedColour (elevation, 1, mSkyGradientsImage, false);
+ return col.a * mFogDensityMultiplier;
+}
+
+Ogre::ColourValue SkyColourModel::getSunSphereColour (float time, const Ogre::Vector3 &sunDir) {
+ float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y);
+ elevation = elevation * 2 + 0.4;
+
+ if (mSunColoursImage == 0) {
+ return Ogre::ColourValue::White;
+ } else {
+ return getInterpolatedColour (elevation, 1, mSunColoursImage, false);
+ }
+}
+
+Ogre::ColourValue SkyColourModel::getSunLightColour (float time, const Ogre::Vector3 &sunDir) {
+ float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y) * 0.5 + 0.5;
+
+ // Hack: return averaged sky colours
+ Ogre::ColourValue col = getInterpolatedColour (elevation, elevation, mSkyGradientsImage);
+ return Ogre::ColourValue::White * (col.r + col.g + col.b) / 3;
+}
+
+Ogre::ColourValue SkyColourModel::getInterpolatedColour (float x, float height, Ogre::Image *img, bool wrap) {
+ // Get the image width
+ int width = static_cast<int>(img->getWidth ()) - 1;
+
+ // calculate the height
+ height = Ogre::Math::Abs (height);
+ int y = (int )((img->getHeight () - 1) * height);
+ if (y >= static_cast<int>(img->getHeight ()))
+ y--;
+
+ // Get the two closest pixels
+ int curPix, auxPix;
+ float diff;
+ curPix = (int )(width * x);
+ diff = width * x - curPix;
+ if (diff < 0) {
+ auxPix = curPix - 1;
+ }
+ else {
+ auxPix = curPix + 1;
+ }
+
+ // Calculate the interpolated pixel
+ Ogre::ColourValue c1, c2, cf;
+ c1 = img->getColourAt (wrap ? curPix % width : curPix < 0 ? 0 : curPix > width ? width : curPix, y, 0);
+ c2 = img->getColourAt (wrap ? auxPix % width : auxPix < 0 ? 0 : auxPix > width ? width : auxPix, y, 0);
+ cf = c1 * (1 - diff) + c2 * diff;
+
+ return cf;
+}
+
+} // namespace caelum
Modified: trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/SkyColourModel.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -5,70 +5,91 @@
namespace caelum {
-/** Sky colour model interface.
- @author Jes\xFAs Alonso Abad
- @version 0.1
+/** Class which returns various sky colours.
+ * This is based on the same gradients as the skydome.
+ * It would be nice to split it into multiple components.
+ * Functions take a "time" parameter but only elevation is actually used.
*/
class DllExport SkyColourModel {
// Attributes -----------------------------------------------------------------
- protected:
- /** A reference to the sky gradients texture unit state.
- */
- Ogre::TextureUnitState *mSkyGradientsTextureUnitState;
-
+ private:
/** The sky gradients image (for lookups).
*/
Ogre::Image *mSkyGradientsImage;
+ /** The sun gradients image (for lookups).
+ */
+ Ogre::Image *mSunColoursImage;
+
+ /** Multiplier for fog densities obtained from the sky gradients image.
+ */
+ float mFogDensityMultiplier;
+
// Methods --------------------------------------------------------------------
public:
- /** Constructor method.
+ /** Constructor method.
*/
- SkyColourModel () {
- mSkyGradientsTextureUnitState = 0;
- mSkyGradientsImage = 0;
- }
+ SkyColourModel (
+ const Ogre::String &skyGradients = "EarthClearSky2.png",
+ const Ogre::String &sunColours = "SunGradient.png"
+ );
/** Destructor.
*/
- virtual ~SkyColourModel () {}
+ 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;
+ Ogre::ColourValue getFogColour (float time, const Ogre::Vector3 &sunDir);
/** 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;
+ float getFogDensity (float time, const Ogre::Vector3 &sunDir);
- /** Gets the sun colour for a certain daytime.
- @param time The current time.
- @param sunDir The sun direction.
- @return The sun colour.
+ inline float getFogDensityMultiplier() {
+ return mFogDensityMultiplier;
+ }
+
+ inline void setFogDensityMultiplier(float value) {
+ mFogDensityMultiplier = value;
+ }
+
+ /** Get the colour of the sun sphere.
+ * This colour is used to draw the sun sphere in the sky.
+ * @return The colour of the sun.
*/
- virtual Ogre::ColourValue getSunColour (float time, const Ogre::Vector3 &sunDir) = 0;
+ Ogre::ColourValue getSunSphereColour (float time, const Ogre::Vector3 &sunDir);
- /** 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.
+ /** Gets the colour of sun light.
+ * This color is used to illuminate the scene.
+ * @return The colour of the sun's light
*/
- virtual bool updateMaterial (Ogre::GpuProgramParametersSharedPtr fpp, Ogre::GpuProgramParametersSharedPtr vpp, float time, const Ogre::Vector3 &sunDir) = 0;
+ Ogre::ColourValue getSunLightColour (float time, const Ogre::Vector3 &sunDir);
+
+ /// Set the sun gradients image.
+ /// resources/EarthClearSky2.png is the default image; but you can supply another
+ void setSkyGradientsImage (const Ogre::String &filename);
+
+ /// Set the sun colours image.
+ /// Sun colour is taken from this image.
+ /// 'resources/SunGradient.png' is the default image; but you can supply another
+ void setSunColoursImage (const Ogre::String &filename);
+
+ protected:
+ /** Gets the interpolated colour between two pixels from an image.
+ @param x The horizontal coordinate in the range [0, 1].
+ @param height The height at which the pixels are located in the range [0, 1] (will be converted to integer).
+ @param img The lookup image.
+ @param wrap If the map wraps horizontally or not.
+ @return The interpolated colour.
+ */
+ static Ogre::ColourValue getInterpolatedColour (float x, float height, Ogre::Image *img, bool wrap = true);
};
} // namespace caelum
Modified: trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/SkyDome.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -1,12 +1,11 @@
#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::SPHERIC_DOME_NAME = "CaelumSphericDome";
const Ogre::String SkyDome::SKY_DOME_MATERIAL_NAME = "CaelumSkyDomeMaterial";
SkyDome::SkyDome (Ogre::SceneManager *sceneMgr) {
@@ -14,10 +13,10 @@
createSkyDomeMaterial ();
- GeometryFactory::generateSphericDome (mSphericDomeResourceName, 32);
- Ogre::Entity *ent = sceneMgr->createEntity ("Dome", mSphericDomeResourceName);
+ GeometryFactory::generateSphericDome (SPHERIC_DOME_NAME, 32);
+ Ogre::Entity *ent = sceneMgr->createEntity ("Dome", SPHERIC_DOME_NAME);
ent->setMaterialName (SKY_DOME_MATERIAL_NAME);
- ent->setRenderQueueGroup (Ogre::RENDER_QUEUE_SKIES_EARLY + 2);
+ ent->setRenderQueueGroup (CAELUM_RENDER_QUEUE_SKYDOME);
ent->setCastShadows (false);
mNode = sceneMgr->getRootSceneNode ()->createChildSceneNode ();
@@ -41,10 +40,13 @@
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));
+ 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));
+ }
}
}
@@ -52,18 +54,25 @@
if (radius > 0) {
mNode->setScale (Ogre::Vector3::UNIT_SCALE * radius);
mAutoRadius = false;
- }
- else {
+ } 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::setSunDirection (Ogre::Vector3 sunDir) {
+ float elevation = sunDir.dotProduct (Ogre::Vector3::UNIT_Y);
+ elevation = elevation * 0.5 + 0.5;
+
+ Ogre::GpuProgramParametersSharedPtr vpParams =
+ mMaterial->getBestTechnique()->getPass(0)->getVertexProgramParameters();
+ Ogre::GpuProgramParametersSharedPtr fpParams =
+ mMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
+ Ogre::TextureUnitState* gradientsTus =
+ mMaterial->getBestTechnique()->getPass(0)->getTextureUnitState(0);
+
+ vpParams->setNamedConstant ("sunDirection", sunDir);
+ fpParams->setNamedConstant ("offset", elevation);
+ gradientsTus->setTextureUScroll (elevation);
}
void SkyDome::setLightAbsorption (float absorption) const {
@@ -72,84 +81,82 @@
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);
- }
- }
+ Ogre::GpuProgramParametersSharedPtr vpParams =
+ mMaterial->getBestTechnique()->getPass(0)->getVertexProgramParameters();
+ vpParams->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);
- }
- }
+ Ogre::GpuProgramParametersSharedPtr fpParams =
+ mMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
+ fpParams->setNamedConstant ("lightInvScattering", 1.0f / scattering);
}
void SkyDome::setAtmosphereHeight (float height) const {
- if (height <= 0)
+ if (height <= 0) {
height = 0.00001;
- else if (height > 1)
+ } 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);
- }
- }
+ Ogre::GpuProgramParametersSharedPtr fpParams =
+ mMaterial->getBestTechnique()->getPass(0)->getFragmentProgramParameters();
+ fpParams->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);
+void SkyDome::setSkyGradientsImage (const Ogre::String& gradients) {
+ Ogre::TextureUnitState* gradientsTus =
+ mMaterial->getTechnique (0)->getPass (0)->getTextureUnitState(0);
+
+ gradientsTus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_CLAMP);
+
+ // Dagon and Eihort compatibility
+ #if OGRE_VERSION < ((1 << 16) | (3 << 8))
+ gradientsTus->setTextureName (gradients, Ogre::TEX_TYPE_2D, -1, true);
+ #else
+ gradientsTus->setTextureName (gradients, Ogre::TEX_TYPE_2D);
+ gradientsTus->setIsAlpha (true);
+ #endif
}
-Ogre::TextureUnitState *SkyDome::getTextureUnitState () {
- if (mSkyDomeMaterial.isNull ())
- return 0;
+void SkyDome::setAtmosphereDepthImage (const Ogre::String& atmosphereDepth) {
+ Ogre::TextureUnitState* atmosphereTus =
+ mMaterial->getTechnique (0)->getPass (0)->getTextureUnitState(1);
- return mSkyDomeMaterial->getTechnique (0)->getPass (0)->getTextureUnitState (0);
+ atmosphereTus->setTextureName (atmosphereDepth, Ogre::TEX_TYPE_1D);
+ atmosphereTus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_WRAP, Ogre::TextureUnitState::TAM_WRAP);
}
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
+ // Check shader support.
+ // It would be nice to check supported profiles in detail.
+ if (!Ogre::Root::getSingleton ().getRenderSystem ()->getCapabilities ()->hasCapability (Ogre::RSC_FRAGMENT_PROGRAM)) {
+ throw new UnsupportedException (0, "The card doesn't support fragment programs for the sky dome material.", "SkyDome", "SkyDome.cpp", -1);
}
- 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)) {
+ throw new UnsupportedException (0, "The card doesn't support vertex programs for the sky dome material.", "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);
+ mMaterial = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton ().create (SKY_DOME_MATERIAL_NAME, RESOURCE_GROUP_NAME));
+ mMaterial->setReceiveShadows (false);
LOG ("\t\tMaterial [OK]");
- Ogre::Pass *pass = mat->getTechnique (0)->getPass (0);
+
+ Ogre::Pass *pass = mMaterial->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
+
+ // Bind fragment program.
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);
+ Ogre::HighLevelGpuProgramPtr fp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram ("SkyDomeFP", 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");
@@ -158,8 +165,10 @@
parameters->setNamedConstant ("offset", 0.0f);
parameters->setNamedAutoConstant ("hazeColour", Ogre::GpuProgramParameters::ACT_FOG_COLOUR);
}
+
+ // Bind vertex program.
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);
+ Ogre::HighLevelGpuProgramPtr vp = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram ("SkyDomeVP", 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");
@@ -169,40 +178,41 @@
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);
+
+ // Create first texture unit; gradients image.
+ pass->createTextureUnitState ();
+ setSkyGradientsImage("EarthClearSky2.png");
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);
+
+ // Create second texture unit; atmosphere depth image.
+ pass->createTextureUnitState ();
+ setAtmosphereDepthImage("AtmosphereDepth.png");
LOG ("\t\tTextureUnit - Atmosphere depth [OK]");
- mat->load ();
+
+ mMaterial->load ();
LOG ("\tDONE");
+ } else {
+ mMaterial = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton ().getByName (SKY_DOME_MATERIAL_NAME));
}
- 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("SkyDomeFP"))) {
+ LOG ("Removing sky dome SkyDomeFP...");
+ Ogre::HighLevelGpuProgramManager::getSingletonPtr()->remove("SkyDomeFP");
}
- if ((Ogre::HighLevelGpuProgramManager::getSingletonPtr()->resourceExists("SkyLightAbsorptionVP"))) {
- LOG ("Removing sky dome SkyLightAbsorptionVP...");
- Ogre::HighLevelGpuProgramManager::getSingletonPtr()->remove("SkyLightAbsorptionVP");
+ if ((Ogre::HighLevelGpuProgramManager::getSingletonPtr()->resourceExists("SkyDomeVP"))) {
+ LOG ("Removing sky dome SkyDomeVP...");
+ Ogre::HighLevelGpuProgramManager::getSingletonPtr()->remove("SkyDomeVP");
}
if (!Ogre::MaterialManager::getSingleton ().resourceExists (SKY_DOME_MATERIAL_NAME)) {
Ogre::MaterialManager::getSingleton ().remove (SKY_DOME_MATERIAL_NAME);
}
- mSkyDomeMaterial.setNull ();
+ mMaterial.setNull ();
LOG ("DONE");
}
Modified: trunk/python-ogre/ThirdParty/caelum/SkyDome.h
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/SkyDome.h 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/SkyDome.h 2007-10-11 13:13:35 UTC (rev 415)
@@ -3,7 +3,6 @@
#include "CaelumPrerequisites.h"
#include "CameraBoundElement.h"
-#include "SkyColourModel.h"
#include "Sun.h"
namespace caelum {
@@ -13,31 +12,31 @@
*/
class DllExport SkyDome : public CameraBoundElement {
// Attributes -----------------------------------------------------------------
- protected:
+ private:
/** Control scene node.
*/
Ogre::SceneNode *mNode;
/** Name of the spheric dome resource.
*/
- static const Ogre::String mSphericDomeResourceName;
+ static const Ogre::String SPHERIC_DOME_NAME;
/** Name of the dome material.
*/
static const Ogre::String SKY_DOME_MATERIAL_NAME;
- /** Reference to the sky dome material.
- */
- Ogre::MaterialPtr mSkyDomeMaterial;
+ /// Reference to the sky dome material.
+ Ogre::MaterialPtr mMaterial;
// Methods --------------------------------------------------------------------
public:
- /** Constructor (DO NOT USE! Use CaelumSystem::createSkyDome instead).
- @param sceneMgr The scene manager where this sky dome will be created.
+ /** Constructor
+ * This will setup some nice defaults.
+ * @param sceneMgr The scene manager where this sky dome will be created.
*/
SkyDome (Ogre::SceneManager *sceneMgr);
- /** Destructor (DO NOT USE! Use CaelumSystem::destroySkyDome instead).
+ /** Destructor
*/
virtual ~SkyDome ();
@@ -48,7 +47,7 @@
/** @copydoc CameraBoundElement::setFarRadius().
*/
void setFarRadius (float radius);
-
+
/** Sets the sun direction.
@param dir The sun light direction.
*/
@@ -69,17 +68,11 @@
*/
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);
+ /// Set the sky color gradients image.
+ void setSkyGradientsImage (const Ogre::String& gradients);
- /** Returns the sky dome texture unit state.
- @return The texture unit state of the sky dome material.
- */
- Ogre::TextureUnitState *getTextureUnitState ();
+ /// Set the atmosphere depthh gradient image.
+ void setAtmosphereDepthImage (const Ogre::String& gradients);
private:
/** Internal method to create the sky dome material.
Modified: trunk/python-ogre/ThirdParty/caelum/Starfield.cpp
===================================================================
--- trunk/python-ogre/ThirdParty/caelum/Starfield.cpp 2007-10-10 02:21:29 UTC (rev 414)
+++ trunk/python-ogre/ThirdParty/caelum/Starfield.cpp 2007-10-11 13:13:35 UTC (rev 415)
@@ -1,23 +1,24 @@
#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_DOME_NAME = "CaelumStarfieldDome";
+
const Ogre::String Starfield::STARFIELD_MATERIAL_NAME = "CaelumStarfieldMaterial";
-Starfield::Starfield (Ogre::SceneManager *sceneMgr) {
+Starfield::Starfield (Ogre::SceneMan...
[truncated message content] |