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 #include "OSGPointLight.h"
00049
00050 OSG_USING_NAMESPACE
00051
00060
00061
00062 StatElemDesc<StatIntElem> PointLight::statNPointLights(
00063 "NPointLights", "number of point light sources");
00064
00065
00066
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
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
00101
00102 void PointLight::changed(BitVector whichField, UInt32 origin)
00103 {
00104 Inherited::changed(whichField, origin);
00105 }
00106
00107
00108
00109
00110 void PointLight::dump( UInt32 uiIndent,
00111 const BitVector bvFlags) const
00112 {
00113 Inherited::dump(uiIndent, bvFlags);
00114 }
00115
00116
00117
00118
00119 PointLight::PointLight(void) :
00120 Inherited()
00121 {
00122 }
00123
00124 PointLight::PointLight(const PointLight &source) :
00125 Inherited(source)
00126 {
00127 }
00128
00129
00130
00131
00132 PointLight::~PointLight(void)
00133 {
00134 }
00135
00136
00137
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
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
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
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 }