Commit ad2498e4 authored by Mike Kremer's avatar Mike Kremer
Browse files

Improved light properties widget and added brightness property to light source.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9120 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6cf24563
......@@ -92,6 +92,8 @@ LightSource::LightSource()
linearAttenuation_ = 0;
quadraticAttenuation_ = 0;
brightness_ = 1.0f;
radius_ = 0.1f;
}
......@@ -153,6 +155,12 @@ void LightSource::specularColor( Vec4f _color)
Vec4f LightSource::specularColor()
{ return specularColor_; }
void LightSource::setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular) {
ambientColor_ = _ambient;
diffuseColor_ = _diffuse;
specularColor_ = _specular;
}
void LightSource::fixedPosition( bool _state)
{ fixedPosition_ = _state; }
......@@ -200,7 +208,13 @@ float LightSource::quadraticAttenuation() {
return quadraticAttenuation_;
}
void LightSource::brightness(float _brightness) {
brightness_ = _brightness;
}
float LightSource::brightness() const {
return brightness_;
}
LightNode::LightNode( BaseNode* _parent,
const std::string& _name)
......@@ -247,7 +261,7 @@ void LightNode::draw(GLState& _state, DrawModes::DrawMode /*_drawMode*/) {
light_.realPosition_[1],
light_.realPosition_[2]);
ACG::Vec3d spot = light_.realSpotDirection_;
ACG::Vec4f c = light_.ambientColor();
ACG::Vec4f c = light_.ambientColor() * light_.brightness_;
// Backup variables
ACG::Vec4f base_color_backup;
......@@ -368,13 +382,32 @@ void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/
void LightNode::setParameters(GLenum _index, LightSource& _light)
{
// Multiply colors by brightness
Vec4f& a = _light.ambientColor_;
GLfloat ambient[4] = {a[0]*_light.brightness_,
a[1]*_light.brightness_,
a[2]*_light.brightness_,
a[3]*_light.brightness_};
Vec4f& d = _light.diffuseColor_;
GLfloat diffuse[4] = {d[0]*_light.brightness_,
d[1]*_light.brightness_,
d[2]*_light.brightness_,
d[3]*_light.brightness_};
Vec4f& s = _light.specularColor_;
GLfloat specular[4] = {s[0]*_light.brightness_,
s[1]*_light.brightness_,
s[2]*_light.brightness_,
s[3]*_light.brightness_};
// set preferences of _light for GL_LIGHT#_index
glLightfv(_index, GL_AMBIENT, (GLfloat *)_light.ambientColor_.data());
glLightfv(_index, GL_DIFFUSE, (GLfloat *)_light.diffuseColor_.data());
glLightfv(_index, GL_SPECULAR, (GLfloat *)_light.specularColor_.data());
glLightfv(_index, GL_AMBIENT, ambient);
glLightfv(_index, GL_DIFFUSE, diffuse);
glLightfv(_index, GL_SPECULAR, specular);
Vec3d& d = _light.realSpotDirection_;
GLfloat dir[3] = {(float)d[0], (float)d[1], (float)d[2]};
Vec3d& sd = _light.realSpotDirection_;
GLfloat dir[3] = {(float)sd[0], (float)sd[1], (float)sd[2]};
glLightfv(_index, GL_POSITION, (GLfloat *)_light.realPosition_.data());
glLightfv(_index, GL_SPOT_DIRECTION, dir);
......
......@@ -163,6 +163,8 @@ public:
/// get Specular color for LightSource
Vec4f specularColor();
void setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular);
/// make LightSource fixed or moveable with ModelViewMatrix
void fixedPosition( bool _state);
......@@ -189,6 +191,10 @@ public:
float quadraticAttenuation();
void brightness(const float _brightness);
float brightness() const;
/** \brief Get light source radius
*
* The light radius is the size of the lightsource. In OpenGL rendering this value is ignored.
......@@ -223,6 +229,8 @@ protected:
float linearAttenuation_;
float quadraticAttenuation_;
float brightness_;
/// When using ray tracing, light sources can have
/// extent. We simplify to spherical light sources with
/// radius radius_.
......
......@@ -78,6 +78,20 @@ LightWidget::LightWidget( ACG::SceneGraph::BaseNode* _node, QWidget *parent)
connect(angle,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
connect(exponent,SIGNAL(editingFinished()),this,SLOT(spotChanged()));
brightness->setTracking(true);
connect(brightness, SIGNAL(valueChanged(int)), this, SLOT(brightnessChanged(int)));
connect(ambientR,SIGNAL(editingFinished()),this,SLOT(ambientChanged()));
connect(ambientG,SIGNAL(editingFinished()),this,SLOT(ambientChanged()));
connect(ambientB,SIGNAL(editingFinished()),this,SLOT(ambientChanged()));
connect(diffuseR,SIGNAL(editingFinished()),this,SLOT(diffuseChanged()));
connect(diffuseG,SIGNAL(editingFinished()),this,SLOT(diffuseChanged()));
connect(diffuseB,SIGNAL(editingFinished()),this,SLOT(diffuseChanged()));
connect(specularR,SIGNAL(editingFinished()),this,SLOT(specularChanged()));
connect(specularG,SIGNAL(editingFinished()),this,SLOT(specularChanged()));
connect(specularB,SIGNAL(editingFinished()),this,SLOT(specularChanged()));
}
void LightWidget::showEvent ( QShowEvent * event )
......@@ -103,7 +117,6 @@ void LightWidget::showEvent ( QShowEvent * event )
xpos->setText(QString::number(light_->position()[0]));
ypos->setText(QString::number(light_->position()[1]));
zpos->setText(QString::number(light_->position()[2]));
fixedPosition->setChecked( light_->fixedPosition() );
......@@ -114,6 +127,20 @@ void LightWidget::showEvent ( QShowEvent * event )
angle->setText(QString::number(light_->spotCutoff()));
exponent->setText(QString::number(light_->spotExponent()));
ambientR->setText(QString::number(light_->ambientColor()[0]));
ambientG->setText(QString::number(light_->ambientColor()[1]));
ambientB->setText(QString::number(light_->ambientColor()[2]));
diffuseR->setText(QString::number(light_->diffuseColor()[0]));
diffuseG->setText(QString::number(light_->diffuseColor()[1]));
diffuseB->setText(QString::number(light_->diffuseColor()[2]));
specularR->setText(QString::number(light_->specularColor()[0]));
specularG->setText(QString::number(light_->specularColor()[1]));
specularB->setText(QString::number(light_->specularColor()[2]));
brightness->setSliderPosition((int)(light_->brightness()*100));
// Allow updates
updatingWidgets_ = false;
......@@ -141,6 +168,59 @@ void LightWidget::directionalToggled() {
}
void LightWidget::ambientChanged() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
light_->ambientColor(ACG::Vec4f(ambientR->text().toDouble(),
ambientG->text().toDouble(),
ambientB->text().toDouble(),
1.0f));
updated();
}
void LightWidget::diffuseChanged() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
light_->diffuseColor(ACG::Vec4f(diffuseR->text().toDouble(),
diffuseG->text().toDouble(),
diffuseB->text().toDouble(),
1.0f));
updated();
}
void LightWidget::specularChanged() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
light_->specularColor(ACG::Vec4f(specularR->text().toDouble(),
specularG->text().toDouble(),
specularB->text().toDouble(),
1.0f));
updated();
}
void LightWidget::brightnessChanged(int _newValue) {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
return;
float pos = _newValue;
pos /= 100.0f;
light_->brightness(pos);
updated();
}
void LightWidget::spotChanged() {
// Block if we currently update the widgets or if we dont get the object
if (updatingWidgets_ || !getObject() )
......
......@@ -57,6 +57,14 @@ class DLLEXPORT LightWidget : public QDialog, public Ui::LightWidgetBase
/// The directional checkbox changed -> update object
void directionalToggled();
/// Color values have changed
void ambientChanged();
void diffuseChanged();
void specularChanged();
/// Brightness value has changed
void brightnessChanged(int _newValue);
/// Spot direction changed
void spotChanged();
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>226</width>
<height>582</height>
<width>277</width>
<height>636</height>
</rect>
</property>
<property name="windowTitle">
......@@ -37,7 +37,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_3">
......@@ -47,35 +47,48 @@
<string>Position</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="xpos"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ypos"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="zpos"/>
<item row="6" column="0">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Z</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="xpos"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ypos"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="zpos"/>
</item>
</layout>
</item>
</layout>
</widget>
......@@ -90,35 +103,48 @@
<string>Direction</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="xdir"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ydir"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="zdir"/>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="0">
<widget class="QLineEdit" name="xdir"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ydir"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="zdir"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Z</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
......@@ -132,45 +158,59 @@
<property name="title">
<string>Spot</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Direction</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="spotx"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="spoty"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="spotz"/>
</item>
</layout>
</widget>
<layout class="QGridLayout" name="gridLayout_9">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="spotx"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="spoty"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Z</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="spotz"/>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_25">
<property name="text">
<string>Direction</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
......@@ -207,6 +247,208 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Colors</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Brightness</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="brightness">
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="sliderPosition">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Ambient</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
<widget class="QLineEdit" name="ambientR"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="ambientG"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="ambientB"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>R</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_15">
<property name="text">
<string>G</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_16">
<property name="text">
<string>B</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Diffuse</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="0">
<widget class="QLineEdit" name="diffuseR"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="diffuseG"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="diffuseB"/>
</item>
&l