From 19491a579f75045345bcc01b2cc0002ff3151e93 Mon Sep 17 00:00:00 2001 From: hybrid Date: Thu, 27 Nov 2008 23:25:20 +0000 Subject: [PATCH] Merged from 1.5 branch revisions 1837:1850. Light property changes, shader problems fixed, OSX resize fixed, meshloader debug messages disabled. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1851 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 6 +++ examples/08.SpecialFX/main.cpp | 2 +- include/ILightSceneNode.h | 31 ++++++++++++ include/SAnimatedMesh.h | 2 +- include/SLight.h | 18 ++++--- source/Irrlicht/C3DSMeshFileLoader.cpp | 2 + source/Irrlicht/CLWOMeshFileLoader.cpp | 2 + source/Irrlicht/CLightSceneNode.cpp | 59 +++++++++++++++++++++- source/Irrlicht/CLightSceneNode.h | 31 ++++++++++++ source/Irrlicht/COpenGLDriver.cpp | 1 + source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm | 42 +++++++++++++-- 11 files changed, 179 insertions(+), 17 deletions(-) diff --git a/changes.txt b/changes.txt index 7c7fb98b..b00b25dc 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,11 @@ Changes in version 1.5 (...12.2008) + - Changed the preferred way of altering light node's radius: Use the new member methods of ILightSceneNode instead of directly modifying the SLight structure. + + - Changed the initial attenuation back to (0,1/radius,0). To override this value simply change the attenuation in the SLight (lightnode->getLightData().Attenuation.set(x,y,z)) + + - Dirty fix for OSX device setResizable and a bug fix to do with resizing the device. + - Terrain heightmap and texture were flipped in order to draw them as expected (looking onto the terrain from high above will just look like the actual texture/heightmap). - Significant internal change to the way that FPS camera jump speed and collision response animator gravity interact. The behaviour is now much more realistic, but it will require you to adjust your jump speed and gravity. diff --git a/examples/08.SpecialFX/main.cpp b/examples/08.SpecialFX/main.cpp index cf3ca573..856d46fd 100644 --- a/examples/08.SpecialFX/main.cpp +++ b/examples/08.SpecialFX/main.cpp @@ -128,7 +128,7 @@ int main() // create light node = smgr->addLightSceneNode(0, core::vector3df(0,0,0), - video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 1200.0f); + video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 800.0f); scene::ISceneNodeAnimator* anim = 0; anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),250.0f); node->addAnimator(anim); diff --git a/include/ILightSceneNode.h b/include/ILightSceneNode.h index 0e3455a3..3bc89c0c 100644 --- a/include/ILightSceneNode.h +++ b/include/ILightSceneNode.h @@ -39,6 +39,37 @@ public: //! Gets the light data associated with this ILightSceneNode /** \return The light data. */ virtual video::SLight& getLightData() = 0; + + //! Sets the light's radius of influence. + /** Outside this radius the light won't lighten geometry and cast no + shadows. Setting the radius will also influence the attenuation, setting + it to (0,1/radius,0). If you want to override this behavior, set the + attenuation after the radius. + \param radius The new radius. */ + virtual void setRadius(f32 radius) = 0; + + //! Gets the light's radius of influence. + /** \return The current radius. */ + virtual f32 getRadius() const = 0; + + //! Sets the light type. + /** \param type The new type. */ + virtual void setLightType(video::E_LIGHT_TYPE type) = 0; + + //! Gets the light type. + /** \return The current light type. */ + virtual video::E_LIGHT_TYPE getLightType() const = 0; + + //! Sets whether this light casts shadows. + /** Enabling this flag won't automatically cast shadows, the meshes + will still need shadow scene nodes attached. But one can enable or + disable distinct lights for shadow casting for performance reasons. + \param shadow True if this light shall cast shadows. */ + virtual void enableCastShadow(bool shadow=true) = 0; + + //! Check whether this light casts shadows. + /** \return True if light would cast shadows, else false. */ + virtual bool getCastShadow() const = 0; }; } // end namespace scene diff --git a/include/SAnimatedMesh.h b/include/SAnimatedMesh.h index f904abf3..09e4c9c0 100644 --- a/include/SAnimatedMesh.h +++ b/include/SAnimatedMesh.h @@ -83,7 +83,7 @@ namespace scene //! set user axis aligned bounding box - virtual void setBoundingBox( const core::aabbox3df& box) + virtual void setBoundingBox(const core::aabbox3df& box) { Box = box; } diff --git a/include/SLight.h b/include/SLight.h index 94bf0ac2..5fcd7651 100644 --- a/include/SLight.h +++ b/include/SLight.h @@ -39,9 +39,9 @@ struct SLight { SLight() : AmbientColor(0.f,0.f,0.f), DiffuseColor(1.f,1.f,1.f), SpecularColor(1.f,1.f,1.f), Attenuation(1.f,0.f,0.f), - Radius(100.f), OuterCone(45.f), InnerCone(0.f), Falloff(2.f), + OuterCone(45.f), InnerCone(0.f), Falloff(2.f), Position(0.f,0.f,0.f), Direction(0.f,0.f,1.f), - Type(ELT_POINT), CastShadows(true) + Radius(100.f), Type(ELT_POINT), CastShadows(true) {} //! Ambient color emitted by the light @@ -56,12 +56,11 @@ struct SLight SColorf SpecularColor; //! Attenuation factors (constant, linear, quadratic) - /** Changes the light strength fading over distance */ + /** Changes the light strength fading over distance. + Can also be altered by setting the radius, Attenuation will change to + (0,1.f/radius,0). Can be overridden after radius was set. */ core::vector3df Attenuation; - //! Radius of light. Everything within this radius be be lighted. - f32 Radius; - //! The angle of the spot's outer cone. Ignored for other lights. f32 OuterCone; @@ -79,10 +78,13 @@ struct SLight /** If Type is ELT_POINT, it is ignored. Changed via light scene node's rotation. */ core::vector3df Direction; - //! Type of the light. Default: ELT_POINT + //! Read-ONLY! Radius of light. Everything within this radius be be lighted. + f32 Radius; + + //! Read-ONLY! Type of the light. Default: ELT_POINT E_LIGHT_TYPE Type; - //! Does the light cast shadows? + //! Read-ONLY! Does the light cast shadows? bool CastShadows; }; diff --git a/source/Irrlicht/C3DSMeshFileLoader.cpp b/source/Irrlicht/C3DSMeshFileLoader.cpp index 3c651673..f5fedffc 100644 --- a/source/Irrlicht/C3DSMeshFileLoader.cpp +++ b/source/Irrlicht/C3DSMeshFileLoader.cpp @@ -13,7 +13,9 @@ #include "IVideoDriver.h" #include "IMeshManipulator.h" +#ifdef _DEBUG #define _IRR_DEBUG_3DS_LOADER_ +#endif namespace irr { diff --git a/source/Irrlicht/CLWOMeshFileLoader.cpp b/source/Irrlicht/CLWOMeshFileLoader.cpp index 88c160cb..4bd9ab15 100644 --- a/source/Irrlicht/CLWOMeshFileLoader.cpp +++ b/source/Irrlicht/CLWOMeshFileLoader.cpp @@ -19,7 +19,9 @@ namespace irr namespace scene { +#ifdef _DEBUG #define LWO_READER_DEBUG +#endif #define charsToUIntD(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d) inline unsigned int charsToUInt(const char *str) diff --git a/source/Irrlicht/CLightSceneNode.cpp b/source/Irrlicht/CLightSceneNode.cpp index 7aafb3ba..ec6cf755 100644 --- a/source/Irrlicht/CLightSceneNode.cpp +++ b/source/Irrlicht/CLightSceneNode.cpp @@ -23,12 +23,11 @@ CLightSceneNode::CLightSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, setDebugName("CLightSceneNode"); #endif - LightData.Radius = radius; LightData.DiffuseColor = color; - // set some useful specular color LightData.SpecularColor = color.getInterpolated(video::SColor(255,255,255,255),0.7f); + setRadius(radius); doLightRecalc(); } @@ -105,6 +104,62 @@ const core::aabbox3d& CLightSceneNode::getBoundingBox() const } +//! Sets the light's radius of influence. +/** Outside this radius the light won't lighten geometry and cast no +shadows. Setting the radius will also influence the attenuation, setting +it to (0,1/radius,0). If you want to override this behavior, set the +attenuation after the radius. +\param radius The new radius. */ +void CLightSceneNode::setRadius(f32 radius) +{ + LightData.Radius=radius; + LightData.Attenuation.set(0.f, 1.f/radius, 0.f); +} + + +//! Gets the light's radius of influence. +/** \return The current radius. */ +f32 CLightSceneNode::getRadius() const +{ + return LightData.Radius; +} + + +//! Sets the light type. +/** \param type The new type. */ +void CLightSceneNode::setLightType(video::E_LIGHT_TYPE type) +{ + LightData.Type=type; +} + + +//! Gets the light type. +/** \return The current light type. */ +video::E_LIGHT_TYPE CLightSceneNode::getLightType() const +{ + return LightData.Type; +} + + +//! Sets whether this light casts shadows. +/** Enabling this flag won't automatically cast shadows, the meshes +will still need shadow scene nodes attached. But one can enable or +disable distinct lights for shadow casting for performance reasons. +\param shadow True if this light shall cast shadows. */ +void CLightSceneNode::enableCastShadow(bool shadow) +{ + LightData.CastShadows=shadow; +} + + +//! Check whether this light casts shadows. +/** \return True if light would cast shadows, else false. */ +bool CLightSceneNode::getCastShadow() const +{ + return LightData.CastShadows; +} + + void CLightSceneNode::doLightRecalc() { if ((LightData.Type == video::ELT_SPOT) || (LightData.Type == video::ELT_DIRECTIONAL)) diff --git a/source/Irrlicht/CLightSceneNode.h b/source/Irrlicht/CLightSceneNode.h index 310f2dd1..689e3f64 100644 --- a/source/Irrlicht/CLightSceneNode.h +++ b/source/Irrlicht/CLightSceneNode.h @@ -54,6 +54,37 @@ public: //! Creates a clone of this scene node and its children. virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0); + + //! Sets the light's radius of influence. + /** Outside this radius the light won't lighten geometry and cast no + shadows. Setting the radius will also influence the attenuation, setting + it to (0,1/radius,0). If you want to override this behavior, set the + attenuation after the radius. + \param radius The new radius. */ + virtual void setRadius(f32 radius); + + //! Gets the light's radius of influence. + /** \return The current radius. */ + virtual f32 getRadius() const; + + //! Sets the light type. + /** \param type The new type. */ + virtual void setLightType(video::E_LIGHT_TYPE type); + + //! Gets the light type. + /** \return The current light type. */ + virtual video::E_LIGHT_TYPE getLightType() const; + + //! Sets whether this light casts shadows. + /** Enabling this flag won't automatically cast shadows, the meshes + will still need shadow scene nodes attached. But one can enable or + disable distinct lights for shadow casting for performance reasons. + \param shadow True if this light shall cast shadows. */ + virtual void enableCastShadow(bool shadow=true); + + //! Check whether this light casts shadows. + /** \return True if light would cast shadows, else false. */ + virtual bool getCastShadow() const; private: video::SLight LightData; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index f5fd4c05..032239b2 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -1805,6 +1805,7 @@ void COpenGLDriver::setRenderStates3DMode() { // Reset Texture Stages glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); // switch back the matrices diff --git a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm index e51a4738..403e9010 100644 --- a/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm +++ b/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm @@ -359,6 +359,9 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) initKeycodes(); if (CreationParams.DriverType != video::EDT_NULL) createWindow(); + + setResizeAble(false); + CursorControl = new CCursorControl(CreationParams.WindowSize, this); createDriver(); createGUIAndScene(); @@ -567,12 +570,18 @@ bool CIrrDeviceMacOSX::createWindow() return (result); } -void CIrrDeviceMacOSX::setResize(int width,int height) -{ +void CIrrDeviceMacOSX::setResize(int width, int height) +{ + // set new window size _width = width; _height = height; + + // update the size of the opengl rendering context [(NSOpenGLContext *)_oglcontext update]; - getVideoDriver()->OnResize(core::dimension2d(width, height)); + + // resize the driver to the inner pane size + NSRect driverFrame = [(NSWindow*)_window contentRectForFrameRect:[(NSWindow*)_window frame]]; + getVideoDriver()->OnResize(core::dimension2d( (s32)driverFrame.size.width, (s32)driverFrame.size.height)); } void CIrrDeviceMacOSX::createDriver() @@ -946,12 +955,35 @@ void CIrrDeviceMacOSX::initKeycodes() } + //! Sets if the window should be resizeable in windowed mode. void CIrrDeviceMacOSX::setResizeAble(bool resize) { - // todo: implement resize + // todo: Hacky method, clicking the bottom right corner freezes the window. + // We can't set the resize flag without destroying the window, so we'll set the max size to the current size + + if (!_window) + return; + + NSSize s; + + if (resize) + { + s.width = 0.0f; + s.height = 0.0f; + [(NSWindow *)_window setMinSize: s]; + s.width = float(_screenWidth); + s.height = float(_screenHeight); + [(NSWindow *)_window setMaxSize: s]; + } + else + { + s = [(NSWindow *)_window frame].size; + [(NSWindow *)_window setMinSize: s]; + [(NSWindow *)_window setMaxSize: s]; + } } - + bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect* src ) {