From d5f0ef5f264a50dd5ea907d480682e69c8ada0a8 Mon Sep 17 00:00:00 2001 From: Christophe Migliorini Date: Tue, 14 Jul 2020 15:24:11 +0200 Subject: [PATCH] fix visu --- symoroviz/graphics.py | 15 +++++++++------ symoroviz/primitives.py | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/symoroviz/graphics.py b/symoroviz/graphics.py index 294a678..210974a 100644 --- a/symoroviz/graphics.py +++ b/symoroviz/graphics.py @@ -9,7 +9,7 @@ import wx import wx.lib.agw.floatspin as FS -from wx.glcanvas import GLCanvas +from wx.glcanvas import GLCanvas, GLContext import OpenGL.GL as gl import OpenGL.GLU as glu @@ -34,6 +34,7 @@ #TODO: Random button class VizGlCanvas(GLCanvas): + def __init__(self, parent, robo, params, size=(600, 600)): super(VizGlCanvas, self).__init__(parent, size=size) self.Bind(wx.EVT_PAINT, self.OnPaintAll) @@ -59,6 +60,8 @@ def __init__(self, parent, robo, params, size=(600, 600)): self.construct_hierarchy() self.dgms = {} self.l_solver = None + self._glContext = GLContext(self) + def OnEraseBackground(self, event): # Do nothing, to avoid flashing on MSW. @@ -140,8 +143,8 @@ def construct_hierarchy(self): def OnSize(self, event): size = self.size = self.GetClientSize() - if self.GetContext(): - self.SetCurrent() + if self._glContext: + self._glContext.SetCurrent(self) gl.glViewport(0, 0, size.width, size.height) #gl.glMatrixMode(gl.GL_PROJECTION) #gl.glLoadIdentity() @@ -244,7 +247,7 @@ def centralize_to_frame(self, index): self.Refresh(False) def OnPaintAll(self, event): - self.SetCurrent() + self._glContext.SetCurrent(self) if not self.init: self.InitGL() self.init = 1 @@ -469,7 +472,7 @@ def init_ui(self): choices.append("Frame " + str(jnt.index)) self.drag_pos = None self.clb_frames = wx.CheckListBox(self.p, choices=choices) - self.clb_frames.SetChecked(range(len(choices))) + self.clb_frames.SetCheckedItems(range(len(choices))) self.clb_frames.Bind(wx.EVT_CHECKLISTBOX, self.CheckFrames) self.clb_frames.Bind(wx.EVT_LISTBOX, self.SelectFrames) grd_szr_control.Add( @@ -573,7 +576,7 @@ def OnShowAllFrames(self, _): else: indices = [] self.canvas.show_frames(indices) - self.clb_frames.SetChecked(indices) + self.clb_frames.SetCheckedItems(indices) def update_spin_controls(self): for ctrl in self.spin_ctrls.values(): diff --git a/symoroviz/primitives.py b/symoroviz/primitives.py index c7bda5f..92c5900 100644 --- a/symoroviz/primitives.py +++ b/symoroviz/primitives.py @@ -9,6 +9,7 @@ from numpy import sin, cos, pi +import ctypes def create_cyl_array(radius, length, n_segments, centered=True): vertices, indices, normals = [], [], [] @@ -51,7 +52,7 @@ def create_sphere_array(radius, n_lat, n_long): normals += xn, yn, zn vertices += (x, y, z) # top and bottom indices - for i, start in enumerate([2, len(vertices)/3 - n_long]): + for i, start in enumerate([2, int(len(vertices)/3) - n_long]): for j in range(n_long): indices += (i, j + start, (j + 1) % n_long + start) # in-between