1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
14 * * * This library is free software; you can redistribute it and/or modify it *
15 * under the terms of the GNU Library General Public License as published *
16 * by the Free Software Foundation, version 2. *
18 * This library is distributed in the hope that it will be useful, but *
19 * WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
21 * Library General Public License for more details. *
23 * You should have received a copy of the GNU Library General Public *
24 * License along with this library; if not, write to the Free Software *
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 \*---------------------------------------------------------------------------*/
28 /*---------------------------------------------------------------------------*\
36 \*---------------------------------------------------------------------------*/
38 #ifndef _OSGMULTILIGHTCHUNK_H_
39 #define _OSGMULTILIGHTCHUNK_H_
44 #include "OSGMultiLightChunkBase.h"
48 struct OSG_SYSTEM_DLLMAPPING MultiLight
53 DIRECTIONAL_LIGHT
= 2,
59 SIMPLE_LAYOUT
= 0x01, // Color,Intensity,RangeCutOff
60 RANGE_LAYOUT
= 0x02, // RangeCutOn, RangeCutOff
61 ZONE_LAYOUT
= 0x04, // RangeNearZone, RangeFarZone
62 OPENGL_LAYOUT
= 0x08, // Ambient-, Diffuse-, Specular Intensity, Attenuation
63 CINEMA_LAYOUT
= 0x10 // SuperEllipses
66 explicit MultiLight(Type e
);
72 Vec3f ambientIntensity
;
73 Vec3f diffuseIntensity
;
74 Vec3f specularIntensity
;
76 Real32 spotlightAngle
;
78 Real32 innerSuperEllipsesWidth
;
79 Real32 innerSuperEllipsesHeight
;
80 Real32 outerSuperEllipsesWidth
;
81 Real32 outerSuperEllipsesHeight
;
82 Real32 superEllipsesRoundness
;
83 Real32 superEllipsesTwist
;
93 /*! \brief MultiLightChunk class. See \ref
94 PageSystemMultiLightChunk for a description.
97 class OSG_SYSTEM_DLLMAPPING MultiLightChunk
: public MultiLightChunkBase
101 /*========================== PUBLIC =================================*/
105 typedef MultiLightChunkBase Inherited
;
106 typedef MultiLightChunk Self
;
108 /*---------------------------------------------------------------------*/
109 /*! \name Interface */
112 UInt32
addLight (MultiLight::Type eType
);
113 UInt32
addLight (const MultiLight
& light
);
114 void updateLight (const UInt32 idx
, const MultiLight
& light
);
115 void removeLight (const UInt32 idx
);
117 UInt32
numLights () const;
118 void setLayoutType (UInt32 layout
);
120 const Pnt3f
&getPosition (const UInt32 idx
) const;
121 const Vec3f
&getDirection (const UInt32 idx
) const;
122 const Color3f
&getColor (const UInt32 idx
) const;
123 Real32
getIntensity (const UInt32 idx
) const;
124 const Vec3f
&getAmbientIntensity (const UInt32 idx
) const;
125 const Vec3f
&getDiffuseIntensity (const UInt32 idx
) const;
126 const Vec3f
&getSpecularIntensity (const UInt32 idx
) const;
127 const Vec3f
&getAttenuation (const UInt32 idx
) const;
128 Real32
getRange (const UInt32 idx
) const;
129 Real32
getSpotlightAngle (const UInt32 idx
) const;
130 Real32
getSpotExponent (const UInt32 idx
) const;
131 Real32
getInnerSuperEllipsesWidth (const UInt32 idx
) const;
132 Real32
getInnerSuperEllipsesHeight (const UInt32 idx
) const;
133 Real32
getOuterSuperEllipsesWidth (const UInt32 idx
) const;
134 Real32
getOuterSuperEllipsesHeight (const UInt32 idx
) const;
135 Real32
getSuperEllipsesRoundness (const UInt32 idx
) const;
136 Real32
getSuperEllipsesTwist (const UInt32 idx
) const;
137 Real32
getRangeCutOn (const UInt32 idx
) const;
138 Real32
getRangeCutOff (const UInt32 idx
) const;
139 Real32
getRangeNearZone (const UInt32 idx
) const;
140 Real32
getRangeFarZone (const UInt32 idx
) const;
141 UInt8
getType (const UInt32 idx
) const;
142 bool getEnabled (const UInt32 idx
) const;
143 Node
* getBeacon (const UInt32 idx
) const;
145 void setPosition (const UInt32 idx
, const Pnt3f
& position
);
146 void setDirection (const UInt32 idx
, const Vec3f
& direction
);
147 void setColor (const UInt32 idx
, const Color3f
& color
);
148 void setIntensity (const UInt32 idx
, Real32 intensity
);
149 void setAmbientIntensity (const UInt32 idx
, const Vec3f
& intensity
);
150 void setDiffuseIntensity (const UInt32 idx
, const Vec3f
& intensity
);
151 void setSpecularIntensity (const UInt32 idx
, const Vec3f
& intensity
);
152 void setAttenuation (const UInt32 idx
, const Vec3f
& attenuation
);
153 void setRange (const UInt32 idx
, Real32 range
);
154 void setSpotlightAngle (const UInt32 idx
, Real32 angle
);
155 void setSpotExponent (const UInt32 idx
, Real32 exponent
);
156 void setInnerSuperEllipsesWidth (const UInt32 idx
, Real32 width
);
157 void setInnerSuperEllipsesHeight (const UInt32 idx
, Real32 height
);
158 void setOuterSuperEllipsesWidth (const UInt32 idx
, Real32 width
);
159 void setOuterSuperEllipsesHeight (const UInt32 idx
, Real32 height
);
160 void setSuperEllipsesRoundness (const UInt32 idx
, Real32 roundness
);
161 void setSuperEllipsesTwist (const UInt32 idx
, Real32 twist
);
162 void setRangeCutOn (const UInt32 idx
, Real32 cutOn
);
163 void setRangeCutOff (const UInt32 idx
, Real32 cutOff
);
164 void setRangeNearZone (const UInt32 idx
, Real32 nearZone
);
165 void setRangeFarZone (const UInt32 idx
, Real32 farZone
);
166 void setType (const UInt32 idx
, MultiLight::Type eType
);
167 void setEnabled (const UInt32 idx
, bool flag
);
168 void setBeacon (const UInt32 idx
, Node
* const beacon
);
170 void changedBeacon ();
172 std::string
getLightProgSnippet () const;
176 /*---------------------------------------------------------------------*/
180 virtual void changed(ConstFieldMaskArg whichField
,
185 /*---------------------------------------------------------------------*/
189 virtual void dump( UInt32 uiIndent
= 0,
190 const BitVector bvFlags
= 0) const;
193 /*---------------------------------------------------------------------*/
197 virtual void activate (DrawEnv
*pEnv
,
200 virtual void changeFrom (DrawEnv
*pEnv
,
204 virtual void deactivate (DrawEnv
*pEnv
,
208 /*---------------------------------------------------------------------*/
209 /*! \name OpenGL handling */
212 /*========================= PROTECTED ===============================*/
217 ChangedFunctor _cameraCB
;
219 // Variables should all be in MultiLightChunkBase.
221 void onCreate (const MultiLightChunk
*source
= NULL
);
222 void onCreateAspect(const MultiLightChunk
*createAspect
,
223 const MultiLightChunk
*source
= NULL
);
224 void onDestroy ( UInt32 uiContainerId
);
226 /*---------------------------------------------------------------------*/
227 /*! \name Constructors */
230 MultiLightChunk(void);
231 MultiLightChunk(const MultiLightChunk
&source
);
234 /*---------------------------------------------------------------------*/
235 /*! \name Destructors */
238 virtual ~MultiLightChunk(void);
241 /*---------------------------------------------------------------------*/
245 static void initMethod(InitPhase ePhase
);
248 /*========================== PRIVATE ================================*/
252 friend class FieldContainer
;
253 friend class MultiLightChunkBase
;
255 /*---------------------------------------------------------------------*/
258 void transformToWorldSpace (DrawEnv
* pEnv
,
260 const Pnt3f
& position_bs
,
261 const Vec3f
& direction_bs
,
263 Vec3f
& direction_ws
) const;
265 void transformToEyeSpace (DrawEnv
* pEnv
,
267 const Pnt3f
& position_bs
,
268 const Vec3f
& direction_bs
,
270 Vec3f
& direction_es
) const;
272 void calcDirectionalLightMatrices (DrawEnv
* pEnv
,
274 const Vec3f
& direction_bs
,
276 Matrix
& matLSFromES
) const;
278 void calcPointLightMatrices (DrawEnv
* pEnv
,
280 const Pnt3f
& position_bs
,
282 Matrix
& matLSFromES
) const;
284 void calcSpotLightMatrices (DrawEnv
* pEnv
,
286 const Pnt3f
& position_bs
,
287 const Vec3f
& direction_bs
,
289 Matrix
& matLSFromES
) const;
291 void calcPointLightRange (DrawEnv
* pEnv
,
292 const Vec3f attenuation
,
295 Real32
& outFar
) const;
297 std::size_t calcLightBufferSize () const;
298 std::vector
<UInt8
> createLightBuffer (DrawEnv
* pEnv
) const;
299 void createLightState (DrawEnv
* pEnv
);
300 void updateLightState (DrawEnv
* pEnv
);
304 bool check_invariant() const;
306 // prohibit default functions (move to 'public' if you need one)
307 void operator =(const MultiLightChunk
&source
);
310 typedef MultiLightChunk
*MultiLightChunkP
;
314 #include "OSGMultiLightChunkBase.inl"
315 #include "OSGMultiLightChunk.inl"
317 #endif /* _OSGMULTILIGHTCHUNK_H_ */