fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Light / OSGDirectionalLight.cpp
blob9fb59613393d415c22ed6989de379940bc6a31c0
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 "OSGDirectionalLight.h"
47 #include "OSGRenderAction.h"
49 #include "OSGStatCollector.h"
51 OSG_USING_NAMESPACE
53 // Documentation for this class is emited in the
54 // OSGDirectionalLightBase.cpp file.
55 // To modify it, please change the .fcd file (OSGDirectionalLight.fcd) and
56 // regenerate the base file.
58 /*----------------------------- class variables ---------------------------*/
60 StatElemDesc<StatIntElem> DirectionalLight::statNDirectionalLights(
61 "NDirectionalLights",
62 "number of directional light sources");
65 /*-------------------------------------------------------------------------*/
66 /* Set */
68 void DirectionalLight::setDirection(Real32 rX, Real32 rY, Real32 rZ)
70 editSField(DirectionFieldMask);
72 _sfDirection.getValue().setValues(rX, rY, rZ);
75 /*-------------------------------------------------------------------------*/
76 /* Changed */
78 void DirectionalLight::changed(ConstFieldMaskArg whichField,
79 UInt32 origin,
80 BitVector details)
82 Inherited::changed(whichField, origin, details);
85 /*-------------------------------------------------------------------------*/
86 /* Chunk */
88 void DirectionalLight::makeChunk(void)
90 Inherited::makeChunk();
92 Vec4f dir(_sfDirection.getValue());
94 dir[3] = 0.f;
96 _pChunk->setPosition(dir);
99 /*-------------------------------------------------------------------------*/
100 /* LightEngine */
102 void DirectionalLight::callLightEngineEnter(RenderAction *ract)
104 if(getLightEngine() != NULL && getLightEngine()->getEnabled() == true)
106 getLightEngine()->runOnEnter(this, LightEngine::Directional, ract);
110 void DirectionalLight::callLightEngineLeave(RenderAction *ract)
112 if(getLightEngine() != NULL && getLightEngine()->getEnabled() == true)
114 getLightEngine()->runOnLeave(this, LightEngine::Directional, ract);
118 /*-------------------------------------------------------------------------*/
119 /* Dump */
121 void DirectionalLight::dump( UInt32 uiIndent,
122 const BitVector bvFlags) const
124 Inherited::dump(uiIndent, bvFlags);
127 /*-------------------------------------------------------------------------*/
128 /* Constructors */
130 DirectionalLight::DirectionalLight(void) :
131 Inherited()
135 DirectionalLight::DirectionalLight(const DirectionalLight &source) :
136 Inherited(source)
140 /*-------------------------------------------------------------------------*/
141 /* Destructor */
143 DirectionalLight::~DirectionalLight(void)
147 /*-------------------------------------------------------------------------*/
148 /* Rendering */
150 Action::ResultE DirectionalLight::renderEnter(Action *action)
152 RenderAction *a = dynamic_cast<RenderAction *>(action);
154 return Inherited::renderEnter(LightEngine::Directional,
155 DirectionalLight::statNDirectionalLights,
159 Action::ResultE DirectionalLight::renderLeave(Action *action)
161 return Inherited::renderLeave(LightEngine::Directional, action);
164 /*-------------------------------------------------------------------------*/
165 /* Init */
167 void DirectionalLight::initMethod(InitPhase ePhase)
169 Inherited::initMethod(ePhase);
171 if(ePhase == TypeObject::SystemPost)
173 RenderAction::registerEnterDefault(
174 DirectionalLight::getClassType(),
175 reinterpret_cast<Action::Callback>(
176 &DirectionalLight::renderEnter));
178 RenderAction::registerLeaveDefault(
179 DirectionalLight::getClassType(),
180 reinterpret_cast<Action::Callback>(
181 &DirectionalLight::renderLeave));