@@ -51,16 +51,13 @@ QgsLightsWidget::QgsLightsWidget( QWidget *parent )
51
51
connect ( btnRemoveDirectionalLight, &QToolButton::clicked, this , &QgsLightsWidget::onRemoveDirectionalLight );
52
52
53
53
connect ( cboDirectionalLights, qgis::overload<int >::of ( &QComboBox::currentIndexChanged ), this , &QgsLightsWidget::onCurrentDirectionalLightChanged );
54
- connect ( spinDirectionX, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onSpinBoxDirectionChanged );
55
- connect ( spinDirectionY, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onSpinBoxDirectionChanged );
56
- connect ( spinDirectionZ, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onSpinBoxDirectionChanged );
57
54
connect ( spinDirectionalIntensity, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::updateCurrentDirectionalLightParameters );
58
55
connect ( btnDirectionalColor, &QgsColorButton::colorChanged, this , &QgsLightsWidget::updateCurrentDirectionalLightParameters );
59
56
60
57
connect ( dialAzimuth, &QSlider::valueChanged, [this ]( int value ) {spinBoxAzimuth->setValue ( ( value + 180 ) % 360 );} );
61
- connect ( spinBoxAzimuth, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onSpinBoxAzimuthChange );
62
- connect ( spinBoxAltitude, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onSpinBoxAltitudeChange );
63
58
connect ( sliderAltitude, &QSlider::valueChanged, spinBoxAltitude, &QgsDoubleSpinBox::setValue );
59
+ connect ( spinBoxAzimuth, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onDirectionChange );
60
+ connect ( spinBoxAltitude, qgis::overload<double >::of ( &QDoubleSpinBox::valueChanged ), this , &QgsLightsWidget::onDirectionChange );
64
61
65
62
tabWidget->setCurrentIndex ( QgsSettings ().value ( QStringLiteral ( " UI/last3DLightsTab" ), 1 ).toInt () );
66
63
}
@@ -118,12 +115,12 @@ void QgsLightsWidget::onCurrentDirectionalLightChanged( int index )
118
115
return ;
119
116
120
117
QgsDirectionalLightSettings light = mDirectionalLights .at ( index );
121
- whileBlocking ( spinDirectionX )-> setValue ( light.direction ().x () );
122
- whileBlocking ( spinDirectionY )-> setValue ( light.direction ().y () );
123
- whileBlocking ( spinDirectionZ )-> setValue ( light.direction ().z () );
118
+ mDirectionX = light.direction ().x ();
119
+ mDirectionY = light.direction ().y ();
120
+ mDirectionZ = light.direction ().z ();
124
121
whileBlocking ( btnDirectionalColor )->setColor ( light.color () );
125
122
whileBlocking ( spinDirectionalIntensity )->setValue ( light.intensity () );
126
- onSpinBoxDirectionChanged ();
123
+ setAzimuthAltitude ();
127
124
}
128
125
129
126
@@ -145,12 +142,16 @@ void QgsLightsWidget::updateCurrentLightParameters()
145
142
146
143
void QgsLightsWidget::updateCurrentDirectionalLightParameters ()
147
144
{
145
+ labelX->setText ( QString::number ( mDirectionX , ' f' , 2 ) );
146
+ labelY->setText ( QString::number ( mDirectionY , ' f' , 2 ) );
147
+ labelZ->setText ( QString::number ( mDirectionZ , ' f' , 2 ) );
148
+
148
149
int index = cboDirectionalLights->currentIndex ();
149
150
if ( index < 0 || index >= cboDirectionalLights->count () )
150
151
return ;
151
152
152
153
QgsDirectionalLightSettings light;
153
- light.setDirection ( QgsVector3D ( spinDirectionX-> value (), spinDirectionY-> value (), spinDirectionZ-> value () ) );
154
+ light.setDirection ( QgsVector3D ( mDirectionX , mDirectionY , mDirectionZ ) );
154
155
light.setColor ( btnDirectionalColor->color () );
155
156
light.setIntensity ( spinDirectionalIntensity->value () );
156
157
mDirectionalLights [index] = light;
@@ -218,88 +219,49 @@ void QgsLightsWidget::onRemoveDirectionalLight()
218
219
emit directionalLightsCountChanged ( cboDirectionalLights->count () );
219
220
}
220
221
221
- void QgsLightsWidget::onSpinBoxDirectionChanged ()
222
+ void QgsLightsWidget::setAzimuthAltitude ()
222
223
{
223
- double x = spinDirectionX->value ();
224
- double y = spinDirectionY->value ();
225
- double z = spinDirectionZ->value ();
226
224
double azimuthAngle;
227
225
double altitudeAngle;
228
226
229
- double horizontalVectorMagnitude = sqrt ( x * x + z * z );
227
+ double horizontalVectorMagnitude = sqrt ( mDirectionX * mDirectionX + mDirectionZ * mDirectionZ );
228
+
230
229
if ( horizontalVectorMagnitude == 0 )
231
230
azimuthAngle = 0 ;
232
231
else
233
232
{
234
- azimuthAngle = ( asin ( -x / horizontalVectorMagnitude ) ) / M_PI * 180 ;
235
- if ( z < 0 )
233
+ azimuthAngle = ( asin ( -mDirectionX / horizontalVectorMagnitude ) ) / M_PI * 180 ;
234
+ if ( mDirectionZ < 0 )
236
235
azimuthAngle = 180 - azimuthAngle;
237
236
azimuthAngle = std::fmod ( azimuthAngle + 360.0 , 360.0 );
238
237
}
239
238
240
-
241
239
dialAzimuth->setValue ( int ( azimuthAngle + 180 ) % 360 );
242
240
spinBoxAzimuth->setValue ( azimuthAngle );
243
241
244
242
if ( horizontalVectorMagnitude == 0 )
245
- altitudeAngle = y >= 0 ? 90 : -90 ;
243
+ altitudeAngle = mDirectionY >= 0 ? 90 : -90 ;
246
244
else
247
- altitudeAngle = -atan ( y / horizontalVectorMagnitude ) / M_PI * 180 ;
245
+ altitudeAngle = -atan ( mDirectionY / horizontalVectorMagnitude ) / M_PI * 180 ;
248
246
249
247
spinBoxAltitude->setValue ( altitudeAngle );
250
248
sliderAltitude->setValue ( altitudeAngle );
251
249
252
250
updateCurrentDirectionalLightParameters ();
253
251
}
254
252
255
- void QgsLightsWidget::onSpinBoxAzimuthChange ()
253
+ void QgsLightsWidget::onDirectionChange ()
256
254
{
257
- double x = spinDirectionX->value ();
258
- double z = spinDirectionZ->value ();
259
- double horizontalVectorMagnitude = sqrt ( x * x + z * z );
260
-
261
- double azimuthValue = spinBoxAzimuth->value ();
262
- x = -horizontalVectorMagnitude * sin ( azimuthValue / 180 * M_PI );
263
- z = horizontalVectorMagnitude * cos ( azimuthValue / 180 * M_PI );
264
-
265
- whileBlocking ( dialAzimuth )->setValue ( int ( azimuthValue + 180 ) % 360 );
266
- whileBlocking ( spinDirectionX )->setValue ( x );
267
- whileBlocking ( spinDirectionZ )->setValue ( z );
268
-
269
- updateCurrentDirectionalLightParameters ();
270
- }
271
-
272
- void QgsLightsWidget::onSpinBoxAltitudeChange ()
273
- {
274
- double x = spinDirectionX->value ();
275
- double y = spinDirectionY->value ();
276
- double z = spinDirectionZ->value ();
277
- double horizontalVectorMagnitude = sqrt ( x * x + z * z );
278
- double vectorMagnitude = sqrt ( x * x + y * y + z * z );
279
-
280
255
double altitudeValue = spinBoxAltitude->value ();
281
256
double azimuthValue = spinBoxAzimuth->value ();
282
- if ( fabs ( altitudeValue ) == 90 )
283
- {
284
- x = 0 ;
285
- z = 0 ;
286
- y = -vectorMagnitude * fabs ( altitudeValue ) / altitudeValue;
287
- }
288
- else
289
- {
290
- if ( horizontalVectorMagnitude == 0 )
291
- horizontalVectorMagnitude = vectorMagnitude * cos ( altitudeValue / 180 * M_PI );;
292
257
293
- x = -horizontalVectorMagnitude * sin ( azimuthValue / 180 * M_PI );
294
- z = horizontalVectorMagnitude * cos ( azimuthValue / 180 * M_PI );
295
- y = - tan ( altitudeValue / 180 * M_PI ) * horizontalVectorMagnitude ;
296
- }
258
+ double horizontalVectorMagnitude = cos ( altitudeValue / 180 * M_PI );
259
+ mDirectionX = - horizontalVectorMagnitude * sin ( azimuthValue / 180 * M_PI );
260
+ mDirectionZ = horizontalVectorMagnitude * cos ( azimuthValue / 180 * M_PI );
261
+ mDirectionY = - sin ( altitudeValue / 180 * M_PI );
297
262
298
- whileBlocking ( spinDirectionX )->setValue ( x );
299
- whileBlocking ( spinDirectionZ )->setValue ( z );
300
- whileBlocking ( spinDirectionY )->setValue ( y );
301
- whileBlocking ( sliderAltitude )->setValue ( altitudeValue );
302
263
264
+ whileBlocking ( sliderAltitude )->setValue ( altitudeValue );
303
265
updateCurrentDirectionalLightParameters ();
304
266
}
305
267
0 commit comments