fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Light / OSGPointLight.cpp
blob9873ad154f5bac2933ca28c5fae7101d3c24fb17
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGGL.h"
46 #include "OSGRenderAction.h"
47 #include "OSGPointLight.h"
49 #include "OSGStatCollector.h"
51 OSG_USING_NAMESPACE
53 // Documentation for this class is emited in the
54 // OSGPointLightBase.cpp file.
55 // To modify it, please change the .fcd file (OSGPointLight.fcd) and
56 // regenerate the base file.
58 /*----------------------------- class variables ---------------------------*/
60 StatElemDesc<StatIntElem> PointLight::statNPointLights(
61 "NPointLights",
62 "number of point light sources");
64 /*-------------------------------------------------------------------------*/
65 /* Set */
67 void PointLight::setPosition(Real32 rX, Real32 rY, Real32 rZ)
69 editSField(PositionFieldMask);
71 _sfPosition.getValue().setValues(rX, rY, rZ);
74 void PointLight::setAttenuation(Real32 rConstant,
75 Real32 rLinear,
76 Real32 rQuadratic)
78 editSField(ConstantAttenuationFieldMask );
79 editSField(LinearAttenuationFieldMask );
80 editSField(QuadraticAttenuationFieldMask);
82 _sfConstantAttenuation .setValue(rConstant );
83 _sfLinearAttenuation .setValue(rLinear );
84 _sfQuadraticAttenuation.setValue(rQuadratic);
87 /*-------------------------------------------------------------------------*/
88 /* Chunk */
90 void PointLight::makeChunk(void)
92 Inherited::makeChunk();
94 Vec4f pos(_sfPosition.getValue());
96 pos[3] = 1.f;
98 _pChunk->setPosition (pos );
99 _pChunk->setConstantAttenuation (getConstantAttenuation ());
100 _pChunk->setLinearAttenuation (getLinearAttenuation ());
101 _pChunk->setQuadraticAttenuation(getQuadraticAttenuation());
104 /*-------------------------------------------------------------------------*/
105 /* Changed */
107 void PointLight::changed(ConstFieldMaskArg whichField,
108 UInt32 origin,
109 BitVector details)
111 Inherited::changed(whichField, origin, details);
114 /*-------------------------------------------------------------------------*/
115 /* Dump */
117 void PointLight::dump( UInt32 uiIndent,
118 const BitVector bvFlags) const
120 Inherited::dump(uiIndent, bvFlags);
123 /*-------------------------------------------------------------------------*/
124 /* LightEngine */
126 void PointLight::callLightEngineEnter(RenderAction *ract)
128 if(getLightEngine() != NULL && getLightEngine()->getEnabled() == true)
130 getLightEngine()->runOnEnter(this, LightEngine::Point, ract);
134 void PointLight::callLightEngineLeave(RenderAction *ract)
136 if(getLightEngine() != NULL && getLightEngine()->getEnabled() == true)
138 getLightEngine()->runOnLeave(this, LightEngine::Point, ract);
142 /*-------------------------------------------------------------------------*/
143 /* Constructors */
145 PointLight::PointLight(void) :
146 Inherited()
150 PointLight::PointLight(const PointLight &source) :
151 Inherited(source)
155 /*-------------------------------------------------------------------------*/
156 /* Destructor */
158 PointLight::~PointLight(void)
162 /*-------------------------------------------------------------------------*/
163 /* Rendering */
165 Action::ResultE PointLight::renderEnter(Action *action)
167 RenderAction *a = dynamic_cast<RenderAction *>(action);
169 return Inherited::renderEnter(LightEngine::Point,
170 PointLight::statNPointLights,
174 Action::ResultE PointLight::renderLeave(Action *action)
176 return Inherited::renderLeave(LightEngine::Point,
177 action);
180 /*-------------------------------------------------------------------------*/
181 /* Init */
183 void PointLight::initMethod(InitPhase ePhase)
185 Inherited::initMethod(ePhase);
187 if(ePhase == TypeObject::SystemPost)
189 RenderAction::registerEnterDefault(
190 PointLight::getClassType(),
191 reinterpret_cast<Action::Callback>(&PointLight::renderEnter));
193 RenderAction::registerLeaveDefault(
194 PointLight::getClassType(),
195 reinterpret_cast<Action::Callback>(&PointLight::renderLeave));