ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

engines/stark/resources/light.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/resources/light.h"
00024 
00025 #include "engines/stark/formats/xrc.h"
00026 #include "engines/stark/gfx/renderentry.h"
00027 #include "engines/stark/services/stateprovider.h"
00028 
00029 namespace Stark {
00030 namespace Resources {
00031 
00032 Light::~Light() {
00033     delete _lightEntry;
00034 }
00035 
00036 Light::Light(Object *parent, byte subType, uint16 index, const Common::String &name) :
00037         Object(parent, subType, index, name),
00038         _outerConeAngle(0),
00039         _innerConeAngle(0),
00040         _falloffNear(100.0),
00041         _falloffFar(500.0),
00042         _lightEntry(nullptr),
00043         _multiplier(1.0) {
00044     _type = TYPE;
00045 }
00046 
00047 void Light::readData(Formats::XRCReadStream *stream) {
00048     _color = stream->readVector3();
00049     _position = stream->readVector3();
00050     _direction = stream->readVector3();
00051     _outerConeAngle = stream->readFloatLE();
00052     _innerConeAngle = stream->readFloatLE();
00053 
00054     if (stream->isDataLeft()) {
00055         _falloffNear = stream->readFloatLE();
00056         _falloffFar = stream->readFloatLE();
00057     }
00058 }
00059 
00060 void Light::onPostRead() {
00061     Object::onPostRead();
00062 
00063     _lightEntry = new Gfx::LightEntry();
00064     _lightEntry->type = (Gfx::LightEntry::Type) _subType;
00065     _lightEntry->direction = _direction;
00066     _lightEntry->innerConeAngle = _innerConeAngle / 2.0;
00067     _lightEntry->outerConeAngle = _outerConeAngle / 2.0;
00068     _lightEntry->falloffNear = _falloffNear;
00069     _lightEntry->falloffFar = _falloffFar;
00070 
00071     // Negative lights add darkness
00072     _multiplier = _name.hasPrefix("x_neg") ? -1.0 : 1.0;
00073 }
00074 
00075 void Light::saveLoad(ResourceSerializer *serializer) {
00076     Object::saveLoad(serializer);
00077 
00078     serializer->syncAsVector3d(_color);
00079     serializer->syncAsVector3d(_position);
00080 }
00081 
00082 void Light::setColor(int32 red, int32 green, int32 blue) {
00083     _color.x() = (float) red / 255.0f;
00084     _color.y() = (float) green / 255.0f;
00085     _color.z() = (float) blue / 255.0f;
00086 }
00087 
00088 void Light::setPosition(const Math::Vector3d &position) {
00089     _position = position;
00090 }
00091 
00092 Gfx::LightEntry *Light::getLightEntry() {
00093     _lightEntry->color = _multiplier * _color;
00094     _lightEntry->position = _position;
00095 
00096     return _lightEntry;
00097 }
00098 
00099 void Light::printData() {
00100     Common::Debug debug = streamDbg();
00101     debug << "color: " << _color << "\n";
00102     debug << "position: " << _position << "\n";
00103     debug << "direction: " << _direction << "\n";
00104     debug << "innerConeAngle: " << _innerConeAngle << "\n";
00105     debug << "outerConeAngle: " << _outerConeAngle << "\n";
00106     debug << "falloffNear: " << _falloffNear << "\n";
00107     debug << "falloffFar: " << _falloffFar << "\n";
00108 }
00109 
00110 } // End of namespace Resources
00111 } // End of namespace Stark


Generated on Sat May 25 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge