Commits

German Larrain  committed 8844007

physics: new classes base.World and adapters.OdeWorld

  • Participants
  • Parent commits d8026cd

Comments (0)

Files changed (2)

File ars/model/physics/adapters.py

 import base
 
 
+class OdeWorld(base.World):
+	def __init__(self, gravity=(0.0,-9.81,0.0), ERP=0.8, CFM=1E-10, *args,
+			**kwargs):
+		"""Create an ODE world object.
+
+		:param gravity: Gravity acceleration.
+		:type gravity: 3 floats tuple.
+		:param ERP: Error Reduction Parameter.
+		:type ERP: float.
+		:param CFM: Constraint Force Mixing.
+		:type CFM: float.
+
+		"""
+		super(OdeWorld, self).__init__(gravity, *args, **kwargs)
+
+		world = ode.World()
+		world.setGravity(gravity)
+		world.setERP(ERP)
+		world.setCFM(CFM)
+		self._inner_object = world
+
+	@property
+	def gravity(self):
+		return self._inner_object.getGravity()
+
+	def step(self, time_step):
+		self._inner_object.step(time_step)
+
+
 class OdeEngine(base.Engine):
 	"""Adapter to the ODE physics engine"""
 

File ars/model/physics/base.py

-from abc import ABCMeta, abstractmethod
+from abc import ABCMeta, abstractmethod, abstractproperty
 
 import ars.exceptions as exc
 
 #	def __init__(self):
 #		raise NotImplementedError()
 
+
+class World:
+	__metaclass__ = ABCMeta
+
+	@abstractmethod
+	def __init__(self, gravity, *args, **kwargs):
+		self._inner_object = None
+
+	@property
+	def inner_object(self):
+		return self._inner_object
+
+	@abstractproperty
+	def gravity(self):
+		raise NotImplementedError()
+
+	@abstractmethod
+	def step(self, time_step):
+		raise NotImplementedError()
+
+
 class Body:
 	__metaclass__ = ABCMeta