Author: ArcRiley Date: 2008-03-09 21:00:03 -0400 (Sun, 09 Mar 2008) New Revision: 1120
Modified: trunk/pysoy/src/_datatypes/BodyPosition.pxi Log: Ticket #945 : * code formatting cleanup and added comments * reorganized def's alphabetically (being anal) * fixed non-scene __setitem__ Modified: trunk/pysoy/src/_datatypes/BodyPosition.pxi =================================================================== --- trunk/pysoy/src/_datatypes/BodyPosition.pxi 2008-03-10 00:43:45 UTC (rev 1119) +++ trunk/pysoy/src/_datatypes/BodyPosition.pxi 2008-03-10 01:00:03 UTC (rev 1120) @@ -1,4 +1,4 @@ -# PySoy's soy._datatypes.BodyPosition +# PySoy's soy._datatypes.BodyPosition class # # Copyright (C) 2006,2007,2008 PySoy Group # @@ -17,6 +17,7 @@ # # $Id$ + cdef class BodyPosition : '''soy._datatypes.BodyPosition @@ -26,7 +27,22 @@ def __cinit__(self, parent) : self._body = parent + + + def __getitem__(self, index) : + if type(index) != int : + raise TypeError('Position index must be an int') + if index > 2 or index < 0 : + raise IndexError('Position index out of range') + return self._body._position[index] + + def __repr__(self) : + return '(%f, %f, %f)' % (self._body._position[0], + self._body._position[1], + self._body._position[2]) + + def __setitem__(self, index, value) : if type(value) != int and type(value) != long and type(value) != float : raise TypeError('Value must be an int, long, or float') @@ -34,38 +50,30 @@ raise TypeError('Position index must be an int') if index > 2 or index < 0 : raise IndexError('Position index out of range') - if self._body._bodyID != NULL : + if self._body._bodyID == NULL : + # + # If not in a scene set value directly + self._body._position[index] = value + else : + # + # If in a scene, steplock and use ODE (<soy.scenes.Scene> self._body._scene)._stepLock() if index == 0 : ode.dBodySetPosition(self._body._bodyID, value, self._body._position[1], self._body._position[2]) - if index == 1 : + elif index == 1 : ode.dBodySetPosition(self._body._bodyID, self._body._position[0], value, self._body._position[2]) - if index == 2 : + else: ode.dBodySetPosition(self._body._bodyID, self._body._position[0], self._body._position[1], value) (<soy.scenes.Scene> self._body._scene)._stepUnLock() - else : - if index == 0 - self._body._position[0] = value - else : - self._body._position[0] = index[0] - if index == 1 : - self._body._position[1] = value - else : - self._body._position[1] = index[1] - if index == 2 : - self._body._position[2] = value - else : - self._body._position[2] = index[2] - def __getitem__(self, index) : - if type(index) != int : - raise TypeError('Position index must be an int') - if index > 2 or index < 0 : - raise IndexError('Position index out of range') - return self._body._position[index] + + ############################################################################ + # + # Properties + # property x : '''soy._datatypes.BodyPosition.x @@ -77,6 +85,7 @@ def __set__(self, value) : self[0] = value + property y : '''soy._datatypes.BodyPosition.y @@ -87,6 +96,7 @@ def __set__(self, value) : self[1] = value + property z : '''soy._datatypes.BodyPosition.z _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn