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

OSGLightChunk.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; ifnot, 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 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include "OSGConfig.h"
00047 
00048 #include <OSGGL.h>
00049 #include <OSGGLU.h>
00050 
00051 #include "OSGLightChunk.h"
00052 
00053 OSG_USING_NAMESPACE
00054 
00055 
00056 /***************************************************************************\
00057  *                            Description                                  *
00058 \***************************************************************************/
00059 
00075 /***************************************************************************\
00076  *                           Class variables                               *
00077 \***************************************************************************/
00078 
00079 StateChunkClass LightChunk::_class("Light", 8);
00080 
00081 /***************************************************************************\
00082  *                           Class methods                                 *
00083 \***************************************************************************/
00084 
00085 /*-------------------------------------------------------------------------*\
00086  -  private                                                                -
00087 \*-------------------------------------------------------------------------*/
00088 
00089 void LightChunk::initMethod (void)
00090 {
00091 }
00092 
00093 /***************************************************************************\
00094  *                           Instance methods                              *
00095 \***************************************************************************/
00096 
00097 /*-------------------------------------------------------------------------*\
00098  -  public                                                                 -
00099 \*-------------------------------------------------------------------------*/
00100 
00101 
00102 /*------------- constructors & destructors --------------------------------*/
00103 
00104 LightChunk::LightChunk(void) :
00105     Inherited()
00106 {
00107 }
00108 
00109 LightChunk::LightChunk(const LightChunk &source) :
00110     Inherited(source)
00111 {
00112 }
00113 
00114 LightChunk::~LightChunk(void)
00115 {
00116 }
00117 
00118 /*------------------------- Chunk Class Access ---------------------------*/
00119 
00120 const StateChunkClass *LightChunk::getClass(void) const
00121 {
00122     return &_class;
00123 }
00124 
00125 /*------------------------------- Sync -----------------------------------*/
00126 
00127 void LightChunk::changed(BitVector whichField, UInt32 origin)
00128 {
00129     Inherited::changed(whichField, origin);
00130 }
00131 
00132 /*------------------------------ Output ----------------------------------*/
00133 
00134 void LightChunk::dump(      UInt32    OSG_CHECK_ARG(uiIndent),
00135                       const BitVector OSG_CHECK_ARG(bvFlags )) const
00136 {
00137     SLOG << "Dump LightChunk NI" << std::endl;
00138 }
00139 
00140 
00141 /*------------------------------ State ------------------------------------*/
00142 
00143 void LightChunk::activate(DrawActionBase *, UInt32 index)
00144 {
00145     glErr("light:activate:precheck");
00146 
00147     glLightfv(GL_LIGHT0 + index, GL_DIFFUSE,
00148                             _sfDiffuse.getValue().getValuesRGBA());
00149     glLightfv(GL_LIGHT0 + index, GL_AMBIENT,
00150                             _sfAmbient.getValue().getValuesRGBA());
00151     glLightfv(GL_LIGHT0 + index, GL_SPECULAR,
00152                             _sfSpecular.getValue().getValuesRGBA());
00153     glLightfv(GL_LIGHT0 + index, GL_POSITION,
00154                             _sfPosition.getValue().getValues());
00155     glLightf (GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION,
00156                             _sfConstantAttenuation.getValue());
00157     glLightf (GL_LIGHT0 + index, GL_LINEAR_ATTENUATION,
00158                             _sfLinearAttenuation.getValue());
00159     glLightf (GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION,
00160                             _sfQuadraticAttenuation.getValue());
00161 
00162     glLightf( GL_LIGHT0 + index, GL_SPOT_CUTOFF, _sfCutoff.getValue());
00163 
00164     if(_sfCutoff.getValue() < 180)
00165     {
00166         glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION,
00167                                         _sfDirection.getValue().getValues());
00168         glLightf( GL_LIGHT0 + index, GL_SPOT_EXPONENT, _sfExponent.getValue());
00169     }
00170     glEnable(GL_LIGHT0 + index);
00171 
00172     glErr("light:activate:postcheck");
00173 }
00174 
00175 void LightChunk::changeFrom(DrawActionBase *, StateChunk * old_chunk, UInt32 index)
00176 {
00177     glErr("light:changed:precheck");
00178 
00179     LightChunk const *old = dynamic_cast<LightChunk const*>(old_chunk);
00180 
00181     // change from me to me?
00182     // this assumes I haven't changed in the meantime. is that a valid assumption?
00183     if(old == this)
00184         return;
00185 
00186     // it could theoretically be more efficient to turn the light off before
00187     // changing its parameters, have to try that sometime
00188     glLightfv(GL_LIGHT0 + index, GL_DIFFUSE,
00189                             _sfDiffuse.getValue().getValuesRGBA());
00190     glLightfv(GL_LIGHT0 + index, GL_AMBIENT,
00191                             _sfAmbient.getValue().getValuesRGBA());
00192     glLightfv(GL_LIGHT0 + index, GL_SPECULAR,
00193                             _sfSpecular.getValue().getValuesRGBA());
00194     glLightfv(GL_LIGHT0 + index, GL_POSITION,
00195                             _sfPosition.getValue().getValues());
00196     glLightf (GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION,
00197                             _sfConstantAttenuation.getValue());
00198     glLightf (GL_LIGHT0 + index, GL_LINEAR_ATTENUATION,
00199                             _sfLinearAttenuation.getValue());
00200     glLightf (GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION,
00201                             _sfQuadraticAttenuation.getValue());
00202 
00203     glLightf( GL_LIGHT0 + index, GL_SPOT_CUTOFF, _sfCutoff.getValue());
00204     if(_sfCutoff.getValue() < 180)
00205     {
00206         glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION,
00207                                         _sfDirection.getValue().getValues());
00208         glLightf( GL_LIGHT0 + index, GL_SPOT_EXPONENT, _sfExponent.getValue());
00209     }
00210 
00211     glErr("light:changed:postcheck");
00212 }
00213 
00214 void LightChunk::deactivate(DrawActionBase *, UInt32 index)
00215 {
00216     glDisable(GL_LIGHT0 + index);
00217 }
00218 
00219 
00220 /*-------------------------- Comparison -----------------------------------*/
00221 
00222 Real32 LightChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00223 {
00224     return 0;
00225 }
00226 
00227 bool LightChunk::operator < (const StateChunk &other) const
00228 {
00229     return this < &other;
00230 }
00231 
00232 bool LightChunk::operator == (const StateChunk &other) const
00233 {
00234     LightChunk const *tother = dynamic_cast<LightChunk const*>(&other);
00235 
00236     if(!tother)
00237         return false;
00238 
00239     if(tother == this)
00240         return true;
00241 
00242     if(!getAmbient  ().equals(tother->getAmbient  (), Eps) ||
00243        !getDiffuse  ().equals(tother->getDiffuse  (), Eps) ||
00244        !getSpecular ().equals(tother->getSpecular (), Eps) ||
00245        !getPosition ().equals(tother->getPosition (), Eps) ||
00246        !getDirection().equals(tother->getDirection(), Eps) ||
00247         getConstantAttenuation()  != tother->getConstantAttenuation()  ||
00248         getLinearAttenuation()    != tother->getLinearAttenuation()    ||
00249         getQuadraticAttenuation() != tother->getQuadraticAttenuation() ||
00250         getCutoff()               != tother->getCutoff()               ||
00251         getExponent()             != tother->getExponent()
00252       )
00253         return false;
00254 
00255     return true;
00256 }
00257 
00258 bool LightChunk::operator != (const StateChunk &other) const
00259 {
00260     return ! (*this == other);
00261 }
00262 
00263 /*------------------------------------------------------------------------*/
00264 /*                              cvs id's                                  */
00265 
00266 #ifdef OSG_SGI_CC
00267 #pragma set woff 1174
00268 #endif
00269 
00270 #ifdef OSG_LINUX_ICC
00271 #pragma warning( disable : 177 )
00272 #endif
00273 
00274 namespace
00275 {
00276     static Char8 cvsid_cpp       [] = "@(#)$Id: FCTemplate_cpp.h,v 1.13 2002/06/01 10:37:25 vossg Exp $";
00277     static Char8 cvsid_hpp       [] = OSGLIGHTCHUNK_HEADER_CVSID;
00278     static Char8 cvsid_inl       [] = OSGLIGHTCHUNK_INLINE_CVSID;
00279 
00280     static Char8 cvsid_fields_hpp[] = OSGLIGHTCHUNKFIELDS_HEADER_CVSID;
00281 }
00282 
00283 #ifdef __sgi
00284 #pragma reset woff 1174
00285 #endif
00286 
00287 

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