opennurbs_light.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_LIGHT_INC_)
18 #define OPENNURBS_LIGHT_INC_
19 
20 class ON_CLASS ON_Light : public ON_Geometry
21 {
22  ON_OBJECT_DECLARE(ON_Light);
23 
24 public:
25  ON_Light();
26  ~ON_Light();
27  ON_Light& operator=(const ON_Light&) = default;
28  ON_Light(const ON_Light&) = default;
29 
30  static const ON_Light Unset;
31 
32  /////////////////////////////////////////////////////////////////
33  //
34  // ON_Object virtual functions
35  //
36 
37  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
38 
39  void Dump( ON_TextLog& ) const override; // for debugging
40 
41  // Use ON_BinaryArchive::WriteObject() and ON_BinaryArchive::ReadObject()
42  // for top level serialization. These Read()/Write() members should just
43  // write/read specific definitions. In particular, they should not write/
44  // read any chunk typecode or length information. The default
45  // implementations return false and do nothing.
46  bool Write(
47  ON_BinaryArchive& // serialize definition to binary archive
48  ) const override;
49 
50  bool Read(
51  ON_BinaryArchive& // restore definition from binary archive
52  ) override;
53 
54  ON::object_type ObjectType() const override;
55 
56  // virtual
57  ON_UUID ModelObjectId() const override;
58 
59 
60  /////////////////////////////////////////////////////////////////
61  //
62  // ON_Geometry virtual functions
63  //
64  int Dimension() const override;
65 
66  // virtual ON_Geometry GetBBox override
67  bool GetBBox( double* boxmin, double* boxmax, bool bGrowBox = false ) const override;
68 
69  bool Transform(
70  const ON_Xform&
71  ) override;
72 
73  /////////////////////////////////////////////////////////
74  //
75  // Interface
76  //
77 
78  void Default(); // make default light
79 
80  /////////////////////////////////////////////////////////
81  //
82  // turn light on/off
83  //
84  bool Enable( bool = true ); // returns previous state
85  bool IsEnabled() const;
86 
87  /////////////////////////////////////////////////////////
88  //
89  // style, location, and direction
90  // direction is ignored for "point" and "ambient" lights
91  // location is ignored for "directional" and "ambient" lights
92  void SetStyle(ON::light_style);
93  ON::light_style Style() const;
94 
95  const bool IsPointLight() const;
96  const bool IsDirectionalLight() const;
97  const bool IsSpotLight() const;
98  const bool IsLinearLight() const;
99  const bool IsRectangularLight() const;
100 
101  ON::coordinate_system CoordinateSystem() const; // determined by style
102 
103  /*
104  Description:
105  A light's location and direction can be defined with respect
106  to world, camera, or view coordinates. GetLightXform gets
107  the transformation from the light's intrinsic coordinate
108  system to the destination coordinate system specified
109  by dest_cs.
110  Parameters:
111  vp - [in] viewport where light is being used
112  dest_cs - [in] destination coordinate system
113  xform - [out] transformation from the light's intrinsic
114  coordinate system to cs.
115  Returns:
116  true if successful.
117  */
118  bool GetLightXform(
119  const ON_Viewport& vp,
120  ON::coordinate_system dest_cs,
121  ON_Xform& xform
122  ) const;
123 
124  void SetLocation( const ON_3dPoint& );
125  void SetDirection( const ON_3dVector& );
126 
127  ON_3dPoint Location() const;
128  ON_3dVector Direction() const;
129  ON_3dVector PerpindicularDirection() const;
130 
131  double Intensity() const; // 0.0 = 0% 1.0 = 100% Only clamped above zero - no maximum.
132  void SetIntensity(double);
133 
134  double PowerWatts() const;
135  double PowerLumens() const;
136  double PowerCandela() const;
137 
138  void SetPowerWatts( double );
139  void SetPowerLumens( double );
140  void SetPowerCandela( double );
141 
142  /////////////////////////////////////////////////////////
143  //
144  // colors
145  //
146  void SetAmbient( ON_Color );
147  void SetDiffuse( ON_Color );
148  void SetSpecular( ON_Color );
149  ON_Color Ambient() const;
150  ON_Color Diffuse() const;
151  ON_Color Specular() const;
152 
153  /////////////////////////////////////////////////////////
154  //
155  // attenuation settings (ignored for "directional" and "ambient" lights)
156  // attenuation = 1/(a[0] + d*a[1] + d^2*a[2]) where d = distance to light
157  //
158  void SetAttenuation(double,double,double);
159  void SetAttenuation(const ON_3dVector&);
160  ON_3dVector Attenuation() const;
161  double Attenuation(double) const; // computes 1/(a[0] + d*a[1] + d^2*a[2]) where d = argument
162  // returns 0 if a[0] + d*a[1] + d^2*a[2] <= 0
163 
164  /////////////////////////////////////////////////////////
165  //
166  // spot light parameters (ignored for non-spot lights)
167  //
168  // angle = 0 to 90 degrees
169  // exponent = 0 to 128 (0=uniform, 128=high focus)
170  //
171  void SetSpotAngleDegrees( double );
172  double SpotAngleDegrees() const;
173 
174  void SetSpotAngleRadians( double );
175  double SpotAngleRadians() const;
176 
177  //////////
178  // The spot exponent varies from 0.0 to 128.0 and provides
179  // an exponential interface for controling the focus or
180  // concentration of a spotlight (like the
181  // OpenGL GL_SPOT_EXPONENT parameter). The spot exponent
182  // and hot spot parameters are linked; changing one will
183  // change the other.
184  // A hot spot setting of 0.0 corresponds to a spot exponent of 128.
185  // A hot spot setting of 1.0 corresponds to a spot exponent of 0.0.
186  void SetSpotExponent( double );
187  double SpotExponent() const;
188 
189  //////////
190  // The hot spot setting runs from 0.0 to 1.0 and is used to
191  // provides a linear interface for controling the focus or
192  // concentration of a spotlight.
193  // A hot spot setting of 0.0 corresponds to a spot exponent of 128.
194  // A hot spot setting of 1.0 corresponds to a spot exponent of 0.0.
195  void SetHotSpot( double );
196  double HotSpot() const;
197 
198  // The spotlight radii are useful for display UI.
199  bool GetSpotLightRadii( double* inner_radius, double* outer_radius ) const;
200 
201 
202  /////////////////////////////////////////////////////////
203  //
204  // linear and rectangular light parameters
205  // (ignored for non-linear/rectangular lights)
206  //
207  void SetLength( const ON_3dVector& );
208  ON_3dVector Length() const;
209 
210  void SetWidth( const ON_3dVector& );
211  ON_3dVector Width() const;
212 
213  /////////////////////////////////////////////////////////
214  //
215  // shadow parameters (ignored for non-spot lights)
216  //
217  // shadow intensity 0.0 = does not cast any shadows
218  // 1.0 = casts black shadows
219  //
220  void SetShadowIntensity(double);
221  double ShadowIntensity() const;
222 
223 
224  /////////////////////////////////////////////////////////
225  //
226  // light index
227  //
228  void SetLightIndex( int );
229  int LightIndex() const;
230 
231  /////////////////////////////////////////////////////////
232  //
233  // light name
234  //
235  void SetLightName( const char* );
236  void SetLightName( const wchar_t* );
237  const ON_wString& LightName() const;
238 
239 public:
240  int m_light_index;
241  ON_UUID m_light_id;
242  ON_wString m_light_name;
244  bool m_bOn; // true if light is on
245  ON::light_style m_style; // style of light
247  ON_Color m_ambient;
248  ON_Color m_diffuse;
249  ON_Color m_specular;
250 
251  ON_3dVector m_direction; // ignored for "point" and "ambient" lights
252  ON_3dPoint m_location; // ignored for "directional" and "ambient" lights
253  ON_3dVector m_length; // only for linear and rectangular lights
254  // ends of linear lights are m_location and m_location+m_length
255  ON_3dVector m_width; // only for rectangular lights
256  // corners of rectangular lights are m_location, m_location+m_length,
257  // m_location+m_width, m_location+m_width+m_length
259  double m_intensity; // Linear dimming/brightening factor: 0.0 = off, 1.0 = 100%.
260  // Values < 0.0 and values > 1.0 are permitted but are
261  // not consistently interpreted by various renderers.
262  // Renderers should clamp the range to [0.0, 1.0] if their
263  // lighting model does not support more exotic interpretations
264  // of m_intensity.
265  double m_watts; // Used by lighting models that reference lighting fixtures.
266  // Values < 0.0 are invalid. If m_watts is 0.0, the
267  // value is ignored.
268 
269  // spot settings - ignored for non-spot lights
270  double m_spot_angle; // 0.0 to 90.0
271  double m_spot_exponent; // 0.0 to 128.0
272  // 0.0 = uniform
273  // 128.0 = high focus
274  double m_hotspot; // 0.0 to 1.0 (See SetHotSpot() for details)
275 
276  // attenuation settings - ignored for "directional" and "ambient" lights
277  ON_3dVector m_attenuation; // each entry >= 0.0
278  // att = 1/(a[0] + d*a[1] + d^2*a[2])
279  // where d = distance to light
280 
281  // shawdow casting
282  double m_shadow_intensity; // 0.0 = no shadow casting, 1.0 = full shadow casting
283 };
284 
285 
286 
287 #endif
virtual bool Transform(const ON_Xform &xform)
Transforms the object.
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
virtual int Dimension() const
Dimension of the object.
virtual bool GetBBox(double *boxmin, double *boxmax, bool bGrowBox=false) const
This is the virtual function that actually calculates axis aligned bounding boxes.
Definition: opennurbs_light.h:20
Definition: opennurbs_string.h:2020
virtual ON::object_type ObjectType() const
Useful for switch statements that need to differentiate between basic object types like points...
Base class for all geometry classes that must provide runtime class id. Provides interface for common...
Definition: opennurbs_geometry.h:37
Definition: opennurbs_color.h:24
Definition: opennurbs_xform.h:28
static const ON_Light Unset
Definition: opennurbs_light.h:30
virtual void Dump(ON_TextLog &) const
Creates a text dump of the object.
ON_Geometry & operator=(const ON_Geometry &)=default
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_viewport.h:31
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_point.h:460
bool IsValid(class ON_TextLog *text_log=nullptr) const override
Tests an object to see if its data members are correctly initialized.
virtual bool Write(ON_BinaryArchive &binary_archive) const
Low level archive writing tool used by ON_BinaryArchive::WriteObject().
virtual ON_UUID ModelObjectId() const
All objects in an opennurbs model have an id ( ON_Layer.m_layer_id, ON_Font.m_font_id, ON_Material.m_material_id, ON_3dmObjectAttributes.m_uuid ).
Definition: opennurbs_point.h:1152