If you're looking for something simple-to-program, you'll likely want to
go with one of the scenegraph-based systems, rather than raw OpenGL.
OpenGLContext has a demo wherein a rotating cube is stopped/started by
clicking on a wxPython button. With something like OpenGLContext, you
create a (VRML97 for OpenGLContext) scene with your 3D modeler, giving
each car/cone a DEF name in your modeler that you then access from your
simulation code to get pointers to the Transform nodes. Setting
someTransform.translation and someTransform.rotation then lets you
move/rotate individual cars.
Depending on how you want to drive the animation, you can either use an
internal timer (i.e. one provided by the scenegraph library) or just
drive the animation(s) from a wxPython one. The wx_with_controls.py
sample mentioned uses a scenegraph timer (they tend to be more flexible,
offering speed control, start/stop/reverse and the like), but if you
know wxPython already it shouldn't be too hard to translate that to
wxPython operations.
To give you an idea, this is what the sample is doing to get it's (very
basic) animation:
def OnTimerFraction( self, event ):
"""Update our rotation from the timer event"""
self.sg.children[0].rotation = (
0,1,0,event.fraction()* 3.14149*2
)
def OnButtonPause( self, event ):
"""Handle the wxPython event from our button"""
if self.rotating:
self.time.pause()
else:
self.time.resume()
self.rotating = not self.rotating
the events that come in are scenegraph events, not wxPython events
there. In the first method, a particular node in the scenegraph is
rotated about the 0,1,0 axis, with its rotation as a function of the
fraction() of the time-cycle represented by the event. The
OnButtonPause method is taking a wxPython event and using it to modify
the Timer (i.e. pause/resume it). The scenegraph engine takes care of
scheduling redraws when the scenegraph is changed.
The same basic idea works for any scenegraph engine, such as Pivy,
Vpython, or the like, though I don't know of any others which are able
to run under wxPython. If that isn't a hard requirement, your choice of
scenegraph platforms expands significantly. Note: if you're intending
to use multiple windows, wxPython likely isn't a good choice ATM, as it
has a bug that makes multiple window interactions nonfunctional. My
personal recommendation for something this small would probably be
Vpython, which is targeted at those looking to create simple educational
simulations. Oh, I realise this is a long shot, but if your goal is
court rendering, be very careful and read a lot, there's quite a few
non-intuitive rules surrounding that stuff.
If you really do want to program "to the metal" in raw OpenGL, then
expect to be storing a model of your system somewhere (i.e.
position/location for each thing), and during rendering of each frame,
use that model to control the creation of the transformation matrix for
each object (and be sure to push/pop the matrix stack for each object).
That's what the scenegraph is doing for you under the covers, of course.
Enjoy yourself,
Mike
AP Meyer wrote:
> Dear PyOpenGL users
>
> For a simulation project I would like to use the wxPython GLCanvas for
> animated visualisation.
...
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
|