From: Scott P. <spr...@gm...> - 2010-11-17 00:33:08
|
I have a question about class inheritance in PyODE.... how does it work? I've tried to inherit the ode.Body class in my python code as follows: #!/usr/bin/env python import ode class Sphere(ode.Body): """Class representing a spherical rigid body""" def __init__(self, world, space, mass, radius): """Creates a new sphere and places it in the world""" # Create the base body class #super(Sphere, self).__init__(world) # using old style classes? ode.Body.__init__(self, world) # Set up some initial required values for the sphere self.shape = "sphere" self.radius = radius self.volume = 4. / 3. * pi * radius ** 3. self.space = space # Set up the main properties of the sphere self.setMass(mass) self.setRadius(radius) self.setGeom(space, radius) However, when I attempt to instantiate my Sphere class, I get an error complaining that the number of arguments I'm providing it are wrong, even though I can clearly see that that is not the case. In fact, I can only get my Sphere class to work at all if I recreate the Sphere.__init__ function to accept the same number of arguments as ode.Body.__init__. I tried out a couple of different ODE classes to see if this is true of any others, and it appears to be true for all PyODE classes. Can anyone show an example of using class inheritance with a PyODE base class and/or explain to me why class inheritance doesn't work? |