00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00066
00067 StatElemDesc<StatIntElem> SpotLight::statNSpotLights(
00068 "NSpotLights", "number of spot light sources");
00069
00070
00071
00072
00073 void SpotLight::changed(BitVector whichField, UInt32 origin)
00074 {
00075 Inherited::changed(whichField, origin);
00076 }
00077
00078
00079
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
00098
00099 void SpotLight::dump( UInt32 uiIndent,
00100 const BitVector bvFlags) const
00101 {
00102 Inherited::dump(uiIndent, bvFlags);
00103 }
00104
00105
00106
00107
00108 SpotLight::SpotLight(void) :
00109 Inherited()
00110 {
00111 }
00112
00113 SpotLight::SpotLight(const SpotLight &source) :
00114 Inherited(source)
00115 {
00116 }
00117
00118
00119
00120
00121 SpotLight::~SpotLight(void)
00122 {
00123 }
00124
00125
00126
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
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
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
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 }