Commits

German Larrain  committed 93376e4

physics.adapters: modified objects constructors to use the new module instead
of calling ODE directly (analogous to 0a7f5f444b8e).

  • Participants
  • Parent commits 429f62a

Comments (0)

Files changed (1)

File ars/model/physics/adapters.py

 from ...lib.pydispatch import dispatcher
 from ..collision import adapters as shapes
 
-from . import base, signals
+from . import base, ode_objects_factories, signals
 
 
 class OdeWorld(base.World):
 
 		"""
 		super(OdeWorld, self).__init__(gravity, *args, **kwargs)
-		self._inner_object = _create_ode_world(gravity, ERP, CFM)
+		self._inner_object = ode_objects_factories.create_ode_world(
+			gravity, ERP, CFM)
 
 	@property
 	def gravity(self):
 		OdeBody.__init__(self, world, space, mass, density)
 		base.Capsule.__init__(self, length, radius, mass, density)
 
-		body = _create_ode_capsule(world, length, radius, mass, density)
+		body = ode_objects_factories.create_ode_capsule(
+			world, length, radius, mass, density)
 		geom = shapes.Capsule(space, length, radius)
 		self._inner_object = body
 		self.attach_geom(geom)
 		OdeBody.__init__(self, world, space, mass, density)
 		base.Cylinder.__init__(self, length, radius, mass, density)
 
-		body = _create_ode_cylinder(world, length, radius, mass, density)
+		body = ode_objects_factories.create_ode_cylinder(
+			world, length, radius, mass, density)
 		geom = shapes.Cylinder(space, length, radius)
 		self._inner_object = body
 		self.attach_geom(geom)
 		OdeBody.__init__(self, world, space, mass, density)
 		base.Box.__init__(self, size, mass, density)
 
-		body = _create_ode_box(world, size, mass, density)
+		body = ode_objects_factories.create_ode_box(
+			world, size, mass, density)
 		geom = shapes.Box(space, size)
 		self._inner_object = body
 		self.attach_geom(geom)
 		OdeBody.__init__(self, world, space, mass, density)
 		base.Sphere.__init__(self, radius, mass, density)
 
-		body = _create_ode_sphere(world, radius, mass, density)
+		body = ode_objects_factories.create_ode_sphere(
+			world, radius, mass, density)
 		geom = shapes.Sphere(space, radius)
 		self._inner_object = body
 		self.attach_geom(geom)
-
-#==============================================================================
-# Private functions
-#==============================================================================
-
-
-def _create_ode_world(gravity=G_VECTOR, ERP=0.8, CFM=1E-10):
-	"""Create an ODE world object.
-	
-	:return: world
-	:rtype: :class:`ode.World`
-
-	"""
-	world = ode.World()
-	world.setGravity(gravity)
-	world.setERP(ERP)
-	world.setCFM(CFM)
-	return world
-
-
-def _create_ode_capsule(world, length, radius, mass=None, density=None):
-	"""Create an ODE capsule body.
-
-	:return: capsule body
-	:rtype: :class:`ode.Body`
-
-	"""
-	capsule_direction = 3  # z-axis
-	body = ode.Body(world._inner_object)
-
-	if mass is not None:
-		m = ode.Mass()
-		m.setCapsuleTotal(mass, capsule_direction, radius, length)
-		body.setMass(m)
-	elif density is not None:
-		m = ode.Mass()
-		m.setCapsule(density, capsule_direction, radius, length)
-		body.setMass(m)
-
-	# set parameters for drawing the body
-	# TODO: delete this, because it is related to the original implementation
-	body.shape = "capsule"
-	body.length = length
-	body.radius = radius
-
-	return body
-
-
-def _create_ode_cylinder(world, length, radius, mass=None, density=None):
-	"""Create an ODE cylinder body.
-
-	:return: cylinder body
-	:rtype: :class:`ode.Body`
-
-	"""
-	cylinderDirection = 3  # Z-axis
-	body = ode.Body(world._inner_object)
-
-	if mass is not None:
-		m = ode.Mass()
-		m.setCylinderTotal(mass, cylinderDirection, radius, length)
-		body.setMass(m)
-	elif density is not None:
-		m = ode.Mass()
-		m.setCylinder(density, cylinderDirection, radius, length)
-		body.setMass(m)
-
-	return body
-
-
-def _create_ode_box(world, size, mass=None, density=None):
-	"""Create an ODE box body.
-
-	:return: box body
-	:rtype: :class:`ode.Body`
-
-	"""
-	body = ode.Body(world._inner_object)
-
-	if mass is not None:
-		m = ode.Mass()
-		m.setBoxTotal(mass, *size)
-		body.setMass(m)
-	elif density is not None:
-		m = ode.Mass()
-		m.setBox(density, *size)
-		body.setMass(m)
-
-	return body
-
-
-def _create_ode_sphere(world, radius, mass=None, density=None):
-	"""Create an ODE sphere body.
-
-	:return: sphere body
-	:rtype: :class:`ode.Body`
-
-	"""
-	body = ode.Body(world._inner_object)
-
-	if mass is not None:
-		m = ode.Mass()
-		m.setSphereTotal(mass, radius)
-		body.setMass(m)
-	elif density is not None:
-		m = ode.Mass()
-		m.setSphere(density, radius)
-		body.setMass(m)
-
-	return body