Author: DavidCzech
Date: 2008-03-17 19:10:51 -0400 (Mon, 17 Mar 2008)
New Revision: 1154

Modified:
   trunk/pysoy/src/atoms/Vector.pxi
   trunk/pysoy/src/atoms/soy.atoms.pxd
Log:
No Ticket: More work on Vector

Modified: trunk/pysoy/src/atoms/Vector.pxi
===================================================================
--- trunk/pysoy/src/atoms/Vector.pxi    2008-03-17 21:26:04 UTC (rev 1153)
+++ trunk/pysoy/src/atoms/Vector.pxi    2008-03-17 23:10:51 UTC (rev 1154)
@@ -23,7 +23,57 @@
     An atom that helps with 3D math
   '''
   def __cinit__(self, position=None, *args, **keywords) :
-    return
+    if position:
+      self._position[0] = position[0]
+      self._position[1] = position[1]
+      self._position[2] = position[2]
+      
   def __add__(self,other):
-    return
-  
\ No newline at end of file
+    if isinstance(other,Vector):
+      return (self._position[0] + other[0],
+               self._position[1] + other[1],
+               self._position[2] + other[2])
+  def __mul__(self,other):
+    cdef float* _position
+    if isinstance(other, Vector) :
+      raise TypeError("Must multiply with an integer, use cross or dot with 
Vectors")
+    if isinstance(other, int):
+      self._position[0] * other
+      self._position[1] * other
+      self._position[2] * other
+    return (self.x,self.y,self.z)
+    
+  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._position[index] 
+  
+  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')
+    if type(index) != int :
+      raise TypeError('Vector index must be an int')
+    if index > 2 or index < 0 :
+      raise IndexError('Vector index out of range')
+    self._position[index]=value
+  property x :
+    def __get__(self) :   
+      return self._position[0]
+    def __set__(self, value) :
+      self._position[0] = value
+
+
+  property y :
+    def __get__(self) :   
+      return self._position[1]
+    def __set__(self, value) :
+      self._position[1] = value
+
+
+  property z :
+    def __get__(self) :   
+      return self._position[2]
+    def __set__(self, value) :
+      self._position[2] = value
\ No newline at end of file

Modified: trunk/pysoy/src/atoms/soy.atoms.pxd
===================================================================
--- trunk/pysoy/src/atoms/soy.atoms.pxd 2008-03-17 21:26:04 UTC (rev 1153)
+++ trunk/pysoy/src/atoms/soy.atoms.pxd 2008-03-17 23:10:51 UTC (rev 1154)
@@ -22,8 +22,8 @@
 cimport soy._internals
 cimport soy.models
 cimport soy.materials
+cimport ode
 
-
 cdef class Vertex :
   cdef soy._datatypes.VertexList  _list
   cdef int                        _index
@@ -36,3 +36,5 @@
   cdef void*                      _mutex
 
 
+cdef class Vector :
+  cdef ode.dVector3 _position
\ No newline at end of file

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to