-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLight.cpp
More file actions
156 lines (112 loc) · 3.57 KB
/
Light.cpp
File metadata and controls
156 lines (112 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//================================================//
#include "Light.hpp"
//================================================//
Light::Light(void)
: DynamicObject()
{
m_dataLoaded = false;
}
//================================================//
void Light::initLight(Ogre::SceneManager* mgr, Ogre::SceneNode* node)
{
m_pSceneMgr = mgr;
m_pSceneNode = node;
m_data = nullptr;
const Ogre::Any& any = m_pSceneNode->getUserAny();
if(!any.isEmpty()){
if(any.getType() == typeid(LightData*)){
m_data = Ogre::any_cast<LightData*>(any);
m_dataLoaded = true;
}
}
if(!m_dataLoaded){
// Setup default light settings
printf("No light data found on %s\n", m_pSceneNode->getName().c_str());
m_data = new LightData();
m_data->type = TYPE_SPOT;
m_data->range = 600.0;
m_data->inner = 5.0;
m_data->outer = 21.0;
m_data->shadows = false;
}
m_pLight = m_pSceneMgr->createLight("Dyn_" + m_pSceneNode->getName());
m_pLight->setType((m_data->type == TYPE_SPOT) ? Ogre::Light::LT_SPOTLIGHT : Ogre::Light::LT_POINT);
m_pLight->setPosition(m_pSceneNode->_getDerivedPosition());
Ogre::Vector3 dir = m_pSceneNode->_getDerivedOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Y;
m_pLight->setDirection(dir);
//m_pLight->setCustomShadowCameraSetup(Ogre::ShadowCameraSetupPtr(new Ogre::FocusedShadowCameraSetup()));
// Light colour
m_pLight->setDiffuseColour(m_data->colour);
m_pLight->setSpecularColour(m_data->colour);
// Type settings
if(m_data->type == TYPE_SPOT){
m_pLight->setAttenuation(m_data->range, 0.5, 0.0, 0.0);
m_pLight->setSpotlightInnerAngle(Ogre::Degree(m_data->inner));
m_pLight->setSpotlightOuterAngle(Ogre::Degree(m_data->outer));
m_pLight->setSpotlightFalloff(1.0);
}
m_pLight->setCastShadows(m_data->shadows);
if(m_data->hideNode)
m_pSceneNode->setVisible(false);
}
//================================================//
void Light::deleteData(void)
{
const Ogre::Any& any = m_pSceneNode->getUserAny();
if(!any.isEmpty()){
if(any.getType() == typeid(LightData*))
delete Ogre::any_cast<LightData*>(any);
}
}
//================================================//
//================================================//
StaticLight::StaticLight(void)
: Light()
{
}
//================================================//
void StaticLight::update(double timeSinceLastFrame)
{
}
//================================================//
//================================================//
PulseLight::PulseLight(void)
: Light()
{
}
//================================================//
void PulseLight::initLight(Ogre::SceneManager* mgr, Ogre::SceneNode* node)
{
Light::initLight(mgr, node);
if(m_dataLoaded){
m_speed = m_data->buffer;
}
}
//================================================//
void PulseLight::update(double timeSinceLastFrame)
{
static Ogre::Real sin = 0.0;
static Ogre::ColourValue colour = m_pLight->getDiffuseColour();
Ogre::ColourValue newColour = colour * Ogre::Math::Abs(0.5 * Ogre::Math::Sin(sin));
m_pLight->setDiffuseColour(newColour);
m_pLight->setSpecularColour(newColour);
sin += 0.002 * m_speed * timeSinceLastFrame;
}
//================================================//
//================================================//
FlickerLight::FlickerLight(void)
{
}
//================================================//
void FlickerLight::initLight(Ogre::SceneManager* mgr, Ogre::SceneNode* node)
{
Light::initLight(mgr, node);
if(m_dataLoaded){
}
}
//================================================//
void FlickerLight::update(double timeSinceLastFrame)
{
// turn on and off
}
//================================================//