OpenCMISS-Zinc C++ API Documentation
light.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_LIGHT_HPP__
10 #define CMZN_LIGHT_HPP__
11 
12 #include "opencmiss/zinc/light.h"
13 #include "opencmiss/zinc/context.hpp"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
28 class Light
29 {
30 protected:
31  cmzn_light_id id;
32 
33 public:
34 
35  Light() : id(0)
36  { }
37 
38  // takes ownership of C handle, responsibility for desLIGHTexplicit Light(cmzn_light_id in_light_id) :
39  explicit Light(cmzn_light_id light_id) :
40  id(light_id)
41  { }
42 
43  Light(const Light& light) :
44  id(cmzn_light_access(light.id))
45  { }
46 
47  Light& operator=(const Light& light)
48  {
49  cmzn_light_id temp_id = cmzn_light_access(light.id);
50  if (0 != id)
51  {
52  cmzn_light_destroy(&id);
53  }
54  id = temp_id;
55  return *this;
56  }
57 
58  ~Light()
59  {
60  if (0 != id)
61  {
62  cmzn_light_destroy(&id);
63  }
64  }
65 
71  bool isValid() const
72  {
73  return (0 != id);
74  }
75 
79  enum Type
80  {
81  TYPE_INVALID = CMZN_LIGHT_TYPE_INVALID,
83  TYPE_AMBIENT = CMZN_LIGHT_TYPE_AMBIENT,
86  TYPE_DIRECTIONAL = CMZN_LIGHT_TYPE_DIRECTIONAL,
89  TYPE_POINT = CMZN_LIGHT_TYPE_POINT,
92  TYPE_SPOT = CMZN_LIGHT_TYPE_SPOT
95  };
96 
102  cmzn_light_id getId() const
103  {
104  return id;
105  }
106 
113  bool isManaged()
114  {
115  return cmzn_light_is_managed(id);
116  }
117 
130  int setManaged(bool value)
131  {
132  return cmzn_light_set_managed(id, value);
133  }
134 
140  enum Type getType()
141  {
142  return static_cast<Type>(cmzn_light_get_type(id));
143  }
144 
151  int setType(enum Type type)
152  {
153  return cmzn_light_set_type(id, static_cast<cmzn_light_type>(type));
154  }
155 
162  char *getName()
163  {
164  return cmzn_light_get_name(id);
165  }
166 
174  int setName(const char *name)
175  {
176  return cmzn_light_set_name(id, name);
177  }
178 
189  {
190  return cmzn_light_get_constant_attenuation(id);
191  }
192 
204  int setConstantAttenuation(double constantAttenuation)
205  {
206  return cmzn_light_set_constant_attenuation(id, constantAttenuation);
207  }
208 
219  {
220  return cmzn_light_get_linear_attenuation(id);
221  }
222 
234  int setLinearAttenuation(double linearAttenuation)
235  {
236  return cmzn_light_set_linear_attenuation(id, linearAttenuation);
237  }
238 
249  {
250  return cmzn_light_get_quadratic_attenuation(id);
251  }
252 
264  int setQuadraticAttenuation(double quadraticAttenuation)
265  {
266  return cmzn_light_set_quadratic_attenuation(id, quadraticAttenuation);
267  }
268 
277  int getColourRGB(double *valuesOut3)
278  {
279  return cmzn_light_get_colour_rgb(id, valuesOut3);
280  }
281 
293  int setColourRGB(const double *valuesIn3)
294  {
295  return cmzn_light_set_colour_rgb(id, valuesIn3);
296  }
297 
307  int getDirection(double *valuesOut3)
308  {
309  return cmzn_light_get_direction(id, valuesOut3);
310  }
311 
320  int setDirection(const double *valuesIn3)
321  {
322  return cmzn_light_set_direction(id, valuesIn3);
323  }
324 
334  int getPosition(double *valuesOut3)
335  {
336  return cmzn_light_get_position(id, valuesOut3);
337  }
338 
347  int setPosition(const double *valuesIn3)
348  {
349  return cmzn_light_set_position(id, valuesIn3);
350  }
351 
358  double getSpotCutoff()
359  {
360  return cmzn_light_get_spot_cutoff(id);
361  }
362 
371  int setSpotCutoff(double cutoff)
372  {
373  return cmzn_light_set_spot_cutoff(id, cutoff);
374  }
375 
384  {
385  return cmzn_light_get_spot_exponent(id);
386  }
387 
396  int setSpotExponent(double exponent)
397  {
398  return cmzn_light_set_spot_exponent(id, exponent);
399  }
400 
401 };
402 
403 inline bool operator==(const Light& a, const Light& b)
404 {
405  return a.getId() == b.getId();
406 }
407 
408 
415 {
416 private:
417 
418  cmzn_lightiterator_id id;
419 
420 public:
421 
422  Lightiterator() : id(0)
423  { }
424 
425  // takes ownership of C handle, responsibility for destroying it
426  explicit Lightiterator(cmzn_lightiterator_id iterator_id) :
427  id(iterator_id)
428  { }
429 
430  Lightiterator(const Lightiterator& lightiterator) :
431  id(cmzn_lightiterator_access(lightiterator.id))
432  { }
433 
434  Lightiterator& operator=(const Lightiterator& lightiterator)
435  {
436  cmzn_lightiterator_id temp_id = cmzn_lightiterator_access(lightiterator.id);
437  if (0 != id)
438  {
439  cmzn_lightiterator_destroy(&id);
440  }
441  id = temp_id;
442  return *this;
443  }
444 
445  ~Lightiterator()
446  {
447  if (0 != id)
448  {
449  cmzn_lightiterator_destroy(&id);
450  }
451  }
452 
458  bool isValid() const
459  {
460  return (0 != id);
461  }
462 
472  {
473  return Light(cmzn_lightiterator_next(id));
474  }
475 };
476 
485 {
486 protected:
487  cmzn_lightmodule_id id;
488 
489 public:
490 
491  Lightmodule() : id(0)
492  { }
493 
494  // takes ownership of C handle, responsibility for destroying it
495  explicit Lightmodule(cmzn_lightmodule_id in_lightmodule_id) :
496  id(in_lightmodule_id)
497  { }
498 
499  Lightmodule(const Lightmodule& lightModule) :
500  id(cmzn_lightmodule_access(lightModule.id))
501  { }
502 
503  Lightmodule& operator=(const Lightmodule& lightModule)
504  {
505  cmzn_lightmodule_id temp_id = cmzn_lightmodule_access(
506  lightModule.id);
507  if (0 != id)
508  {
509  cmzn_lightmodule_destroy(&id);
510  }
511  id = temp_id;
512  return *this;
513  }
514 
515  ~Lightmodule()
516  {
517  if (0 != id)
518  {
519  cmzn_lightmodule_destroy(&id);
520  }
521  }
522 
528  bool isValid() const
529  {
530  return (0 != id);
531  }
532 
538  cmzn_lightmodule_id getId() const
539  {
540  return id;
541  }
542 
551  {
552  return Light(cmzn_lightmodule_create_light(id));
553  }
554 
568  {
569  return Lightiterator(cmzn_lightmodule_create_lightiterator(id));
570  }
571 
578  Light findLightByName(const char *name)
579  {
580  return Light(cmzn_lightmodule_find_light_by_name(id, name));
581  }
582 
593  {
594  return cmzn_lightmodule_begin_change(id);
595  }
596 
606  int endChange()
607  {
608  return cmzn_lightmodule_end_change(id);
609  }
610 
622  {
623  return Light(cmzn_lightmodule_get_default_light(id));
624  }
625 
634  int setDefaultLight(const Light& light)
635  {
636  return cmzn_lightmodule_set_default_light(id, light.getId());
637  }
638 
649  {
650  return Light(cmzn_lightmodule_get_default_ambient_light(id));
651  }
652 
660  int setDefaultAmbientLight(const Light& light)
661  {
662  return cmzn_lightmodule_set_default_ambient_light(id, light.getId());
663  }
664 };
665 
667 {
668  return Lightmodule(cmzn_context_get_lightmodule(id));
669 }
670 
671 } // namespace Zinc
672 
673 }
674 #endif
double getQuadraticAttenuation()
Definition: light.hpp:248
Light findLightByName(const char *name)
Definition: light.hpp:578
Module managing all light objects.
Definition: light.hpp:484
cmzn_lightmodule_id getId() const
Definition: light.hpp:538
double getSpotCutoff()
Definition: light.hpp:358
int getColourRGB(double *valuesOut3)
Definition: light.hpp:277
int setName(const char *name)
Definition: light.hpp:174
Light next()
Definition: light.hpp:471
The light controls how vertices will be lit on a sceneviewer.
Definition: light.hpp:28
int endChange()
Definition: light.hpp:606
int setType(enum Type type)
Definition: light.hpp:151
Lightiterator createLightiterator()
Definition: light.hpp:567
Definition: light.hpp:83
int setSpotExponent(double exponent)
Definition: light.hpp:396
double getSpotExponent()
Definition: light.hpp:383
int getDirection(double *valuesOut3)
Definition: light.hpp:307
double getLinearAttenuation()
Definition: light.hpp:218
cmzn_light_id getId() const
Definition: light.hpp:102
bool isValid() const
Definition: light.hpp:71
int setDefaultAmbientLight(const Light &light)
Definition: light.hpp:660
int setDefaultLight(const Light &light)
Definition: light.hpp:634
bool isValid() const
Definition: light.hpp:528
int setSpotCutoff(double cutoff)
Definition: light.hpp:371
int setQuadraticAttenuation(double quadraticAttenuation)
Definition: light.hpp:264
Definition: light.hpp:92
int setPosition(const double *valuesIn3)
Definition: light.hpp:347
Light createLight()
Definition: light.hpp:550
char * getName()
Definition: light.hpp:162
Type
Definition: light.hpp:79
int getPosition(double *valuesOut3)
Definition: light.hpp:334
Definition: light.hpp:81
double getConstantAttenuation()
Definition: light.hpp:188
Light getDefaultAmbientLight()
Definition: light.hpp:648
int setColourRGB(const double *valuesIn3)
Definition: light.hpp:293
The OpenCMISS namespace.
Definition: context.hpp:20
Definition: light.hpp:89
Light getDefaultLight()
Definition: light.hpp:621
int setDirection(const double *valuesIn3)
Definition: light.hpp:320
Lightmodule getLightmodule()
Definition: light.hpp:666
int setLinearAttenuation(double linearAttenuation)
Definition: light.hpp:234
bool isManaged()
Definition: light.hpp:113
int beginChange()
Definition: light.hpp:592
An iterator for looping through all the lights in a light module.
Definition: light.hpp:414
bool isValid() const
Definition: light.hpp:458
int setManaged(bool value)
Definition: light.hpp:130
enum Type getType()
Definition: light.hpp:140
int setConstantAttenuation(double constantAttenuation)
Definition: light.hpp:204