Skyscraper 2.0
light.cpp
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Light Object
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#include <OgreSceneManager.h>
25#include <OgreLight.h>
26#include "globals.h"
27#include "sbs.h"
28#include "floor.h"
29#include "elevatorcar.h"
30#include "shaft.h"
31#include "stairs.h"
32#include "scenenode.h"
33#include "light.h"
34
35namespace SBS {
36
37Light::Light(Object *parent, const std::string &name, int type) : Object(parent)
38{
39 //creates a light object
40
41 //types are:
42 //0 - point light
43 //1 - directional light
44 //2 - spotlight
45
46 //set up SBS object
47 SetValues("Light", name, false);
48
49 Type = type;
50
51 try
52 {
53 light = sbs->mSceneManager->createLight(GetSceneNode()->GetFullName());
55
56 if (type == 0)
57 light->setType(Ogre::Light::LT_POINT);
58 if (type == 1)
59 light->setType(Ogre::Light::LT_DIRECTIONAL);
60 if (type == 2)
61 light->setType(Ogre::Light::LT_SPOTLIGHT);
62
64 }
65 catch (Ogre::Exception &e)
66 {
67 ReportError("Error creating light:\n" + e.getDescription());
68 }
69
70 std::string type_name = "point";
71 if (type == 1)
72 type_name = "directional";
73 if (type == 2)
74 type_name = "spotlight";
75
76 if (sbs->Verbose == true)
77 Report("Light '" + name + "' created as type " + type_name);
78}
79
81{
82 if (light)
84 sbs->mSceneManager->destroyLight(GetSceneNode()->GetFullName());
85
86 //unregister from parent
87 if (sbs->FastDelete == false && parent_deleting == false)
88 {
89 std::string type = GetParent()->GetType();
90
91 if (type == "ElevatorCar")
92 static_cast<ElevatorCar*>(GetParent())->RemoveLight(this);
93 else if (type == "Floor")
94 static_cast<Floor*>(GetParent())->RemoveLight(this);
95 else if (type == "Shaft Level")
96 static_cast<Shaft::Level*>(GetParent())->RemoveLight(this);
97 else if (type == "Stairwell Level")
98 static_cast<Stairwell::Level*>(GetParent())->RemoveLight(this);
99 else if (type == "SBS")
100 sbs->RemoveLight(this);
101 }
102}
103
104void Light::SetColor(Real color_r, Real color_g, Real color_b)
105{
106 //set color of light
107 light->setDiffuseColour(color_r, color_g, color_b);
108}
109
110void Light::SetSpecularColor(Real color_r, Real color_g, Real color_b)
111{
112 light->setSpecularColour(color_r, color_g, color_b);
113}
114
115void Light::SetAttenuation(Real att_range, Real att_constant, Real att_linear, Real att_quadratic)
116{
117 light->setAttenuation(sbs->ToRemote(att_range), att_constant, att_linear, att_quadratic);
118}
119
120void Light::SetSpotlightRange(Real spot_inner_angle, Real spot_outer_angle, Real spot_falloff)
121{
122 if (Type == 2)
123 light->setSpotlightRange(Degree(spot_inner_angle), Degree(spot_outer_angle), spot_falloff);
124}
125
126void Light::SetDirection(const Vector3 &direction)
127{
128 GetSceneNode()->SetDirection(direction);
129}
130
132{
133 light->setRenderingDistance(sbs->ToRemote(distance));
134}
135
136void Light::Enabled(bool value)
137{
138 light->setVisible(value);
139}
140
142{
143 return light->getVisible();
144}
145
146}
bool IsEnabled()
Definition light.cpp:141
void Enabled(bool value)
Definition light.cpp:136
void SetDirection(const Vector3 &direction)
Definition light.cpp:126
void SetRenderingDistance(Real distance)
Definition light.cpp:131
Light(Object *parent, const std::string &name, int type)
Definition light.cpp:37
void SetColor(Real color_r=1.0f, Real color_g=1.0f, Real color_b=1.0f)
Definition light.cpp:104
void SetAttenuation(Real att_range=100000.f, Real att_constant=1.f, Real att_linear=0.f, Real att_quadratic=0.f)
Definition light.cpp:115
void SetSpotlightRange(Real spot_inner_angle=30.f, Real spot_outer_angle=40.f, Real spot_falloff=1.f)
Definition light.cpp:120
void SetSpecularColor(Real color_r=0.0f, Real color_g=0.0f, Real color_b=0.0f)
Definition light.cpp:110
int Type
Definition light.h:33
Ogre::Light * light
Definition light.h:49
virtual bool ReportError(const std::string &message)
Definition object.cpp:84
Object * GetParent()
Definition object.cpp:42
virtual void Report(const std::string &message)
Definition object.cpp:78
bool parent_deleting
Definition object.h:64
SceneNode * GetSceneNode()
Definition object.cpp:240
void SetValues(const std::string &type, const std::string &name, bool is_permanent, bool is_movable=true)
Definition object.cpp:144
const std::string & GetType()
Definition object.cpp:177
Ogre::SceneManager * mSceneManager
Definition sbs.h:138
void RemoveLight(Light *light)
Definition sbs.cpp:2831
bool FastDelete
Definition sbs.h:188
Real ToRemote(Real local_value)
Definition sbs.cpp:2407
bool Verbose
Definition sbs.h:186
void DetachObject(Ogre::MovableObject *object)
void AttachObject(Ogre::MovableObject *object)
void SetDirection(const Vector3 &direction)
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
Ogre::Degree Degree
Definition globals.h:61