1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * ... |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "Ambient.h" |
---|
31 | |
---|
32 | #include <vector> |
---|
33 | #include <string> |
---|
34 | |
---|
35 | #include <OgreSceneManager.h> |
---|
36 | |
---|
37 | #include "tinyxml/tinyxml.h" |
---|
38 | #include "util/SubString.h" |
---|
39 | #include "util/Convert.h" |
---|
40 | #include "util/Math.h" |
---|
41 | #include "core/Debug.h" |
---|
42 | #include "core/CoreIncludes.h" |
---|
43 | #include "GraphicsEngine.h" |
---|
44 | #include "core/XMLPort.h" |
---|
45 | #include "core/ConsoleCommand.h" |
---|
46 | |
---|
47 | namespace orxonox |
---|
48 | { |
---|
49 | SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline); |
---|
50 | |
---|
51 | CreateFactory(Ambient); |
---|
52 | |
---|
53 | Ambient* Ambient::instance_s; |
---|
54 | |
---|
55 | Ambient::Ambient() |
---|
56 | { |
---|
57 | RegisterObject(Ambient); |
---|
58 | Ambient::instance_s = this; |
---|
59 | registerAllVariables(); |
---|
60 | } |
---|
61 | |
---|
62 | Ambient::~Ambient() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | bool Ambient::create(){ |
---|
67 | GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_); |
---|
68 | return Synchronisable::create(); |
---|
69 | } |
---|
70 | |
---|
71 | void Ambient::registerAllVariables(){ |
---|
72 | registerVar(&ambientLight_, sizeof(ColourValue), network::DATA); |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | void Ambient::loadParams(TiXmlElement* xmlElem) |
---|
77 | { |
---|
78 | if (xmlElem->Attribute("colourvalue")) |
---|
79 | { |
---|
80 | SubString colourvalues(xmlElem->Attribute("colourvalue"), ','); |
---|
81 | |
---|
82 | float r, g, b; |
---|
83 | convertValue<std::string, float>(&r, colourvalues[0]); |
---|
84 | convertValue<std::string, float>(&g, colourvalues[1]); |
---|
85 | convertValue<std::string, float>(&b, colourvalues[2]); |
---|
86 | |
---|
87 | this->setAmbientLight(ColourValue(r, g, b)); |
---|
88 | |
---|
89 | COUT(4) << "Loader: Set ambient light: "<<r<<" " << g << " " << b << std::endl << std::endl; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | void Ambient::setAmbientLight(const ColourValue& colour) |
---|
94 | { |
---|
95 | GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour); |
---|
96 | ambientLight_=colour; |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | @brief XML loading and saving. |
---|
101 | @param xmlelement The XML-element |
---|
102 | @param loading Loading (true) or saving (false) |
---|
103 | @return The XML-element |
---|
104 | */ |
---|
105 | void Ambient::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
106 | { |
---|
107 | BaseObject::XMLPort(xmlelement, mode); |
---|
108 | |
---|
109 | XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode); |
---|
110 | create(); |
---|
111 | } |
---|
112 | } |
---|