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 "OSGNodePtr.h"
00047 #include "OSGDirectionalLight.h"
00048 #include <OSGDrawAction.h>
00049 #include <OSGRenderAction.h>
00050
00051 OSG_USING_NAMESPACE
00052
00058
00059
00060 StatElemDesc<StatIntElem> DirectionalLight::statNDirectionalLights(
00061 "NDirectionalLights", "number of directional light sources");
00062
00063
00064
00065
00066
00067 void DirectionalLight::setDirection(Real32 rX, Real32 rY, Real32 rZ)
00068 {
00069 _sfDirection.getValue().setValues(rX, rY, rZ);
00070 }
00071
00072
00073
00074
00075 void DirectionalLight::changed(BitVector whichField, UInt32 origin)
00076 {
00077 Inherited::changed(whichField, origin);
00078 }
00079
00080
00081
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
00096
00097 void DirectionalLight::dump( UInt32 uiIndent,
00098 const BitVector bvFlags) const
00099 {
00100 Inherited::dump(uiIndent, bvFlags);
00101 }
00102
00103
00104
00105
00106 DirectionalLight::DirectionalLight(void) :
00107 Inherited()
00108 {
00109 }
00110
00111 DirectionalLight::DirectionalLight(const DirectionalLight &source) :
00112 Inherited(source)
00113 {
00114 }
00115
00116
00117
00118
00119 DirectionalLight::~DirectionalLight(void)
00120 {
00121 }
00122
00123
00124
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
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
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
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 }