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 "OSGLight.h"
00049
00050 OSG_USING_NAMESPACE
00051
00063
00064
00065
00066 void Light::setAmbient(Real32 rRed,
00067 Real32 rGreen,
00068 Real32 rBlue,
00069 Real32 rAlpha)
00070 {
00071 _sfAmbient.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
00072 }
00073
00074 void Light::setDiffuse(Real32 rRed,
00075 Real32 rGreen,
00076 Real32 rBlue,
00077 Real32 rAlpha)
00078 {
00079 _sfDiffuse.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
00080 }
00081
00082 void Light::setSpecular(Real32 rRed,
00083 Real32 rGreen,
00084 Real32 rBlue,
00085 Real32 rAlpha)
00086 {
00087 _sfSpecular.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
00088 }
00089
00090
00091
00092
00093 LightChunkPtr Light::getChunk(void)
00094 {
00095 return _pChunk;
00096 }
00097
00098 void Light::makeChunk(void)
00099 {
00100 if(_pChunk == NullFC)
00101 {
00102 _pChunk = LightChunk::create();
00103 }
00104
00105 _pChunk->setAmbient (getAmbient ());
00106 _pChunk->setDiffuse (getDiffuse ());
00107 _pChunk->setSpecular(getSpecular());
00108 }
00109
00110
00111
00112
00113 void Light::changed(BitVector whichField, UInt32 origin)
00114 {
00115 Inherited::changed(whichField, origin);
00116 }
00117
00118
00119
00120
00121
00122 void Light::dump( UInt32 uiIndent,
00123 const BitVector bvFlags) const
00124 {
00125 Inherited::dump(uiIndent, bvFlags);
00126 }
00127
00128
00129
00130
00131 Light::Light(void) :
00132 Inherited(),
00133 _pChunk (NullFC)
00134 {
00135 }
00136
00137 Light::Light(const Light &source) :
00138 Inherited(source),
00139 _pChunk (source._pChunk)
00140 {
00141 }
00142
00143
00144
00145
00146 Light::~Light(void)
00147 {
00148 if(_pChunk != NullFC)
00149 subRefCP(_pChunk);
00150 }
00151
00152
00153
00154
00155 Action::ResultE Light::drawEnter(Action *action)
00156 {
00157 DrawAction *da = dynamic_cast<DrawAction *>(action);
00158 GLenum light = GL_LIGHT0 + da->getLightCount();
00159
00160 da->incLightCount();
00161
00162 glEnable (light);
00163
00164 glLightfv(light, GL_DIFFUSE , _sfDiffuse. getValue().getValuesRGBA());
00165 glLightfv(light, GL_AMBIENT , _sfAmbient. getValue().getValuesRGBA());
00166 glLightfv(light, GL_SPECULAR, _sfSpecular.getValue().getValuesRGBA());
00167
00168 glLightf( light,
00169 GL_CONSTANT_ATTENUATION,
00170 _sfConstantAttenuation.getValue() );
00171 glLightf( light,
00172 GL_LINEAR_ATTENUATION,
00173 _sfLinearAttenuation.getValue() );
00174 glLightf( light,
00175 GL_QUADRATIC_ATTENUATION,
00176 _sfQuadraticAttenuation.getValue());
00177
00178
00179
00180 Matrix fromworld;
00181 Matrix tobeacon;
00182
00183 action->getActNode()->getToWorld(fromworld);
00184 fromworld.invert();
00185
00186 NodePtr beacon = getBeacon();
00187
00188 if(beacon == NullFC)
00189 {
00190 SINFO << "draw: no beacon set!" << std::endl;
00191
00192 glPushMatrix();
00193 }
00194 else
00195 {
00196 getBeacon()->getToWorld(tobeacon);
00197
00198 tobeacon.mult(fromworld);
00199
00200 glPushMatrix();
00201 glMultMatrixf(tobeacon.getValues());
00202 }
00203
00204 da->selectVisibles();
00205
00206 return Action::Continue;
00207 }
00208
00209 Action::ResultE Light::drawLeave(Action *action)
00210 {
00211 DrawAction *da = dynamic_cast<DrawAction *>(action);
00212
00213 da->decLightCount();
00214
00215 GLenum light = GL_LIGHT0 + da->getLightCount();
00216
00217 glDisable(light);
00218
00219 return Action::Continue;
00220 }
00221
00222
00223
00224
00225 Action::ResultE Light::renderEnter(Action *action)
00226 {
00227 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00228
00229 pAction->dropLight(this);
00230
00231 return Action::Continue;
00232 }
00233
00234 Action::ResultE Light::renderLeave(Action *action)
00235 {
00236 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
00237
00238 pAction->undropLight(this);
00239
00240 return Action::Continue;
00241 }
00242
00243
00244
00245
00247
00248 void Light::initMethod(void)
00249 {
00250 }
00251
00252
00253
00254
00255
00256 #ifdef __sgi
00257 #pragma set woff 1174
00258 #endif
00259
00260 #ifdef OSG_LINUX_ICC
00261 #pragma warning( disable : 177 )
00262 #endif
00263
00264 namespace
00265 {
00266 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00267 static Char8 cvsid_hpp[] = OSGLIGHT_HEADER_CVSID;
00268 static Char8 cvsid_inl[] = OSGLIGHT_INLINE_CVSID;
00269 }
00270