Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreLight.cpp

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 © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreStableHeaders.h"
00026 #include "OgreLight.h"
00027 
00028 #include "OgreException.h"
00029 #include "OgreSceneNode.h"
00030 
00031 namespace Ogre {
00032     String Light::msMovableType = "Light";
00033 
00034     //-----------------------------------------------------------------------
00035     Light::Light()
00036     {
00037         // Default to point light, white diffuse light, linear attenuation, fair range
00038         mLightType = LT_POINT;
00039         mDiffuse = ColourValue::White;
00040         mSpecular = ColourValue::Black;
00041         mRange = 1000;
00042         mAttenuationConst = 1.0f;
00043         mAttenuationLinear = 0.0f;
00044         mAttenuationQuad = 0.0f;
00045 
00046         // Center in world, direction irrelevant but set anyway
00047         mPosition = Vector3::ZERO;
00048         mDirection = Vector3::UNIT_Z;
00049         mParentNode = NULL;
00050 
00051     }
00052     //-----------------------------------------------------------------------
00053     Light::Light(const String& name)
00054     {
00055         mName = name;
00056 
00057         // Default to point light, white diffuse light, linear attenuation, fair range
00058         mLightType = LT_POINT;
00059         mDiffuse = ColourValue::White;
00060         mSpecular = ColourValue::Black;
00061         mRange = 100000;
00062         mAttenuationConst = 1.0f;
00063         mAttenuationLinear = 0.0f;
00064         mAttenuationQuad = 0.0f;
00065 
00066         // Center in world, direction irrelevant but set anyway
00067         mPosition = Vector3::ZERO;
00068         mDirection = Vector3::UNIT_Z;
00069 
00070         // Default some spot values
00071         mSpotInner = 30.0f;
00072         mSpotOuter = 40.0f;
00073         mSpotFalloff = 1.0f;
00074         mParentNode = NULL;
00075 
00076 
00077     }
00078     //-----------------------------------------------------------------------
00079     Light::~Light()
00080     {
00081     }
00082     //-----------------------------------------------------------------------
00083     const String& Light::getName(void) const
00084     {
00085         return mName;
00086 
00087     }
00088     //-----------------------------------------------------------------------
00089     void Light::setType(LightTypes type)
00090     {
00091         mLightType = type;
00092     }
00093     //-----------------------------------------------------------------------
00094     Light::LightTypes Light::getType(void) const
00095     {
00096         return mLightType;
00097     }
00098     //-----------------------------------------------------------------------
00099     void Light::setPosition(Real x, Real y, Real z)
00100     {
00101         mPosition.x = x;
00102         mPosition.y = y;
00103         mPosition.z = z;
00104 
00105     }
00106     //-----------------------------------------------------------------------
00107     void Light::setPosition(const Vector3& vec)
00108     {
00109         mPosition = vec;
00110     }
00111     //-----------------------------------------------------------------------
00112     const Vector3& Light::getPosition(void) const
00113     {
00114         return mPosition;
00115     }
00116     //-----------------------------------------------------------------------
00117     void Light::setDirection(Real x, Real y, Real z)
00118     {
00119         mDirection.x = x;
00120         mDirection.y = y;
00121         mDirection.z = z;
00122     }
00123     //-----------------------------------------------------------------------
00124     void Light::setDirection(const Vector3& vec)
00125     {
00126         mDirection = vec;
00127     }
00128     //-----------------------------------------------------------------------
00129     const Vector3& Light::getDirection(void) const
00130     {
00131         return mDirection;
00132     }
00133     //-----------------------------------------------------------------------
00134     void Light::setSpotlightRange(Real innerAngle, Real outerAngle, Real falloff)
00135     {
00136 
00137         if (mLightType != LT_SPOTLIGHT)
00138             Except(9999,
00139                 "setSpotlightRange is only valid for spotlights.",
00140                 "Light::setSpotlightRange");
00141 
00142         mSpotInner =innerAngle;
00143         mSpotOuter = outerAngle;
00144         mSpotFalloff = falloff;
00145     }
00146     //-----------------------------------------------------------------------
00147     Real Light::getSpotlightInnerAngle(void) const
00148     {
00149         return mSpotInner;
00150     }
00151     //-----------------------------------------------------------------------
00152     Real Light::getSpotlightOuterAngle(void) const
00153     {
00154         return mSpotOuter;
00155     }
00156     //-----------------------------------------------------------------------
00157     Real Light::getSpotlightFalloff(void) const
00158     {
00159         return mSpotFalloff;
00160     }
00161     //-----------------------------------------------------------------------
00162     void Light::setDiffuseColour(Real red, Real green, Real blue)
00163     {
00164         mDiffuse.r = red;
00165         mDiffuse.b = blue;
00166         mDiffuse.g = green;
00167     }
00168     //-----------------------------------------------------------------------
00169     void Light::setDiffuseColour(const ColourValue& colour)
00170     {
00171         mDiffuse = colour;
00172     }
00173     //-----------------------------------------------------------------------
00174     const ColourValue& Light::getDiffuseColour(void) const
00175     {
00176         return mDiffuse;
00177     }
00178     //-----------------------------------------------------------------------
00179     void Light::setSpecularColour(Real red, Real green, Real blue)
00180     {
00181         mSpecular.r = red;
00182         mSpecular.b = blue;
00183         mSpecular.g = green;
00184     }
00185     //-----------------------------------------------------------------------
00186     void Light::setSpecularColour(const ColourValue& colour)
00187     {
00188         mSpecular = colour;
00189     }
00190     //-----------------------------------------------------------------------
00191     const ColourValue& Light::getSpecularColour(void) const
00192     {
00193         return mSpecular;
00194     }
00195     //-----------------------------------------------------------------------
00196     void Light::setAttenuation(Real range, Real constant,
00197                         Real linear, Real quadratic)
00198     {
00199         mRange = range;
00200         mAttenuationConst = constant;
00201         mAttenuationLinear = linear;
00202         mAttenuationQuad = quadratic;
00203     }
00204     //-----------------------------------------------------------------------
00205     Real Light::getAttenuationRange(void) const
00206     {
00207         return mRange;
00208     }
00209     //-----------------------------------------------------------------------
00210     Real Light::getAttenuationConstant(void) const
00211     {
00212         return mAttenuationConst;
00213     }
00214     //-----------------------------------------------------------------------
00215     Real Light::getAttenuationLinear(void) const
00216     {
00217         return mAttenuationLinear;
00218     }
00219     //-----------------------------------------------------------------------
00220     Real Light::getAttenuationQuadric(void) const
00221     {
00222         return mAttenuationQuad;
00223     }
00224     //-----------------------------------------------------------------------
00225     void Light::update(void) const
00226     {
00227         if (mParentNode)
00228         {
00229             if (!(mParentNode->_getDerivedOrientation() == mLastParentOrientation &&
00230                 mParentNode->_getDerivedPosition() == mLastParentPosition))
00231             {
00232                 // Ok, we're out of date with SceneNode we're attached to
00233                 mLastParentOrientation = mParentNode->_getDerivedOrientation();
00234                 mLastParentPosition = mParentNode->_getDerivedPosition();
00235                 mDerivedDirection = mLastParentOrientation * mDirection;
00236                 mDerivedPosition = (mLastParentOrientation * mPosition) + mLastParentPosition;
00237             }
00238         }
00239         else
00240         {
00241             mDerivedPosition = mPosition;
00242             mDerivedDirection = mDirection;
00243         }
00244 
00245     }
00246     //-----------------------------------------------------------------------
00247     void Light::_notifyCurrentCamera(Camera* cam)
00248     {
00249         // Do nothing
00250     }
00251     //-----------------------------------------------------------------------
00252     const AxisAlignedBox& Light::getBoundingBox(void) const
00253     {
00254         // Null, lights are not visible
00255         static AxisAlignedBox box;
00256         return box;
00257     }
00258     //-----------------------------------------------------------------------
00259     void Light::_updateRenderQueue(RenderQueue* queue)
00260     {
00261         // Do nothing
00262     }
00263     //-----------------------------------------------------------------------
00264     const String& Light::getMovableType(void) const
00265     {
00266         return msMovableType;
00267     }
00268     //-----------------------------------------------------------------------
00269     const Vector3& Light::getDerivedPosition(void) const
00270     {
00271         update();
00272         return mDerivedPosition;
00273     }
00274     //-----------------------------------------------------------------------
00275     const Vector3& Light::getDerivedDirection(void) const
00276     {
00277         update();
00278         return mDerivedDirection;
00279     }
00280     //-----------------------------------------------------------------------
00281     void Light::setVisible(bool visible)
00282     {
00283         MovableObject::setVisible(visible);
00284     }
00285 
00286 
00287 
00288 
00289 
00290 
00291 } // Namespace

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:14 2004