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
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "engines/stark/resources/light.h"
#include "engines/stark/formats/xrc.h"
#include "engines/stark/gfx/renderentry.h"
#include "engines/stark/services/stateprovider.h"
namespace Stark {
namespace Resources {
Light::~Light() {
delete _lightEntry;
}
Light::Light(Object *parent, byte subType, uint16 index, const Common::String &name) :
Object(parent, subType, index, name),
_outerConeAngle(0),
_innerConeAngle(0),
_falloffNear(100.0),
_falloffFar(500.0),
_lightEntry(nullptr),
_multiplier(1.0) {
_type = TYPE;
}
void Light::readData(Formats::XRCReadStream *stream) {
_color = stream->readVector3();
_position = stream->readVector3();
_direction = stream->readVector3();
_outerConeAngle = stream->readFloatLE();
_innerConeAngle = stream->readFloatLE();
if (stream->isDataLeft()) {
_falloffNear = stream->readFloatLE();
_falloffFar = stream->readFloatLE();
}
}
void Light::onPostRead() {
Object::onPostRead();
_lightEntry = new Gfx::LightEntry();
_lightEntry->type = (Gfx::LightEntry::Type) _subType;
_lightEntry->direction = _direction;
_lightEntry->innerConeAngle = _innerConeAngle / 2.0;
_lightEntry->outerConeAngle = _outerConeAngle / 2.0;
_lightEntry->falloffNear = _falloffNear;
_lightEntry->falloffFar = _falloffFar;
// Negative lights add darkness
_multiplier = _name.hasPrefix("x_neg") ? -1.0 : 1.0;
}
void Light::saveLoad(ResourceSerializer *serializer) {
Object::saveLoad(serializer);
serializer->syncAsVector3d(_color);
serializer->syncAsVector3d(_position);
}
void Light::setColor(int32 red, int32 green, int32 blue) {
_color.x() = (float) red / 255.0f;
_color.y() = (float) green / 255.0f;
_color.z() = (float) blue / 255.0f;
}
void Light::setPosition(const Math::Vector3d &position) {
_position = position;
}
Gfx::LightEntry *Light::getLightEntry() {
_lightEntry->color = _multiplier * _color;
_lightEntry->position = _position;
return _lightEntry;
}
void Light::printData() {
Common::StreamDebug debug = streamDbg();
debug << "color: " << _color << "\n";
debug << "position: " << _position << "\n";
debug << "direction: " << _direction << "\n";
debug << "innerConeAngle: " << _innerConeAngle << "\n";
debug << "outerConeAngle: " << _outerConeAngle << "\n";
debug << "falloffNear: " << _falloffNear << "\n";
debug << "falloffFar: " << _falloffFar << "\n";
}
} // End of namespace Resources
} // End of namespace Stark
|