AnnLightObject.cpp
Go to the documentation of this file.
1 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
2 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3 
4 #include "AnnLightObject.hpp"
5 #include "AnnEngine.hpp"
6 #include "AnnLogger.hpp"
7 #include "AnnGetter.hpp"
8 
9 using namespace Annwvyn;
10 
11 AnnLightObject::AnnLightObject(Ogre::Light* light, const std::string& name) :
12  light(light),
13  name(name)
14 {
15  AnnDebug() << "Light constructor called";
16  if(light)
17  {
18  node = AnnGetEngine()->getSceneManager()->getRootSceneNode()->createChildSceneNode();
19  node->attachObject(light);
20  }
21 }
22 
24 {
25  AnnDebug() << "Light destructor called";
26  if(light)
27  {
28  if(node)
29  {
30  node->detachObject(light);
31  if(node->getParentSceneNode())
32  node->getParentSceneNode()->removeChild(node);
33  AnnGetEngine()->getSceneManager()->destroySceneNode(node);
34  node = nullptr;
35  }
36  AnnGetEngine()->getSceneManager()->destroyLight(light);
37  }
38 }
39 
41 {
42  if(ltype == "Point") return ANN_LIGHT_POINT;
43  if(ltype == "Spotlight") return ANN_LIGHT_SPOTLIGHT;
44  if(ltype == "Directional") return ANN_LIGHT_DIRECTIONAL;
45  return ANN_LIGHT_POINT;
46 }
47 
49 {
50  node->setPosition(position);
51 }
52 
54 {
55  light->setDirection(direction);
56 }
57 
59 {
60  return light->getDirection();
61 }
62 
64 {
65  light->setType(Ogre::Light::LightTypes(type));
66 }
67 
69 {
70  light->setDiffuseColour(color.getOgreColor());
71 }
72 
74 {
75  light->setSpecularColour(color.getOgreColor());
76 }
77 
79 {
80  return AnnColor(light->getDiffuseColour());
81 }
82 
84 {
85  return AnnColor(light->getSpecularColour());
86 }
87 
89 {
90  return node->getPosition();
91 }
92 
93 void AnnLightObject::setAttenuation(float range, float constant, float linear, float quadratic) const
94 {
95  light->setAttenuation(range, constant, linear, quadratic);
96 }
97 
98 Ogre::Light* AnnLightObject::_getOgreLight() const
99 {
100  return light;
101 }
102 
104 {
105  return name;
106 }
107 
108 void AnnLightObject::setPower(float lumens) const
109 {
110  light->setPowerScale(lumens);
111 }
112 
114 {
115  return light->getPowerScale();
116 }
Object that represent a light source.
void setDiffuseColor(AnnColor color) const
Set the diffuse color of this light source.
Ogre::SceneNode * node
AnnEngine * AnnGetEngine()
Get the current instance of AnnEngine.
Definition: AnnGetter.cpp:10
AnnVect3 getPosition() override
Get the position of the light (if relevant)
Class that represent a 4 channel color value.
Definition: AnnColor.hpp:17
Directional lights simulate parallel light beams from a distant source, hence have direction but no p...
const std::string name
Ogre::ColourValue getOgreColor() const
Return a Ogre::ColourValue from the internal color value.
Definition: AnnColor.cpp:40
Spotlights simulate a cone of light from a source so require position and direction, plus extra values for falloff.
A 3D Vector.
Definition: AnnVect3.hpp:16
void setPosition(AnnVect3 position) override
Set the position of the light (if relevant)
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
LightTypes
Defines the type of light.
static LightTypes getLightTypeFromString(const std::string &ltype)
void setType(LightTypes type) const
Set the type of the light.
void setAttenuation(float range, float constant, float linear, float quadratic) const
Set the attenuation parameters.
AnnLightObject(Ogre::Light *light, const std::string &name)
Create a ostream to the Ogre logger.
Ogre::SceneManager * getSceneManager() const
Get ogre scene manager.
Definition: AnnEngine.cpp:331
AnnVect3 getDirection() const
Get the direction of the light (if relevant)
float getPower() const
get the current power of this lamp
void setPower(float lumens) const
Set the power of this lamp (in lumens)
Open an output stream to the engine log.
Definition: AnnLogger.hpp:24
std::string getName() const
Get the name of this light.
AnnColor getSpecularColor() const
Get the specular color of this light source.
Main Annwvyn Engine class Initialize the renderer and all subsystem. Provide access to all of the eng...
void setDirection(AnnVect3 direction) const
Set the direction of the light (if relevant)
Point light sources give off light equally in all directions, so require only position not direction...
void setSpecularColor(AnnColor color) const
Set the specular color of this light source.
Ogre::Light * _getOgreLight() const
Advanced method : get the underlying Ogre light object.
AnnColor getDiffuseColor() const
Get the diffuse color of this light source.