fix setCameraPosition not setting ele and azi in euler mode

This commit is contained in:
KIU Shueng Chuan 2021-07-17 11:03:18 +08:00
parent b5fc3d2a7e
commit ce4c6d95ed

View File

@ -284,21 +284,40 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
glPopMatrix() glPopMatrix()
def setCameraPosition(self, pos=None, distance=None, elevation=None, azimuth=None, rotation=None): def setCameraPosition(self, pos=None, distance=None, elevation=None, azimuth=None, rotation=None):
if rotation is not None:
# Alternatively, we could define that rotation overrides elevation and azimuth
if elevation is not None:
raise ValueError("cannot set both rotation and elevation")
if azimuth is not None:
raise ValueError("cannot set both rotation and azimuth")
if pos is not None: if pos is not None:
self.opts['center'] = pos self.opts['center'] = pos
if distance is not None: if distance is not None:
self.opts['distance'] = distance self.opts['distance'] = distance
if rotation is not None:
# set with quaternion if self.opts['rotationMethod'] == "quaternion":
self.opts['rotation'] = rotation # note that "quaternion" mode modifies only opts['rotation']
if elevation is not None or azimuth is not None:
eu = self.opts['rotation'].toEulerAngles()
if azimuth is not None:
eu.setZ(-azimuth-90)
if elevation is not None:
eu.setX(elevation-90)
self.opts['rotation'] = QtGui.QQuaternion.fromEulerAngles(eu)
if rotation is not None:
self.opts['rotation'] = rotation
else: else:
# set with elevation-azimuth, restored for compatibility # note that "euler" mode modifies only opts['elevation'] and opts['azimuth']
eu = self.opts['rotation'].toEulerAngles()
if azimuth is not None:
eu.setZ(-azimuth-90)
if elevation is not None: if elevation is not None:
eu.setX(elevation-90) self.opts['elevation'] = elevation
self.opts['rotation'] = QtGui.QQuaternion.fromEulerAngles(eu) if azimuth is not None:
self.opts['azimuth'] = azimuth
if rotation is not None:
eu = rotation.toEulerAngles()
self.opts['elevation'] = eu.x() + 90
self.opts['azimuth'] = -eu.z() - 90
self.update() self.update()
def cameraPosition(self): def cameraPosition(self):