Commits

German Larrain  committed 01d6e0b

physics.adapters: reordered classes homogenously and defined sections; added a
workaround necessary because of the reordering.

  • Participants
  • Parent commits b4bd8e0

Comments (0)

Files changed (1)

File ars/model/physics/adapters.py

 
 from . import base, ode_objects_factories, signals
 
+#==============================================================================
+# Environment
+#==============================================================================
+
+
+class OdeEngine(base.Engine):
+
+	"""Adapter to the ODE physics engine"""
+
+	world_class = None  # we have to define it below OdeWorld's definition
+
+	# TODO: shouldn't this method be defined in parent?
+	@staticmethod
+	def create_joint_group():
+		return ode_objects_factories.create_ode_joint_group()
+
 
 class OdeWorld(base.World):
 
 		dispatcher.send(signals.WORLD_POST_STEP, sender=self)
 
 
-class OdeEngine(base.Engine):
-	"""Adapter to the ODE physics engine"""
+# This is a workaround necessary to solve the issue caused by the fact OdeWorld
+# is defined after OdeEngine thus the latter can't use the former in its own
+# definition (class attribute).
+OdeEngine.world_class = OdeWorld
 
-	world_class = OdeWorld
-
-	# TODO: shouldn't this method be defined in parent?
-	@staticmethod
-	def create_joint_group():
-		return ode_objects_factories.create_ode_joint_group()
+#==============================================================================
+# Parents
+#==============================================================================
 
 
 class OdeBody(object):
 		self._inner_object.setRotation(rot)
 		dispatcher.send(signals.BODY_POST_SET_ROTATION, sender=self)
 
+#==============================================================================
+# Bodies
+#==============================================================================
+
+
+class Box(OdeBody, base.Box):
+	def __init__(self, world, space, size, mass=None, density=None):
+		OdeBody.__init__(self, world, space, mass, density)
+		base.Box.__init__(self, size, mass, density)
+
+		body = ode_objects_factories.create_ode_box(
+			world._inner_object, size, mass, density)
+		geom = shapes.Box(space, size)
+		self._inner_object = body
+		self.attach_geom(geom)
+
+
+class Sphere(OdeBody, base.Sphere):
+	def __init__(self, world, space, radius, mass=None, density=None):
+		OdeBody.__init__(self, world, space, mass, density)
+		base.Sphere.__init__(self, radius, mass, density)
+
+		body = ode_objects_factories.create_ode_sphere(
+			world._inner_object, radius, mass, density)
+		geom = shapes.Sphere(space, radius)
+		self._inner_object = body
+		self.attach_geom(geom)
+
 
 class Capsule(OdeBody, base.Capsule):
 	def __init__(self, world, space, length, radius, mass=None, density=None):
 		geom = shapes.Cylinder(space, length, radius)
 		self._inner_object = body
 		self.attach_geom(geom)
-
-
-class Box(OdeBody, base.Box):
-	def __init__(self, world, space, size, mass=None, density=None):
-		OdeBody.__init__(self, world, space, mass, density)
-		base.Box.__init__(self, size, mass, density)
-
-		body = ode_objects_factories.create_ode_box(
-			world._inner_object, size, mass, density)
-		geom = shapes.Box(space, size)
-		self._inner_object = body
-		self.attach_geom(geom)
-
-
-class Sphere(OdeBody, base.Sphere):
-	def __init__(self, world, space, radius, mass=None, density=None):
-		OdeBody.__init__(self, world, space, mass, density)
-		base.Sphere.__init__(self, radius, mass, density)
-
-		body = ode_objects_factories.create_ode_sphere(
-			world._inner_object, radius, mass, density)
-		geom = shapes.Sphere(space, radius)
-		self._inner_object = body
-		self.attach_geom(geom)