Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGSpotLight.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 
00042 #include "OSGConfig.h"
00043 
00044 #include <OSGGL.h>
00045 
00046 #include <OSGDrawAction.h>
00047 #include <OSGRenderAction.h>
00048 
00049 #include "OSGSpotLight.h"
00050 
00051 OSG_USING_NAMESPACE
00052 
00065 /*----------------------------- class variables ---------------------------*/
00066 
00067 StatElemDesc<StatIntElem>  SpotLight::statNSpotLights(
00068 "NSpotLights", "number of spot light sources");
00069 
00070 /*-------------------------------------------------------------------------*/
00071 /*                             Changed                                     */
00072 
00073 void SpotLight::changed(BitVector whichField, UInt32 origin)
00074 {
00075     Inherited::changed(whichField, origin);
00076 }
00077 
00078 /*-------------------------------------------------------------------------*/
00079 /*                             Chunk                                       */
00080 
00081 void SpotLight::makeChunk(void)
00082 {
00083     Inherited::makeChunk();
00084 
00085     Vec4f pos(_sfPosition.getValue ());
00086 
00087     pos[3] = 1;
00088 
00089     _pChunk->setPosition (pos                     );
00090     _pChunk->setDirection(getDirection         () );
00091 
00092     _pChunk->setExponent (getSpotExponent      () );
00093     _pChunk->setCutoff   (rad2deg(getSpotCutOff()));
00094 }
00095 
00096 /*-------------------------------------------------------------------------*/
00097 /*                                Dump                                     */
00098 
00099 void SpotLight::dump(      UInt32    uiIndent, 
00100                      const BitVector bvFlags) const
00101 {
00102    Inherited::dump(uiIndent, bvFlags);
00103 }
00104 
00105 /*-------------------------------------------------------------------------*/
00106 /*                            Constructors                                 */
00107 
00108 SpotLight::SpotLight(void) :
00109     Inherited()
00110 {
00111 }
00112 
00113 SpotLight::SpotLight(const SpotLight &source) :
00114     Inherited(source)
00115 {
00116 }
00117 
00118 /*-------------------------------------------------------------------------*/
00119 /*                             Destructor                                  */
00120 
00121 SpotLight::~SpotLight(void)
00122 {
00123 }
00124 
00125 /*-------------------------------------------------------------------------*/
00126 /*                               Drawing                                   */
00127 
00128 Action::ResultE SpotLight::drawEnter(Action *action)
00129 {   
00130     if(getOn() == false)
00131         return Action::Continue;
00132 
00133     DrawAction *da    = dynamic_cast<DrawAction *>(action);
00134     GLenum      light = GL_LIGHT0 + da->getLightCount();
00135     
00136     Light::drawEnter(action);
00137 
00138     Vec4f  dir(_sfDirection.getValue());
00139     Vec4f  pos(_sfPosition .getValue());
00140 
00141     pos[3] = 1;
00142     dir[3] = 0;
00143 
00144     Real32 deg = rad2deg(_sfSpotCutOff.getValue());
00145 
00146     if(deg > 90.f) 
00147         deg = 180.f;
00148 
00149     glLightfv(light, GL_POSITION      ,  pos.getValues()          );
00150     glLightfv(light, GL_SPOT_DIRECTION,  dir.getValues()          );
00151 
00152     glLightf (light, GL_SPOT_CUTOFF   ,  deg                      );
00153     glLightf (light, GL_SPOT_EXPONENT , _sfSpotExponent.getValue());
00154 
00155     glPopMatrix();
00156 
00157     da->getStatistics()->getElem(SpotLight::statNSpotLights)->inc();
00158 
00159     return Action::Continue;
00160 }
00161     
00162 Action::ResultE SpotLight::drawLeave(Action *action)
00163 {
00164     if(getOn() == false)
00165         return Action::Continue;
00166 
00167     return Light::drawLeave(action);
00168 }
00169 
00170 /*-------------------------------------------------------------------------*/
00171 /*                             Rendering                                   */
00172 
00173 Action::ResultE SpotLight::renderEnter(Action *action)
00174 {
00175     if(getOn() == false)
00176         return Action::Continue;
00177 
00178     DrawActionBase *da    = dynamic_cast<DrawActionBase *>(action);
00179     da->getStatistics()->getElem(SpotLight::statNSpotLights)->inc();
00180 
00181     return PointLight::renderEnter(action);
00182 }
00183 
00184 Action::ResultE SpotLight::renderLeave(Action *action)
00185 {
00186     if(getOn() == false)
00187         return Action::Continue;
00188 
00189     return PointLightBase::renderLeave(action);
00190 }
00191 
00192 /*-------------------------------------------------------------------------*/
00193 /*                               Init                                      */
00194 
00195 void SpotLight::initMethod (void)
00196 {
00197     DrawAction::registerEnterDefault( 
00198         getClassType(), 
00199         osgTypedMethodFunctor2BaseCPtrRef<
00200             Action::ResultE,
00201             SpotLightPtr    , 
00202             CNodePtr        ,  
00203             Action         *>(&SpotLight::drawEnter));
00204 
00205     DrawAction::registerLeaveDefault( 
00206         getClassType(), 
00207         osgTypedMethodFunctor2BaseCPtrRef<
00208             Action::ResultE,
00209             SpotLightPtr    , 
00210             CNodePtr        ,  
00211             Action         *>(&SpotLight::drawLeave));
00212 
00213     RenderAction::registerEnterDefault(
00214         getClassType(), 
00215         osgTypedMethodFunctor2BaseCPtrRef<
00216             Action::ResultE,
00217             SpotLightPtr    , 
00218             CNodePtr        ,  
00219             Action         *>(&SpotLight::renderEnter));
00220 
00221     RenderAction::registerLeaveDefault( 
00222         getClassType(), 
00223         osgTypedMethodFunctor2BaseCPtrRef<
00224             Action::ResultE,
00225             SpotLightPtr    , 
00226             CNodePtr        ,  
00227             Action         *>(&SpotLight::renderLeave));
00228 }
00229 
00230 
00231 /*-------------------------------------------------------------------------*/
00232 /*                              cvs id's                                   */
00233 
00234 #ifdef __sgi
00235 #pragma set woff 1174
00236 #endif
00237 
00238 #ifdef OSG_LINUX_ICC
00239 #pragma warning( disable : 177 )
00240 #endif
00241 
00242 namespace
00243 {
00244     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00245     static Char8 cvsid_hpp[] = OSGSPOTLIGHT_HEADER_CVSID;
00246     static Char8 cvsid_inl[] = OSGSPOTLIGHT_INLINE_CVSID;
00247 }

Generated on Thu Aug 25 04:10:34 2005 for OpenSG by  doxygen 1.4.3