from ctypes import *

class Physics:
	def __init__(self):
		"""
		Initialises a new ODE world.
		"""
		self.ode = CDLL("libode.so.0")
		self.dWorldID = self.ode.dWorldCreate()
	
	def SetGravity(self, gV):
		"""
		gV is the vector denoting the direction and strength of gravity.
		"""
		self.ode.dWorldSetGravity(self.dWorldID, gV[0], gV[1], gV[2])
	
	def SetERP(self, erp):
		"""
		erp is the error reduction parameter (see the ODE docs)
		"""
		self.ode.dWorldSetERP(self.dWorldID, erp)
	
	def GetERP(self):
		"""
		erp is the error reduction parameter (see the ODE docs)
		"""
		return self.ode.dWorldGetERP(self.dWorldID)
	
	def SetCFM(self, cfm):
		"""
		cfm is the constraint force miixing value (see the ODE docs)
		"""
		self.ode.dWorldSetCFM(self.dWorldID, cfm)
	
	def GetCFM(self):
		"""
		cfm is the constraint force miixing value (see the ODE docs)
		"""
		return self.ode.dWorldGetCFM(self.dWorldID)
	
	def Step(self, stepsize):
		"""
		Take a single normal step.
		"""
		self.ode.dWorldStep(self.dWorldID, stepsize)
	
	def QuickStep(self, stepsize):
		"""
		Take an ODE Quickstep.
		"""
		self.ode.dWorldQuickStep(self.dWorldID, stepsize)
	
	def MakeBody(self):
		return Body(self)
	
	def DelBody(self, body):
		self.ode.dBodyDestroy(body.dBodyID)
	
	def __del__(self):
		self.ode.dWorldDestroy(self.dWorldID)
	
class Body:
	def __init__(self, world):
		"""
		Creates a new ODE body in the world
		"""
		self.dBodyID = world.ode.dBodyCreate(world.WorldID)
	

phys = Physics()

