Commit ff9b6d1c authored by Mike Kremer's avatar Mike Kremer

Light sources can now be read out of (and theoretically written to) *.lgt files.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8950 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f5714ea5
......@@ -103,6 +103,10 @@ void LightSource::direction( Vec3d _pos) {
position_ = Vec4d( _pos[0],_pos[1],_pos[2],0.0);
}
Vec3d LightSource::direction() {
return Vec3d(position_[0], position_[1], position_[2], 0.0);
}
bool LightSource::directional() {
return ( position_[3] == 0.0 );
}
......
......@@ -111,6 +111,12 @@ public:
*/
bool directional();
/** \brief Get direction of the light source
*
* Get direction of light.
*/
Vec3d direction();
/** \brief Set the direction of the light source
*
* This function creates a directional light source. The position is not used by OpenGL.
......
......@@ -90,24 +90,143 @@ int FileLightPlugin::loadObject(QString _filename)
LightSource* light = PluginFunctions::lightSource(lightObject);
ACG::Vec3d position;
ACG::Vec3d direction;
ACG::Vec3d spotDirection;
ACG::Vec4f ambientColor;
ACG::Vec4f diffuseColor;
ACG::Vec4f specularColor;
bool fixedPosition;
float spotExponent;
float spotCutOff;
float cAttenuation;
float lAttenuation;
float qAttenuation;
bool enabled;
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("LIGHT");
if ( settings.contains("PositionX") ) {
position[0] = settings.value("PositionX").toDouble();
position[1] = settings.value("PositionY").toDouble();
position[2] = settings.value("PositionZ").toDouble();
light->position( position );
}
if ( settings.contains("DirectionX") ){
direction[0] = settings.value("DirectionX").toDouble();
direction[1] = settings.value("DirectionY").toDouble();
direction[2] = settings.value("DirectionZ").toDouble();
light->direction( direction );
}
if ( settings.contains("SpotDirectionX") ){
spotDirection[0] = settings.value("SpotDirectionX").toDouble();
spotDirection[1] = settings.value("SpotDirectionY").toDouble();
spotDirection[2] = settings.value("SpotDirectionZ").toDouble();
light->spotDirection( spotDirection );
}
if ( settings.contains("AmbientColorR") ){
ambientColor[0] = settings.value("AmbientColorR").toDouble();
ambientColor[1] = settings.value("AmbientColorG").toDouble();
ambientColor[2] = settings.value("AmbientColorB").toDouble();
if(settings.contains("AmbientColorA"))
ambientColor[3] = settings.value("AmbientColorA").toDouble();
else
ambientColor[3] = 1.0f;
light->ambientColor( ambientColor );
}
if ( settings.contains("DiffuseColorR") ){
diffuseColor[0] = settings.value("DiffuseColorR").toDouble();
diffuseColor[1] = settings.value("DiffuseColorG").toDouble();
diffuseColor[2] = settings.value("DiffuseColorB").toDouble();
if(settings.contains("DiffuseColorA"))
diffuseColor[3] = settings.value("DiffuseColorA").toDouble();
else
diffuseColor[3] = 1.0f;
light->diffuseColor( diffuseColor );
}
if ( settings.contains("SpecularColorR") ){
specularColor[0] = settings.value("SpecularColorR").toDouble();
specularColor[1] = settings.value("SpecularColorG").toDouble();
specularColor[2] = settings.value("SpecularColorB").toDouble();
if(settings.contains("SpecularColorA"))
specularColor[3] = settings.value("SpecularColorA").toDouble();
else
specularColor[3] = 1.0f;
light->specularColor( specularColor );
}
if ( settings.contains("FixedPosition") ){
fixedPosition = settings.value("FixedPosition").toBool();
light->fixedPosition( fixedPosition );
}
if ( settings.contains("SpotExponent") ){
spotExponent = settings.value("SpotExponent").toDouble();
light->spotExponent( spotExponent );
}
if ( settings.contains("SpotCutOff") ){
spotCutOff = settings.value("SpotCutOff").toDouble();
light->spotCutoff( spotCutOff );
}
if ( settings.contains("ConstantAttenuation") ){
if ( settings.contains("Position0") ){
cAttenuation = settings.value("ConstantAttenuation").toDouble();
position[0] = settings.value("PositionX").toDouble();
position[1] = settings.value("PositionY").toDouble();
position[2] = settings.value("PositionZ").toDouble();
settings.endGroup();
light->constantAttenuation( cAttenuation );
}
if ( settings.contains("LinearAttenuation") ){
lAttenuation = settings.value("LinearAttenuation").toDouble();
light->linearAttenuation( lAttenuation );
}
if ( settings.contains("QuadraticAttenuation") ){
light->position( position );
qAttenuation = settings.value("QuadraticAttenuation").toDouble();
lightObject->setFromFileName(_filename);
light->quadraticAttenuation( qAttenuation );
}
if ( settings.contains("Enabled") ){
enabled = settings.value("Enabled").toBool();
enabled ? light->enable() : light->disable();
}
lightObject->setFromFileName(_filename);
settings.endGroup();
}
}
emit updatedObject( lightObject->id() );
emit updatedObject( lightObject->id(), UPDATE_ALL );
}
return id;
......@@ -122,25 +241,58 @@ bool FileLightPlugin::saveObject(int _id, QString _filename)
LightObject* lightObject = PluginFunctions::lightObject(obj);
if( lightObject )
{
LightSource* light = PluginFunctions::lightSource(lightObject);
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("LIGHT");
settings.setValue("PositionX", light->position()[0]);
settings.setValue("PositionY", light->position()[1]);
settings.setValue("PositionZ", light->position()[2]);
//Read : Ambient, Diffuse, Specular color , spot direction, exponent, cutOff , constant ,linear, quadratic, attenuation
// settings.setValue("XDirection0", plane->planeNode()->xDirection()[0]);
// settings.setValue("XDirection1", plane->planeNode()->xDirection()[1]);
// settings.setValue("XDirection2", plane->planeNode()->xDirection()[2]);
// settings.setValue("YDirection0", plane->planeNode()->yDirection()[0]);
// settings.setValue("YDirection1", plane->planeNode()->yDirection()[1]);
// settings.setValue("YDirection2", plane->planeNode()->yDirection()[2]);
settings.endGroup();
LightSource* light = PluginFunctions::lightSource(lightObject);
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
QSettings settings(_filename, QSettings::IniFormat);
settings.beginGroup("LIGHT");
if(!light->directional()) {
settings.setValue("PositionX", light->position()[0]);
settings.setValue("PositionY", light->position()[1]);
settings.setValue("PositionZ", light->position()[2]);
} else {
settings.setValue("DirectionX", light->direction()[0]);
settings.setValue("DirectionY", light->direction()[1]);
settings.setValue("DirectionZ", light->direction()[2]);
}
settings.setValue("SpotDirectionX", light->spotDirection()[0]);
settings.setValue("SpotDirectionY", light->spotDirection()[1]);
settings.setValue("SpotDirectionZ", light->spotDirection()[2]);
settings.setValue("AmbientColorR", light->ambientColor()[0]);
settings.setValue("AmbientColorG", light->ambientColor()[1]);
settings.setValue("AmbientColorB", light->ambientColor()[2]);
settings.setValue("AmbientColorA", light->ambientColor()[3]);
settings.setValue("DiffuseColorR", light->diffuseColor()[0]);
settings.setValue("DiffuseColorG", light->diffuseColor()[1]);
settings.setValue("DiffuseColorB", light->diffuseColor()[2]);
settings.setValue("DiffuseColorA", light->diffuseColor()[3]);
settings.setValue("SpecularColorR", light->specularColor()[0]);
settings.setValue("SpecularColorG", light->specularColor()[1]);
settings.setValue("SpecularColorB", light->specularColor()[2]);
settings.setValue("SpecularColorA", light->specularColor()[3]);
settings.setValue("FixedPosition", light->fixedPosition());
settings.setValue("SpotExponent", light->spotExponent());
settings.setValue("SpotCutOff", light->spotCutoff());
settings.setValue("ConstantAttenuation", light->constantAttenuation());
settings.setValue("LinearAttenuation", light->linearAttenuation());
settings.setValue("QuadraticAttenuation", light->quadraticAttenuation());
settings.setValue("Enabled", light->enabled());
settings.endGroup();
}
}
......
......@@ -73,6 +73,8 @@ class FileLightPlugin : public QObject, BaseInterface, FileInterface, LoadSaveIn
void log(QString _message);
void emptyObjectAdded( int _id );
void updatedObject(int _id, UpdateType _type);
private slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment