treat self.opts as private. provide accessors

This commit is contained in:
KIU Shueng Chuan 2021-07-19 04:52:49 +08:00
parent d9726dbcc1
commit 8a6640c419
2 changed files with 19 additions and 2 deletions

View File

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

View File

@ -308,6 +308,22 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.update() 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): def cameraPosition(self):
"""Return current position of camera based on center, dist, elevation, and azimuth""" """Return current position of camera based on center, dist, elevation, and azimuth"""
center = self.opts['center'] center = self.opts['center']