Skip to content

Commit

Permalink
fix visu
Browse files Browse the repository at this point in the history
  • Loading branch information
cmigliorini committed Jul 14, 2020
1 parent d441f30 commit d5f0ef5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions symoroviz/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion symoroviz/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [], [], []
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5f0ef5

Please sign in to comment.