Its hard to guess as you don't provide the whole example - all self.Refresh are commented out and its not clear if you use the wxApp OnIdle message pump for updates. The other example (osgviewerWX.py) in the repository might give you some pointers.

H


R Fritz wrote:
I've the beginnings of a simple light-fixture modeling component in wxPython and I am trying to use osgswig (2.2.0.1 version) as a base. I've started out by copying the file loading example which uses osgUtil.SceneView(). The code successfully loads the geometry of a lighting fixture (considering that this is done with readNodeFile that's not terribly surprising). Unfortunately, thereafter I can't maneuver the view with the mouse. Sometimes, I can't even find the fixture model. I suspect I'm doing something dumb. My code--almost the sample code--is attached--any ideas? (Getting a newer version of osgswig would be nice, but as I've written here, I've run into build problems, and I would rather not spend the time chasing them down.)

Randolph

#!/usr/bin/env python

# import wxWidgets stuff
import wx
import wx.glcanvas

# import OpenSceneGraph wrapper
import osg
import osgUtil
import osgDB

class OSGLumView(wx.glcanvas.GLCanvas):
    def __init__(self,parent,id):
        wx.glcanvas.GLCanvas.__init__(self,parent,id)
        sv = self.sceneview = osgUtil.SceneView()
        self.rootnode = osg.MatrixTransformRef(osg.MatrixTransform())
        sv.setSceneData(self.rootnode.get())

        x,y = self.GetClientSize()

        self.oldX = 0
        self.oldY = 0

        sv.setDefaults()

        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterWindow)
        self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)

        sv.init()


    def AddGeom(self, geom):
        print "AddGeom"
        self.rootnode.addChild(geom)
        # self.Refresh(False)


    def OnMouse(self, evt):
        if ((evt.Dragging() == True) and (evt.LeftIsDown() == True)):
            x = evt.GetX() - self.oldY
            y = evt.GetY() - self.oldY

            self.sceneview.setViewMatrixAsLookAt(
                osg.Vec3f(0,y,x), osg.Vec3f(0,0,0), osg.Vec3f(0,1,0))

            # self.Refresh(False)

            self.oldX = evt.GetX()
            self.oldY = evt.GetY()


        if ((evt.Dragging() == True) and (evt.RightIsDown() == True)) :
            m = self.rootnode.getMatrix()

            x,y = self.GetClientSize()

            rot = osg.Matrixd()

            rot.makeRotate(self.oldX - evt.GetX(), osg.Vec3f(1,0,0))

            m.postMult(rot)

            # self.Refresh(False)

            self.oldX = evt.GetX()
            self.oldY = evt.GetY()

    def Clear(self):
        self.rootnode.removeChild(0,self.rootnode.getNumChildren())
        # self.Refresh(False)


    def OnEnterWindow(self, evt):
        self.SetFocus()

    def OnEraseBackground(self, evt):
        pass

    def OnSize(self, evt):
        x,y = self.GetClientSize()
        self.SetCurrent()
self.sceneview.setViewport(0,0,x,y) evt.Skip()


    def OnPaint(self, evt):

        if (0 == self.GetContext()) :
                return

        dc = wx.PaintDC(self)
        self.SetCurrent()
        self.sceneview.update()
        self.sceneview.cull()
        self.sceneview.draw()
        self.SwapBuffers()
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


--
Hartmut Seichter, PhD (HKU), Dipl-Ing.(BUW), Postdoctoral Fellow, HITLabNZ

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to