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

OSGDirectionalLight.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 "OSGNodePtr.h"
00047 #include "OSGDirectionalLight.h"
00048 #include <OSGDrawAction.h>
00049 #include <OSGRenderAction.h>
00050 
00051 OSG_USING_NAMESPACE
00052 
00058 /*----------------------------- class variables ---------------------------*/
00059 
00060 StatElemDesc<StatIntElem>  DirectionalLight::statNDirectionalLights(
00061 "NDirectionalLights", "number of directional light sources");
00062 
00063 
00064 /*-------------------------------------------------------------------------*/
00065 /*                                Set                                      */
00066 
00067 void DirectionalLight::setDirection(Real32 rX, Real32 rY, Real32 rZ)
00068 {
00069     _sfDirection.getValue().setValues(rX, rY, rZ);
00070 }
00071 
00072 /*-------------------------------------------------------------------------*/
00073 /*                             Changed                                     */
00074 
00075 void DirectionalLight::changed(BitVector whichField, UInt32 origin)
00076 {
00077     Inherited::changed(whichField, origin);
00078 }
00079 
00080 /*-------------------------------------------------------------------------*/
00081 /*                             Chunk                                       */
00082 
00083 void DirectionalLight::makeChunk(void)
00084 {
00085     Inherited::makeChunk();
00086 
00087     Vec4f dir(_sfDirection.getValue());
00088 
00089     dir[3] = 0;
00090    
00091     _pChunk->setPosition(dir);
00092 }
00093 
00094 /*-------------------------------------------------------------------------*/
00095 /*                                Dump                                     */
00096 
00097 void DirectionalLight::dump(      UInt32    uiIndent, 
00098                             const BitVector bvFlags) const
00099 {
00100    Inherited::dump(uiIndent, bvFlags);
00101 }
00102 
00103 /*-------------------------------------------------------------------------*/
00104 /*                            Constructors                                 */
00105 
00106 DirectionalLight::DirectionalLight(void) :
00107     Inherited()
00108 {
00109 }
00110 
00111 DirectionalLight::DirectionalLight(const DirectionalLight &source) :
00112     Inherited(source)
00113 {
00114 }
00115 
00116 /*-------------------------------------------------------------------------*/
00117 /*                             Destructor                                  */
00118 
00119 DirectionalLight::~DirectionalLight(void)
00120 {
00121 }
00122 
00123 /*-------------------------------------------------------------------------*/
00124 /*                               Drawing                                   */
00125 
00126 Action::ResultE DirectionalLight::drawEnter(Action *action)
00127 {   
00128     if(getOn() == false)
00129         return Action::Continue;
00130 
00131     DrawAction *da = dynamic_cast<DrawAction *>(action);
00132 
00133     GLenum light = GL_LIGHT0 + da->getLightCount();
00134     
00135     Light::drawEnter(action);
00136 
00137     Vec4f dir(_sfDirection.getValue());
00138 
00139     dir[3] = 0;
00140     
00141     glLightfv(light, GL_POSITION   , dir.getValues());
00142     glLightf (light, GL_SPOT_CUTOFF, 180.f          );
00143 
00144     glPopMatrix();
00145 
00146     da->getStatistics()->getElem(DirectionalLight::statNDirectionalLights)->inc();
00147 
00148     return Action::Continue;
00149 }
00150     
00151 Action::ResultE DirectionalLight::drawLeave(Action *action)
00152 {
00153     if(getOn() == false)
00154         return Action::Continue;
00155 
00156     return Light::drawLeave(action);
00157 }
00158 
00159 /*-------------------------------------------------------------------------*/
00160 /*                             Rendering                                   */
00161 
00162 Action::ResultE DirectionalLight::renderEnter(Action *action)
00163 {
00164     if(getOn() == false)
00165         return Action::Continue;
00166 
00167     DrawActionBase *da    = dynamic_cast<DrawActionBase *>(action);
00168     da->getStatistics()->getElem(DirectionalLight::statNDirectionalLights)->inc();
00169     
00170     return Light::renderEnter(action);
00171 }
00172 
00173 Action::ResultE DirectionalLight::renderLeave(Action *action)
00174 {
00175     if(getOn() == false)
00176         return Action::Continue;
00177 
00178     return Light::renderLeave(action);
00179 }
00180 
00181 /*-------------------------------------------------------------------------*/
00182 /*                               Init                                      */
00183 
00184 void DirectionalLight::initMethod (void)
00185 {
00186     DrawAction::registerEnterDefault( 
00187         getClassType(), 
00188         osgTypedMethodFunctor2BaseCPtrRef<
00189             Action::ResultE,
00190             DirectionalLightPtr  , 
00191             CNodePtr             ,  
00192             Action              *>(&DirectionalLight::drawEnter));
00193 
00194     DrawAction::registerLeaveDefault( 
00195         getClassType(), 
00196         osgTypedMethodFunctor2BaseCPtrRef<
00197             Action::ResultE,
00198             DirectionalLightPtr  , 
00199             CNodePtr             ,  
00200             Action              *>(&DirectionalLight::drawLeave));
00201 
00202     RenderAction::registerEnterDefault( 
00203         getClassType(), 
00204         osgTypedMethodFunctor2BaseCPtrRef<
00205             Action::ResultE,
00206             DirectionalLightPtr  , 
00207             CNodePtr             ,  
00208             Action              *>(&DirectionalLight::renderEnter));
00209 
00210     RenderAction::registerLeaveDefault(
00211         getClassType(), 
00212         osgTypedMethodFunctor2BaseCPtrRef<
00213             OSG::Action::ResultE,
00214             DirectionalLightPtr  , 
00215             CNodePtr             ,  
00216             Action              *>(&DirectionalLight::renderLeave));
00217 }
00218 
00219 
00220 /*-------------------------------------------------------------------------*/
00221 /*                              cvs id's                                   */
00222 
00223 #ifdef __sgi
00224 #pragma set woff 1174
00225 #endif
00226 
00227 #ifdef OSG_LINUX_ICC
00228 #pragma warning( disable : 177 )
00229 #endif
00230 
00231 namespace
00232 {
00233     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00234     static Char8 cvsid_hpp[] = OSGDIRECTIONALLIGHT_HEADER_CVSID;
00235     static Char8 cvsid_inl[] = OSGDIRECTIONALLIGHT_INLINE_CVSID;
00236 }

Generated on Thu Aug 25 04:02:48 2005 for OpenSG by  doxygen 1.4.3