# Copyright (c) 2007 SIEGE Development Team
# All rights reserved.
#
# This file is part of libSIEGE.
#
# This software is copyrighted work licensed under the terms of the
# 2-clause BSD license. Please consult the file "license.txt" for
# details.
#
# If you did not recieve the file with this program, please email
# Tim Chas <darkuranium@gmail.com>.

from siege.common cimport *
cimport body
from space cimport Space

cdef class Body:
	def __init__(self, Space space, SGenum type):
		assert self.handle is NULL
		
		if space is None:
			self.handle = sgPhysicsBodyCreate(NULL, type)
		else:
			self.handle = sgPhysicsBodyCreate(space.handle, type)
		if self.handle is NULL:
			raise MemoryError()
		sgPhysicsBodySetData(self.handle, <void*>self)
		self.data = None

	def __dealloc__(self):
		if self.handle is not NULL:
			self.destroy()

	cpdef destroy(self):
		assert self.handle is not NULL
		
		sgPhysicsBodyDestroy(self.handle)
		self.handle = NULL

	property data:
		def __set__(self, data):
			assert self.handle is not NULL
			
			self.pydata = data
		def __get__(self):
			assert self.handle is not NULL
			
			return self.pydata
		def __del__(self):
			self.data = None

	property pos:
		def __set__(self, p):
			assert self.handle is not NULL
			
			sgPhysicsBodySetPos(self.handle, p[0], p[1])
		def __get__(self):
			assert self.handle is not NULL
			
			cdef float x, y
			sgPhysicsBodyGetPos(self.handle, &x, &y)
			return (x, y)
	property x:
		def __set__(self, x):
			assert self.handle is not NULL
			
			sgPhysicsBodySetPosX(self.handle, x)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetPosX(self.handle)
	property y:
		def __set__(self, y):
			assert self.handle is not NULL
			
			sgPhysicsBodySetPosY(self.handle, y)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetPosY(self.handle)

	property angleRads:
		def __set__(self, rads):
			assert self.handle is not NULL
			
			sgPhysicsBodySetAngleRads(self.handle, rads)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetAngleRads(self.handle)
	property angleDegs:
		def __set__(self, degs):
			assert self.handle is not NULL
			
			sgPhysicsBodySetAngleDegs(self.handle, degs)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetAngleDegs(self.handle)

	property vel:
		def __set__(self, v):
			assert self.handle is not NULL
			
			sgPhysicsBodySetVel(self.handle, v[0], v[1])
		def __get__(self):
			assert self.handle is not NULL
			
			cdef float x, y
			sgPhysicsBodyGetVel(self.handle, &x, &y)
			return (x, y)
	property xVel:		
		def __set__(self, x):
			assert self.handle is not NULL
			
			sgPhysicsBodySetVelX(self.handle, x)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetVelX(self.handle)
	property yVel:
		def __set__(self, y):
			assert self.handle is not NULL
			
			sgPhysicsBodySetVelY(self.handle, y)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetVelY(self.handle)
			
	property angVelRads:
		def __set__(self, rads):
			assert self.handle is not NULL
			
			sgPhysicsBodySetAngVelRads(self.handle, rads)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetAngVelRads(self.handle)
	property angVelDegs:
		def __set__(self, degs):
			assert self.handle is not NULL
			
			sgPhysicsBodySetAngVelDegs(self.handle, degs)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetAngVelDegs(self.handle)

	property mass:
		def __set__(self, mass):
			assert self.handle is not NULL
			
			sgPhysicsBodySetMass(self.handle, mass)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetMass(self.handle)

	property moment:
		def __set__(self, moment):
			assert self.handle is not NULL
			
			sgPhysicsBodySetMoment(self.handle, moment)
		def __get__(self):
			assert self.handle is not NULL
			
			return sgPhysicsBodyGetMoment(self.handle)
