Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove spins
  • Loading branch information
vcloarec authored and nyalldawson committed Oct 21, 2020
1 parent 55ee533 commit f31b955
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 170 deletions.
86 changes: 24 additions & 62 deletions src/app/3d/qgslightswidget.cpp
Expand Up @@ -51,16 +51,13 @@ QgsLightsWidget::QgsLightsWidget( QWidget *parent )
connect( btnRemoveDirectionalLight, &QToolButton::clicked, this, &QgsLightsWidget::onRemoveDirectionalLight );

connect( cboDirectionalLights, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLightsWidget::onCurrentDirectionalLightChanged );
connect( spinDirectionX, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
connect( spinDirectionY, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
connect( spinDirectionZ, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxDirectionChanged );
connect( spinDirectionalIntensity, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::updateCurrentDirectionalLightParameters );
connect( btnDirectionalColor, &QgsColorButton::colorChanged, this, &QgsLightsWidget::updateCurrentDirectionalLightParameters );

connect( dialAzimuth, &QSlider::valueChanged, [this]( int value ) {spinBoxAzimuth->setValue( ( value + 180 ) % 360 );} );
connect( spinBoxAzimuth, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxAzimuthChange );
connect( spinBoxAltitude, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onSpinBoxAltitudeChange );
connect( sliderAltitude, &QSlider::valueChanged, spinBoxAltitude, &QgsDoubleSpinBox::setValue );
connect( spinBoxAzimuth, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onDirectionChange );
connect( spinBoxAltitude, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, &QgsLightsWidget::onDirectionChange );

tabWidget->setCurrentIndex( QgsSettings().value( QStringLiteral( "UI/last3DLightsTab" ), 1 ).toInt() );
}
Expand Down Expand Up @@ -118,12 +115,12 @@ void QgsLightsWidget::onCurrentDirectionalLightChanged( int index )
return;

QgsDirectionalLightSettings light = mDirectionalLights.at( index );
whileBlocking( spinDirectionX )->setValue( light.direction().x() );
whileBlocking( spinDirectionY )->setValue( light.direction().y() );
whileBlocking( spinDirectionZ )->setValue( light.direction().z() );
mDirectionX = light.direction().x();
mDirectionY = light.direction().y();
mDirectionZ = light.direction().z();
whileBlocking( btnDirectionalColor )->setColor( light.color() );
whileBlocking( spinDirectionalIntensity )->setValue( light.intensity() );
onSpinBoxDirectionChanged();
setAzimuthAltitude();
}


Expand All @@ -145,12 +142,16 @@ void QgsLightsWidget::updateCurrentLightParameters()

void QgsLightsWidget::updateCurrentDirectionalLightParameters()
{
labelX->setText( QString::number( mDirectionX, 'f', 2 ) );
labelY->setText( QString::number( mDirectionY, 'f', 2 ) );
labelZ->setText( QString::number( mDirectionZ, 'f', 2 ) );

int index = cboDirectionalLights->currentIndex();
if ( index < 0 || index >= cboDirectionalLights->count() )
return;

QgsDirectionalLightSettings light;
light.setDirection( QgsVector3D( spinDirectionX->value(), spinDirectionY->value(), spinDirectionZ->value() ) );
light.setDirection( QgsVector3D( mDirectionX, mDirectionY, mDirectionZ ) );
light.setColor( btnDirectionalColor->color() );
light.setIntensity( spinDirectionalIntensity->value() );
mDirectionalLights[index] = light;
Expand Down Expand Up @@ -218,88 +219,49 @@ void QgsLightsWidget::onRemoveDirectionalLight()
emit directionalLightsCountChanged( cboDirectionalLights->count() );
}

void QgsLightsWidget::onSpinBoxDirectionChanged()
void QgsLightsWidget::setAzimuthAltitude()
{
double x = spinDirectionX->value();
double y = spinDirectionY->value();
double z = spinDirectionZ->value();
double azimuthAngle;
double altitudeAngle;

double horizontalVectorMagnitude = sqrt( x * x + z * z );
double horizontalVectorMagnitude = sqrt( mDirectionX * mDirectionX + mDirectionZ * mDirectionZ );

if ( horizontalVectorMagnitude == 0 )
azimuthAngle = 0;
else
{
azimuthAngle = ( asin( -x / horizontalVectorMagnitude ) ) / M_PI * 180;
if ( z < 0 )
azimuthAngle = ( asin( -mDirectionX / horizontalVectorMagnitude ) ) / M_PI * 180;
if ( mDirectionZ < 0 )
azimuthAngle = 180 - azimuthAngle;
azimuthAngle = std::fmod( azimuthAngle + 360.0, 360.0 );
}


dialAzimuth->setValue( int( azimuthAngle + 180 ) % 360 );
spinBoxAzimuth->setValue( azimuthAngle );

if ( horizontalVectorMagnitude == 0 )
altitudeAngle = y >= 0 ? 90 : -90;
altitudeAngle = mDirectionY >= 0 ? 90 : -90;
else
altitudeAngle = -atan( y / horizontalVectorMagnitude ) / M_PI * 180;
altitudeAngle = -atan( mDirectionY / horizontalVectorMagnitude ) / M_PI * 180;

spinBoxAltitude->setValue( altitudeAngle );
sliderAltitude->setValue( altitudeAngle );

updateCurrentDirectionalLightParameters();
}

