Ocean
LightSource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_LIGHT_SOURCE_H
9 #define META_OCEAN_RENDERING_LIGHT_SOURCE_H
10 
12 #include "ocean/rendering/Object.h"
14 
15 #include "ocean/math/RGBAColor.h"
16 
17 namespace Ocean
18 {
19 
20 namespace Rendering
21 {
22 
23 // Forward declaration
24 class LightSource;
25 
26 /**
27  * Definition of a smart object reference holding a light source object.
28  * @see SmartObjectRef, LightSource.
29  * @ingroup rendering
30  */
32 
33 /**
34  * This is the base class for all lights.
35  * @ingroup rendering
36  */
37 class OCEAN_RENDERING_EXPORT LightSource : virtual public Object
38 {
39  public:
40 
41  /**
42  * Defines different transformation types.
43  */
45  {
46  /// The light is located in the coordinate system of the parent node, this is the default type.
48  /// The light is located in the world coordinate system (an absolute location).
49  TT_WORLD
50  };
51 
52  public:
53 
54  /**
55  * Returns the ambient color of this light source.
56  * @return Ambient color
57  * @exception NotSupportedException Is thrown if this function is not supported
58  */
59  virtual RGBAColor ambientColor() const;
60 
61  /**
62  * Returns the diffuse color of this light source.
63  * @return Diffuse color
64  * @exception NotSupportedException Is thrown if this function is not supported
65  */
66  virtual RGBAColor diffuseColor() const;
67 
68  /**
69  * Returns the specular color of this light source.
70  * @return Specular color
71  * @exception NotSupportedException Is thrown if this function is not supported
72  */
73  virtual RGBAColor specularColor() const;
74 
75  /**
76  * Returns the intensity of this light source.
77  * @return Light intensity with range [0.0, 1.0]
78  * @exception NotSupportedException Is thrown if this function is not supported
79  */
80  virtual Scalar intensity() const;
81 
82  /**
83  * Returns the transformation type of this light.
84  * @return The light's transformation type, TT_PARENT by default
85  * @exception NotSupportedException Is thrown if this function is not supported
86  */
88 
89  /**
90  * Returns whether this light source is enabled.
91  * @return True, if so
92  * @exception NotSupportedException Is thrown if this function is not supported
93  */
94  virtual bool enabled() const;
95 
96  /**
97  * Gets all color values of the light at once.
98  * @param ambient Resulting ambient color of this light source
99  * @param diffuse Resulting diffuse color of this light source
100  * @param specular Resulting specular color of this light source
101  * @param intensity Resulting intensity of this light source
102  * @exception NotSupportedException Is thrown if this function is not supported
103  */
104  virtual void get(RGBAColor& ambient, RGBAColor& diffuse, RGBAColor& specular, Scalar& intensity);
105 
106  /**
107  * Sets the ambient color of the light source.
108  * @param color Ambient color
109  * @return True, if the specified color is valid and could be set
110  * @exception NotSupportedException Is thrown if this function is not supported
111  */
112  virtual bool setAmbientColor(const RGBAColor& color);
113 
114  /**
115  * Sets the diffuse color of the light source.
116  * @param color Diffuse color
117  * @return True, if the specified color is valid and could be set
118  * @exception NotSupportedException Is thrown if this function is not supported
119  */
120  virtual bool setDiffuseColor(const RGBAColor& color);
121 
122  /**
123  * Sets the specular color of the light source.
124  * @param color Specular color
125  * @return True, if the specified color is valid and could be set
126  * @exception NotSupportedException Is thrown if this function is not supported
127  */
128  virtual bool setSpecularColor(const RGBAColor& color);
129 
130  /**
131  * Sets the specular exponent of this material.
132  * @param intensity Light intensity to set with range [0.0, 1.0]
133  * @return True, if the valud is valid and could be set
134  * @exception NotSupportedException Is thrown if this function is not supported
135  */
136  virtual bool setIntensity(const Scalar intensity);
137 
138  /**
139  * Sets all color values of the light source at once.
140  * @param ambient Ambient color to set
141  * @param diffuse Diffuse color to set
142  * @param specular Specular color to set
143  * @param intensity Intensity value to set
144  * @return True, if at least one value is valid and could be set
145  * @exception NotSupportedException Is thrown if this function is not supported
146  */
147  virtual bool set(const RGBAColor& ambient, const RGBAColor& diffuse, const RGBAColor& specular, const Scalar intensity);
148 
149  /**
150  * Sets the transformation type of this light.
151  * @param transformationType The transformation type to set
152  * @exception NotSupportedException Is thrown if this function is not supported
153  */
154  virtual void setTransformationType(const TransformationType transformationType);
155 
156  /**
157  * Sets whether the light source is enabled.
158  * @param state True, if the light source has to be enabled
159  * @exception NotSupportedException Is thrown if this function is not supported
160  */
161  virtual void setEnabled(const bool state);
162 
163  /**
164  * Returns the type of this object.
165  * @see Object::type().
166  */
167  ObjectType type() const override;
168 
169  protected:
170 
171  /**
172  * Creates a new light source object.
173  */
175 
176  /**
177  * Destructs a light source object.
178  */
179  ~LightSource() override;
180 };
181 
182 }
183 
184 }
185 
186 #endif // META_OCEAN_RENDERING_LIGHT_SOURCE_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This is the base class for all lights.
Definition: LightSource.h:38
virtual void setTransformationType(const TransformationType transformationType)
Sets the transformation type of this light.
ObjectType type() const override
Returns the type of this object.
virtual bool setIntensity(const Scalar intensity)
Sets the specular exponent of this material.
virtual void get(RGBAColor &ambient, RGBAColor &diffuse, RGBAColor &specular, Scalar &intensity)
Gets all color values of the light at once.
virtual RGBAColor specularColor() const
Returns the specular color of this light source.
virtual void setEnabled(const bool state)
Sets whether the light source is enabled.
virtual bool setSpecularColor(const RGBAColor &color)
Sets the specular color of the light source.
virtual bool enabled() const
Returns whether this light source is enabled.
virtual RGBAColor ambientColor() const
Returns the ambient color of this light source.
virtual bool setAmbientColor(const RGBAColor &color)
Sets the ambient color of the light source.
virtual Scalar intensity() const
Returns the intensity of this light source.
LightSource()
Creates a new light source object.
virtual bool set(const RGBAColor &ambient, const RGBAColor &diffuse, const RGBAColor &specular, const Scalar intensity)
Sets all color values of the light source at once.
~LightSource() override
Destructs a light source object.
TransformationType
Defines different transformation types.
Definition: LightSource.h:45
@ TT_PARENT
The light is located in the coordinate system of the parent node, this is the default type.
Definition: LightSource.h:47
virtual bool setDiffuseColor(const RGBAColor &color)
Sets the diffuse color of the light source.
virtual TransformationType transformationType() const
Returns the transformation type of this light.
virtual RGBAColor diffuseColor() const
Returns the diffuse color of this light source.
This class is the base class for all rendering objects.
Definition: Object.h:54
ObjectType
Definition of different object type.
Definition: Object.h:63
float Scalar
Definition of a scalar type.
Definition: Math.h:128
SmartObjectRef< LightSource > LightSourceRef
Definition of a smart object reference holding a light source object.
Definition: LightSource.h:24
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15