OgreLight.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2011 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef _LIGHT_H__
00029 #define _LIGHT_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 
00033 #include "OgreColourValue.h"
00034 #include "OgreVector3.h"
00035 #include "OgreVector4.h"
00036 #include "OgreString.h"
00037 #include "OgreMovableObject.h"
00038 #include "OgrePlaneBoundedVolume.h"
00039 #include "OgreShadowCameraSetup.h"
00040 
00041 namespace Ogre {
00042 
00043 
00072     class _OgreExport Light : public MovableObject
00073     {
00074     public:
00076         Real tempSquareDist;
00078         void _calcTempSquareDist(const Vector3& worldPos);
00079 
00081         enum LightTypes
00082         {
00084             LT_POINT = 0,
00086             LT_DIRECTIONAL = 1,
00088             LT_SPOTLIGHT = 2
00089         };
00090 
00093         Light();
00094 
00097         Light(const String& name);
00098 
00101         ~Light();
00102 
00105         void setType(LightTypes type);
00106 
00109         LightTypes getType(void) const;
00110 
00120         void setDiffuseColour(Real red, Real green, Real blue);
00121 
00131         void setDiffuseColour(const ColourValue& colour);
00132 
00135         const ColourValue& getDiffuseColour(void) const;
00136 
00146         void setSpecularColour(Real red, Real green, Real blue);
00147 
00157         void setSpecularColour(const ColourValue& colour);
00158 
00161         const ColourValue& getSpecularColour(void) const;
00162 
00182         void setAttenuation(Real range, Real constant, Real linear, Real quadratic);
00183 
00186         Real getAttenuationRange(void) const;
00187 
00190         Real getAttenuationConstant(void) const;
00191 
00194         Real getAttenuationLinear(void) const;
00195 
00198         Real getAttenuationQuadric(void) const;
00199 
00206         void setPosition(Real x, Real y, Real z);
00207 
00214         void setPosition(const Vector3& vec);
00215 
00220         const Vector3& getPosition(void) const;
00221 
00228         void setDirection(Real x, Real y, Real z);
00229 
00236         void setDirection(const Vector3& vec);
00237 
00242         const Vector3& getDirection(void) const;
00243 
00254         void setSpotlightRange(const Radian& innerAngle, const Radian& outerAngle, Real falloff = 1.0);
00255 
00258         const Radian& getSpotlightInnerAngle(void) const;
00259 
00262         const Radian& getSpotlightOuterAngle(void) const;
00263 
00266         Real getSpotlightFalloff(void) const;
00267 
00270         void setSpotlightInnerAngle(const Radian& val);
00271 
00274         void setSpotlightOuterAngle(const Radian& val);
00275 
00278         void setSpotlightFalloff(Real val);
00279 
00287         void setPowerScale(Real power);
00288 
00292         Real getPowerScale(void) const;
00293 
00295         void _notifyAttached(Node* parent, bool isTagPoint = false);
00296 
00298         void _notifyMoved(void);
00299 
00301         const AxisAlignedBox& getBoundingBox(void) const;
00302 
00304         void _updateRenderQueue(RenderQueue* queue);
00305 
00307         const String& getMovableType(void) const;
00308 
00312         const Vector3& getDerivedPosition(bool cameraRelativeIfSet = false) const;
00313 
00315         const Vector3& getDerivedDirection(void) const;
00316 
00322         void setVisible(bool visible);
00323 
00325         Real getBoundingRadius(void) const { return 0; /* not visible */ }
00326 
00336         Vector4 getAs4DVector(bool cameraRelativeIfSet = false) const;
00337 
00347         virtual const PlaneBoundedVolume& _getNearClipVolume(const Camera* const cam) const;
00348 
00355         virtual const PlaneBoundedVolumeList& _getFrustumClipVolumes(const Camera* const cam) const;
00356 
00358         uint32 getTypeFlags(void) const;
00359 
00361         AnimableValuePtr createAnimableValue(const String& valueName);
00362 
00369         void setCustomShadowCameraSetup(const ShadowCameraSetupPtr& customShadowSetup);
00370 
00374         void resetCustomShadowCameraSetup(void);
00375 
00377         const ShadowCameraSetupPtr& getCustomShadowCameraSetup(void) const;
00378 
00380         void visitRenderables(Renderable::Visitor* visitor, 
00381             bool debugRenderables = false);
00382 
00391         size_t _getIndexInFrame() const { return mIndexInFrame; }
00392         void _notifyIndexInFrame(size_t i) { mIndexInFrame = i; }
00393         
00409         void setShadowFarDistance(Real distance);
00412         void resetShadowFarDistance(void);
00416         Real getShadowFarDistance(void) const;
00417         Real getShadowFarDistanceSquared(void) const;
00418 
00423         void setShadowNearClipDistance(Real nearClip) { mShadowNearClipDist = nearClip; }
00424 
00430         Real getShadowNearClipDistance() const { return mShadowNearClipDist; }
00431 
00435         Real _deriveShadowNearClipDistance(const Camera* maincam) const;
00436 
00444         void setShadowFarClipDistance(Real farClip) { mShadowFarClipDist = farClip; }
00445 
00451         Real getShadowFarClipDistance() const { return mShadowFarClipDist; }
00452 
00456         Real _deriveShadowFarClipDistance(const Camera* maincam) const;
00457 
00459         void _setCameraRelative(Camera* cam);
00460 
00476         void setCustomParameter(uint16 index, const Vector4& value);
00477 
00482         const Vector4& getCustomParameter(uint16 index) const;
00483 
00506         virtual void _updateCustomGpuParameter(uint16 paramIndex, 
00507             const GpuProgramParameters::AutoConstantEntry& constantEntry, 
00508             GpuProgramParameters* params) const;
00509     protected:
00511         virtual void update(void) const;
00512 
00514         const String& getAnimableDictionaryName(void) const;
00516         void initialiseAnimableDictionary(StringVector& vec) const;
00517 
00518         LightTypes mLightType;
00519         Vector3 mPosition;
00520         ColourValue mDiffuse;
00521         ColourValue mSpecular;
00522 
00523         Vector3 mDirection;
00524 
00525         Radian mSpotOuter;
00526         Radian mSpotInner;
00527         Real mSpotFalloff;
00528         Real mRange;
00529         Real mAttenuationConst;
00530         Real mAttenuationLinear;
00531         Real mAttenuationQuad;
00532         Real mPowerScale;
00533         size_t mIndexInFrame;
00534         bool mOwnShadowFarDist;
00535         Real mShadowFarDist;
00536         Real mShadowFarDistSquared;
00537         
00538         Real mShadowNearClipDist;
00539         Real mShadowFarClipDist;
00540 
00541 
00542         mutable Vector3 mDerivedPosition;
00543         mutable Vector3 mDerivedDirection;
00544         // Slightly hacky but unless we separate observed light render state from main Light...
00545         mutable Vector3 mDerivedCamRelativePosition;
00546         mutable bool mDerivedCamRelativeDirty;
00547         Camera* mCameraToBeRelativeTo;
00548 
00550         static String msMovableType;
00551 
00552         mutable PlaneBoundedVolume mNearClipVolume;
00553         mutable PlaneBoundedVolumeList mFrustumClipVolumes;
00555         mutable bool mDerivedTransformDirty;
00556 
00558         mutable ShadowCameraSetupPtr mCustomShadowCameraSetup;
00559 
00560         typedef map<uint16, Vector4>::type CustomParameterMap;
00562         CustomParameterMap mCustomParameters;
00563     };
00564 
00566     class _OgreExport LightFactory : public MovableObjectFactory
00567     {
00568     protected:
00569         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00570     public:
00571         LightFactory() {}
00572         ~LightFactory() {}
00573 
00574         static String FACTORY_TYPE_NAME;
00575 
00576         const String& getType(void) const;
00577         void destroyInstance( MovableObject* obj);  
00578 
00579     };
00583 } // Namespace
00584 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:43