void QgsLightsWidget::onSpinBoxAzimuthChange()
void QgsLightsWidget::onDirectionChange()
{
double x = spinDirectionX->value();
double z = spinDirectionZ->value();
double horizontalVectorMagnitude = sqrt( x * x + z * z );

double azimuthValue = spinBoxAzimuth->value();
x = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
z = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );

whileBlocking( dialAzimuth )->setValue( int( azimuthValue + 180 ) % 360 );
whileBlocking( spinDirectionX )->setValue( x );
whileBlocking( spinDirectionZ )->setValue( z );

updateCurrentDirectionalLightParameters();
}

void QgsLightsWidget::onSpinBoxAltitudeChange()
{
double x = spinDirectionX->value();
double y = spinDirectionY->value();
double z = spinDirectionZ->value();
double horizontalVectorMagnitude = sqrt( x * x + z * z );
double vectorMagnitude = sqrt( x * x + y * y + z * z );

double altitudeValue = spinBoxAltitude->value();
double azimuthValue = spinBoxAzimuth->value();
if ( fabs( altitudeValue ) == 90 )
{
x = 0;
z = 0;
y = -vectorMagnitude * fabs( altitudeValue ) / altitudeValue;
}
else
{
if ( horizontalVectorMagnitude == 0 )
horizontalVectorMagnitude = vectorMagnitude * cos( altitudeValue / 180 * M_PI );;

x = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
z = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );
y = -tan( altitudeValue / 180 * M_PI ) * horizontalVectorMagnitude;
}
double horizontalVectorMagnitude = cos( altitudeValue / 180 * M_PI );
mDirectionX = -horizontalVectorMagnitude * sin( azimuthValue / 180 * M_PI );
mDirectionZ = horizontalVectorMagnitude * cos( azimuthValue / 180 * M_PI );
mDirectionY = -sin( altitudeValue / 180 * M_PI );

whileBlocking( spinDirectionX )->setValue( x );
whileBlocking( spinDirectionZ )->setValue( z );
whileBlocking( spinDirectionY )->setValue( y );
whileBlocking( sliderAltitude )->setValue( altitudeValue );

whileBlocking( sliderAltitude )->setValue( altitudeValue );
updateCurrentDirectionalLightParameters();
}

Expand Down
9 changes: 5 additions & 4 deletions src/app/3d/qgslightswidget.h
Expand Up @@ -52,17 +52,18 @@ class QgsLightsWidget : public QWidget, private Ui::QgsLightsWidget
void updateCurrentDirectionalLightParameters();
void onAddDirectionalLight();
void onRemoveDirectionalLight();
void onSpinBoxDirectionChanged();
void onSpinBoxAzimuthChange();
void onSpinBoxAltitudeChange();
void setAzimuthAltitude();
void onDirectionChange();
private:
void updateLightsList();
void updateDirectionalLightsList();

private:
QList<QgsPointLightSettings> mPointLights;
QList<QgsDirectionalLightSettings> mDirectionalLights;
// QwtCompass *mDirectionCompass = nullptr;
double mDirectionX = 0;
double mDirectionY = -1;
double mDirectionZ = 0;
};

#endif // QGSLIGHTSWIDGET_H
194 changes: 90 additions & 104 deletions src/ui/3d/qgslightswidget.ui
Expand Up @@ -216,107 +216,7 @@
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0" colspan="3">
<layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="1">
<widget class="QgsDoubleSpinBox" name="spinDirectionZ">
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QgsDoubleSpinBox" name="spinDirectionX">
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QgsDoubleSpinBox" name="spinDirectionalIntensity">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsDoubleSpinBox" name="spinDirectionY">
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QgsColorButton" name="btnDirectionalColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Light Direction</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Intensity</string>
Expand Down Expand Up @@ -440,6 +340,95 @@
</item>
</layout>
</item>
<item row="7" column="1">
<widget class="QgsDoubleSpinBox" name="spinDirectionalIntensity">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>999999.000000000000000</double>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QgsColorButton" name="btnDirectionalColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Light Direction</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QGridLayout" name="gridLayout_5">
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="2">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="labelY">
<property name="text">
<string>--</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="labelX">
<property name="text">
<string>--</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="labelZ">
<property name="text">
<string>--</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item row="0" column="2">
Expand Down Expand Up @@ -507,9 +496,6 @@
<tabstop>cboDirectionalLights</tabstop>
<tabstop>btnAddDirectionalLight</tabstop>
<tabstop>btnRemoveDirectionalLight</tabstop>
<tabstop>spinDirectionX</tabstop>
<tabstop>spinDirectionY</tabstop>
<tabstop>spinDirectionZ</tabstop>
<tabstop>btnDirectionalColor</tabstop>
<tabstop>spinDirectionalIntensity</tabstop>
</tabstops>
Expand Down

0 comments on commit f31b955

Please sign in to comment.