implement set/get for cameraParams

This commit is contained in:
KIU Shueng Chuan 2021-07-19 06:57:07 +08:00
parent 8a6640c419
commit 394b0dd75c
2 changed files with 17 additions and 19 deletions

View File

@ -48,10 +48,9 @@ class GLPainterItem(pg.opengl.GLGraphicsItem.GLGraphicsItem):
painter.drawText(rect, af.AlignBottom | af.AlignLeft, 'BL')
painter.drawText(rect, af.AlignBottom | af.AlignRight, 'BR')
opts = self.view().getCameraPosition()
opts['fov'] = self.view().fov()
opts = self.view().cameraParams()
lines = []
center = opts['pos']
center = opts['center']
lines.append(f"center : ({center.x():.1f}, {center.y():.1f}, {center.z():.1f})")
for key in ['distance', 'fov', 'elevation', 'azimuth']:
lines.append(f"{key} : {opts[key]:.1f}")

View File

@ -308,22 +308,6 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.update()
def getCameraPosition(self):
opts = { 'pos': self.opts['center'],
'distance' : self.opts['distance'] }
if self.opts['rotationMethod'] == "quaternion":
opts['rotation'] = self.opts['rotation']
else:
opts['elevation'] = self.opts['elevation']
opts['azimuth'] = self.opts['azimuth']
return opts
def setFov(self, fov):
self.opts['fov'] = fov
def fov(self):
return self.opts['fov']
def cameraPosition(self):
"""Return current position of camera based on center, dist, elevation, and azimuth"""
center = self.opts['center']
@ -341,6 +325,21 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
)
return pos
def setCameraParams(self, **kwds):
valid_keys = {'center', 'rotation', 'distance', 'fov', 'elevation', 'azimuth'}
if not set(kwds).issubset(valid_keys):
raise ValueError(f'valid keywords are {valid_keys}')
self.setCameraPosition(pos=kwds.get('center'), distance=kwds.get('distance'),
elevation=kwds.get('elevation'), azimuth=kwds.get('azimuth'),
rotation=kwds.get('rotation'))
if 'fov' in kwds:
self.opts['fov'] = kwds['fov']
def cameraParams(self):
valid_keys = {'center', 'rotation', 'distance', 'fov', 'elevation', 'azimuth'}
return { k : self.opts[k] for k in valid_keys }
def orbit(self, azim, elev):
"""Orbits the camera around the center position. *azim* and *elev* are given in degrees."""
if self.opts['rotationMethod'] == 'quaternion':