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

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

Generated on Thu Aug 25 04:08:29 2005 for OpenSG by  doxygen 1.4.3