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
|
/* 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 "common/math.h"
#include "graphics/renderer.h"
#include "tetraedge/tetraedge.h"
#include "tetraedge/te/te_light.h"
#include "tetraedge/te/te_light_opengl.h"
#include "tetraedge/te/te_light_tinygl.h"
#include "tetraedge/te/te_color.h"
#include "tetraedge/te/te_quaternion.h"
#include "tetraedge/te/te_vector3f32.h"
namespace Tetraedge {
/*static*/
uint32 TeLight::_globalAmbientColor;
TeLight::TeLight() : _colAmbient(0, 0, 0, 0xff), _colDiffuse(0, 0, 0, 0xff), _colSpecular(0xff, 0xff, 0xff, 0xff),
_constAtten(1.0f), _linearAtten(0.0f), _quadraticAtten(0.0f), _cutoff(0.0f), _exponent(0.0f), _type(LightTypePoint),
_displaySize(3.0)
{
}
TeVector3f32 TeLight::directionVector() const {
float cosx = cosf(_positionRadial.getX());
float cosy = cosf(_positionRadial.getY());
float sinx = sinf(_positionRadial.getX());
float siny = sinf(_positionRadial.getY());
return TeVector3f32(cosx * cosy, siny, sinx * cosy);
}
void TeLight::transformDirPoint(const TeVector3f32 &pt1, TeVector3f32 &pt2) {
const TeQuaternion q1 = TeQuaternion::fromAxisAndAngle(TeVector3f32(0, 1, 0), _positionRadial.getX() + M_PI);
const TeQuaternion q2 = TeQuaternion::fromAxisAndAngle(TeVector3f32(0, 0, -1), -_positionRadial.getY());
pt2.rotate(q2);
pt2.rotate(q1);
pt2 += pt1;
}
void TeLight::transformSpotPoint(TeVector3f32 &pt) {
const TeQuaternion q1 = TeQuaternion::fromAxisAndAngle(TeVector3f32(0, 1, 0), _positionRadial.getX());
const TeQuaternion q2 = TeQuaternion::fromAxisAndAngle(TeVector3f32(0, 0, -1), _positionRadial.getY());
pt.rotate(q2);
pt.rotate(q1);
pt += _position3d;
}
Common::String TeLight::dump() const {
const char *ltype;
switch (_type) {
case LightTypeSpot:
ltype = "Spot";
break;
case LightTypePoint:
ltype = "Point";
break;
case LightTypeDirectional:
ltype = "Directional";
break;
default:
error("Invalid light type %d", (int)_type);
}
return Common::String::format("%sLight(\n\tamb:%s diff:%s spec:%s\n\tpos:%s posRad:%s atten:%.02f %.02f %.02f\n\tcutoff:%.02f exp:%.02f dispSz:%.02f\n)",
ltype, _colAmbient.dump().c_str(), _colDiffuse.dump().c_str(),
_colSpecular.dump().c_str(), _position3d.dump().c_str(),
_positionRadial.dump().c_str(), _constAtten, _linearAtten,
_quadraticAtten, _cutoff, _exponent, _displaySize);
}
/*static*/
TeLight *TeLight::makeInstance() {
Graphics::RendererType r = g_engine->preferredRendererType();
#if defined(USE_OPENGL_GAME)
if (r == Graphics::kRendererTypeOpenGL)
return new TeLightOpenGL();
#endif
#if defined(USE_TINYGL)
if (r == Graphics::kRendererTypeTinyGL)
return new TeLightTinyGL();
#endif
error("Couldn't create TeLight for selected renderer");
}
} // end namespace Tetraedge
|