Commits

Alberto Torres committed 135a75e

Quaternions working properly.

  • Participants
  • Parent commits dff8ef8

Comments (0)

Files changed (13)

File CMakeLists.txt

 # How to Cython the .pyx file
 add_custom_command(
   DEPENDS ${PYGAMEKIT_SRC}
-  OUTPUT gamekit.cpp
+  OUTPUT gamekit.cpp mathutils.cpp
   COMMAND ${CYTHON_EXECUTABLE} --cplus --fast-fail -o gamekit.cpp
          "${CMAKE_CURRENT_SOURCE_DIR}/gamekit.pyx"
   COMMAND ${CYTHON_EXECUTABLE} --cplus --fast-fail -o mathutils.cpp
 )
 list(APPEND ADDITIONAL_MAKE_CLEAN_FILES gamekit.cpp)
 
+set(PYGAMEKIT_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
+
 #add_custom_target(gamekit.cpp DEPENDS gamekit.pyx)
 #add_dependencies(gamekit.cpp gamekit.pyx)
 
         self.data = EventData()
         
     def __add__(self, f):
-        print str(type(f))
-        if type(f)==Event:
+        if isinstance(f, Event):
             raise TypeError("Use boolean operations to combine events.")
         elif hasattr(f,'__iter__'):
             if [x for x in f if not hasattr(x,'__call__')]:
 include "engine.pxi"
 include "blendfile.pxi"
 include "input.pxi"
-
+print     GK_PLATFORM,  GK_PLATFORM_ANDROID,    GK_PLATFORM_LINUX
 import sys
 
 #gkLogger_enable(to_stdstring("AppCppDemo.log"), GK_CPP_VERBOSE_LOG)
 #prefs.useBulletDbvt = False
 prefs.enableshadows = 0
 prefs.shadowtechnique = to_stdstring("textureadditive")
+
+PLATFORM = ""
+if GK_PLATFORM == GK_PLATFORM_WIN32:
+    PLATFORM = "WIN32"
+elif GK_PLATFORM == GK_PLATFORM_APPLE:
+    PLATFORM = "APPLE"
+elif GK_PLATFORM == GK_PLATFORM_APPLE_IOS:
+    PLATFORM = "APPLE_IOS"
+elif GK_PLATFORM == GK_PLATFORM_LINUX:
+    PLATFORM = "LINUX"
+elif GK_PLATFORM == GK_PLATFORM_ANDROID:
+    PLATFORM = "ANDROID"
+    

File gameobject.pxd

 from prerequisites cimport *
 from variable cimport *
 from scene cimport *
+cimport gkmath
 
 cdef extern from "OgreSceneNode.h":
     cdef cppclass Ogre_SceneNode "Ogre::SceneNode":
         gkTransformState&  getTransformState()
         gkMatrix4&         getTransform()
         gkVector3&         getPosition()
-        gkQuaternion&      getOrientation()
+        gkmath.Quaternion& getOrientation()
         gkVector3&         getScale()
         gkEuler          getRotation()
 
         gkMatrix4&         getWorldTransform()
         gkVector3&         getWorldPosition()
         gkVector3&         getWorldScale()
-        gkQuaternion&      getWorldOrientation()
+        gkmath.Quaternion& getWorldOrientation()
         gkEuler            getWorldRotation()
 
 
         void setPosition(gkVector3& v)
         void setScale(gkVector3& v)
 
-        void setOrientation(gkQuaternion& q)
+        void setOrientation(gkmath.Quaternion& q)
         void setOrientation(gkEuler& v)
 
         void rotate(gkEuler& drot, int tspace)
-        void rotate(gkQuaternion& q, int tspace)
+        void rotate(gkmath.Quaternion& q, int tspace)
         void translate(gkVector3& dloc, int tspace)
         void scale(gkVector3& dscale)
 
         #void _resetContactInfo()
         #bool _markDbvt(bool v)
         
-        #btCollisionShape* _createShape()
+        #btCollisionShape* _createShape()

File gameobject.pxi

 
 from variable cimport *
 from gameobject cimport *
+from mathutils cimport *
+cimport gkmath
 
 OBJECT_TYPES = 'NULL', 'CAMERA', 'LIGHT', 'ENTITY', 'OBJECT', 'SKELETON', 'PARTICLES'
 
         def __get__(self):
             cdef gkEuler r = (<gkGameObject*>self._p).getWorldRotation()
             return Vector(r.x.valueRadians(), r.y.valueRadians(), r.z.valueRadians())
+
+    property orientation:
+        
+        def __get__(self):
+            cdef Quaternion q = Quaternion()
+            (q.q).assign((<gkGameObject*>self._p).getOrientation())
+            return q
+            
+        def __set__(self, Quaternion q):
+            (<gkGameObject*>self._p).setOrientation(<gkmath.Quaternion>(q.q)[0])
             
     property scale:
         
             v.z = pos[2]
             (<gkGameObject*>self._p).setScale(v)
 
-
+    property linearVelocity:
+        
+        def __get__(self):
+            cdef gkVector3 v = (<gkGameObject*>self._p).getLinearVelocity()
+            return Vector(v.x, v.y, v.z)
+            
+        def __set__(self,pos):
+            cdef gkVector3 v = gkVector3()
+            v.x = pos[0]
+            v.y = pos[1]
+            v.z = pos[2]
+            (<gkGameObject*>self._p).setLinearVelocity(v,TRANSFORM_PARENT)
+            
+    property angularVelocity:
+        
+        def __get__(self):
+            cdef gkVector3 v = (<gkGameObject*>self._p).getAngularVelocity()
+            return Vector(v.x, v.y, v.z)
+            
+        def __set__(self,pos):
+            cdef gkVector3 v = gkVector3()
+            v.x = pos[0]
+            v.y = pos[1]
+            v.z = pos[2]
+            (<gkGameObject*>self._p).setAngularVelocity(v,TRANSFORM_PARENT)
+            
     def translate(self, pos):
         cdef gkVector3 v = gkVector3()
         v.x = pos[0]
         Vector3 *normalised()
         Real length()
         Real getitem "operator[]"(size_t)
-        Vector3 operator+(Vector3)
-        Vector3 operator-(Vector3)
-        Vector3 operator*(Real)
-        Vector3 operator*(Vector3)
-        Vector3 operator/(Real)
-        Vector3 operator/(Vector3)
+        Vector3& assign "operator="(Vector3)
+        Vector3 neg "operator-"()
+        Vector3& iadd "operator+="(Vector3)
+        Vector3& isub "operator-="(Vector3)
+        Vector3& imul "operator*="(Real)
+        Vector3& imul "operator*="(Vector3)
+        Vector3& idiv "operator/="(Real)
+        Vector3& idiv "operator/="(Vector3)
         Real *ptr()
+        Radian angleBetween(Vector3)
+        Quaternion getRotationTo(Vector3)
+        Quaternion getRotationTo(Vector3, Vector3)
         
     cppclass Vector4:
         Real x
         Real w
     cppclass Quaternion:
         Quaternion()
+        Quaternion(Real*)
         Quaternion(Real,Real,Real,Real)
         Real x
         Real y
         Real normalise()
         Quaternion *normalised()
         Real getitem "operator[]"(size_t)
-        Vector3 operator*(Vector3)
+        Quaternion& assign "operator="(Quaternion)
+        Quaternion neg "operator-"()
+        Quaternion& add "operator+"(Quaternion)
+        Quaternion& sub "operator-"(Quaternion)
+        Quaternion& mul "operator*"(Real)
+        Quaternion& mul "operator*"(Quaternion)
+        Quaternion& div "operator/"(Real)
+        Quaternion& div "operator/"(Quaternion)
+        Vector3 mul "operator*"(Vector3)
         Real *ptr()
         
     cppclass Matrix3:
     
     cppclass Radian:
         Radian(Real)
-        Real mRad
+        Real valueRadians()
         
     cppclass Degree:
         Real mDeg
            
 cdef class Accelerometer:
     cdef Vector v
+    cdef gkmath.Vector3 *v3
 
     def __init__(self):
         self.v = Vector()
+        #self.v3 = <gkmath.Vector3 *>
         
     property value:
         def __get__(self):
+            if self.v3:
+                self.v3.assign((<Vector>self.v).v[0])
             return self.v
 
 cdef void evaluate_input_callbacks() except *:

File mathutils.pxd~

+
+cimport gkmath
+import gkmath
+
+cdef class Vector:
+    cdef gkmath.Vector3 *v
+        
+cdef class Quaternion:
+    cdef gkmath.Quaternion *q
+        

File mathutils.pyx

     def __init__(Vector self, ini=None, ini2=None, ini3=None):
         if ini3!=None:
             self.v = new gkmath.Vector3(ini,ini2,ini3)
-        elif ini.__class__==Vector:
+        elif isinstance(ini, Vector):
             self.v = new gkmath.Vector3()
+            self.v.assign((<Vector>ini).v[0])
             memcpy((<gkmath.Vector3*>self.v).ptr(),(<Vector>ini).v.ptr(),sizeof(Real)*3)
         elif ini!=None:
             self.v = new gkmath.Vector3(ini[0],ini[1],ini[2])
         else:
             self.v = new gkmath.Vector3()
+
+    def __dealloc__(self):
+        del self.v
             
     property x:
         def __get__(Vector self): return self.v.x
         
     def normalize(Vector self):
         return self.v.normalise()
+
+    def normalized(Vector self):
+        cdef Vector v = Vector(self)
+        v.v.normalise()
+        return v
         
     def copy(Vector self):
         return Vector(self)
 
+    def __len__(self): return 3
+
     def __getitem__(Vector self, i):
         return self.v.getitem(i)
         
     def __add__(Vector self, v):
-        #if v.__class__==Vector: return self.v+<Vector>v.v
-        return Vector((self.v.x+v[0], self.v.y+v[1], self.v.z+v[2]))
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).iadd((<Vector>v).v[0])
+        else:
+            (ret.v).iadd(gkmath.Vector3(v[0],v[1],v[2]))
+        return ret
 
     def __sub__(Vector self, v):
-        #if v.__class__==Vector: return self.v-<Vector>v.v
-        return Vector((self.v.x-v[0], self.v.y-v[1], self.v.z-v[2]))
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).isub((<Vector>v).v[0])
+        else:
+            (ret.v).isub(gkmath.Vector3(v[0],v[1],v[2]))
+        return ret
+
+    def __iadd__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).iadd((<Vector>v).v[0])
+        else:
+            (self.v).iadd(gkmath.Vector3(v[0],v[1],v[2]))
+        return self
+
+    def __isub__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (self.v).isub((<Vector>v).v[0])
+        else:
+            (self.v).isub(gkmath.Vector3(v[0],v[1],v[2]))
+        return self
         
+    def __mul__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).imul((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (ret.v).imul(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (ret.v).imul(<Real>v)
+        return ret
+
+    def __div__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).idiv((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (ret.v).idiv(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (ret.v).idiv(<Real>v)
+        return ret
+    __truediv__ = __div__
+
+    def __imul__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).imul((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (self.v).imul(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (self.v).imul(<Real>v)
+        return self
+
+    def __idiv__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).idiv((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (self.v).idiv(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (self.v).idiv(<Real>v)
+        return self
+
+    def __pos__(Vector self): return self
+    
+    def __neg__(Vector self):
+        return self*-1 #optimize this?
+
     def __getitem__(Vector self, i):
-        #if i.__class__==slice:
+        if isinstance(i,slice):
             return [self.v.x,self.v.y,self.v.z][i]
-        #else:
-            #if(i>=3):
-                #return
-            #return self.v.getitem(i)
+        elif i<3:
+            return self.v.ptr()[i%3]
+        else:
+            raise IndexError
+
+    def __setitem__(Vector self, i, v):
+        if not isinstance(i,slice) and i<3:
+            self.v.ptr()[i%3]=v
+        else:
+            raise IndexError
         
     def __repr__(Vector self):
         return "Vector(%f, %f, %f)"%(self.v.x,self.v.y,self.v.z)
         
+    def angleBetween(Vector self, other):
+        return self.v.angleBetween(Vector(other).v[0]).valueRadians()
+        
+    def getRotationTo(Vector self, other, fallbackAxis=None):
+        cdef Quaternion q = Quaternion()
+        if fallbackAxis!=None:
+            q.q.assign(self.v.getRotationTo(Vector(other).v[0], Vector(fallbackAxis).v[0]))
+        else:
+            q.q.assign(self.v.getRotationTo(Vector(other).v[0]))
+        return q
+        
+    def lerp(Vector self, other, factor):
+        factor = max(0.0,min(factor,1.0))
+        invf = 1.0-factor
+        return Vector(self.x*invf + other[0]*factor,
+                      self.y*invf + other[1]*factor,
+                      self.z*invf + other[2]*factor)
+        
     #cdef assignv(Vector self, gkmath.Vector3 v):
     #    memcpy((<gkmath.Vector3*>self.v).ptr(),v.ptr(),sizeof(Real)*3)
         
 cdef class Quaternion:
     
-    def __init__(Quaternion self, ini=None):
-        if ini.__class__==Quaternion:
+    def __init__(Quaternion self, ini=None, ini2=None, ini3=None, ini4=None):
+        if isinstance(ini, Quaternion):
             self.q = new gkmath.Quaternion()
-            memcpy((<gkmath.Quaternion*>self.q).ptr(),(<Quaternion>ini).q.ptr(),sizeof(Real)*3)
+            self.q.assign((<Quaternion>ini).q[0])
+        elif ini4!=None:
+            self.q = new gkmath.Quaternion(ini,ini2,ini3,ini4)
         elif ini!=None:
             self.q = new gkmath.Quaternion(ini[0],ini[1],ini[2],ini[3])
         else:
             self.q = new gkmath.Quaternion()
             
+    property w:
+        def __get__(self): return self.q.w
+        def __set__(self, v): self.q.w=v 
+
     property x:
         def __get__(self): return self.q.x
         def __set__(self, v): self.q.x=v 
         def __get__(self): return self.q.z
         def __set__(self, v): self.q.z=v
         
-    def normalize(self):
+    def normalize(Quaternion self):
         return self.q.normalise()
+
+    def normalized(Quaternion self):
+        cdef Quaternion v = Quaternion(self)
+        v.v.normalise()
+        return v
         
-    def copy(self):
-        return Vector(self)
+    def copy(Quaternion self):
+        return Quaternion(self)
 
-    def __getitem__(self, i):
-        return self.getitem(i)
+    def __len__(self): return 4
+
+    def __pos__(Quaternion self): return self
     
-    def __mul__(Quaternion self, Vector vec):
-        cdef Vector v = Vector.__new__(Vector)
-        #v_v = self.q*(&(vec.v))
-        return v
-        
+    def __neg__(Quaternion self):
+        return self*-1 #optimize this?
+
+    def __getitem__(Quaternion self, i):
+        if isinstance(i,slice):
+            return [self.q.w,self.q.x,self.q.y,self.q.z][i]
+        elif i<4:
+            return self.q.ptr()[i%4]
+        else:
+            raise IndexError
+
+    def __setitem__(Quaternion self, i, v):
+        if not isinstance(i,slice) and i<4:
+            self.q.ptr()[i%4]=v
+        else:
+            raise IndexError
+        
+    def __repr__(Quaternion self):
+        return "Quaternion(%f, %f, %f, %f)"%(self.q.w,self.q.x,self.q.y,self.q.z)
+ 
+    def __mul__(Quaternion self, v):
+        cdef Quaternion retq
+        cdef Vector retv
+        if isinstance(v, Quaternion):
+            retq = Quaternion()
+            (retq.q).assign((retq.q).mul((<Quaternion>v).q[0]))
+            return retq
+        if isinstance(v, Vector):
+            retv = Vector()
+            (retv.v).assign((<Quaternion>self).q.mul((<Vector>v).v[0]))
+            return retv
+        retq = Quaternion()
+        (retq.q).assign((retq.q).mul(<Real>v))
+        return retq
+        
+    def inverted(Quaternion self):
+        cdef Quaternion q = self.copy()
+        q.invert()
+        return q
+        
+    def invert(Quaternion self):
+        self.q.x=-(self.q.x)
+        self.q.y=-(self.q.y)
+        self.q.z=-(self.q.z)

File mathutils.pyx~

+
+from prerequisites cimport *
+cimport gkmath
+
+cdef class Vector:
+    
+    def __init__(Vector self, ini=None, ini2=None, ini3=None):
+        if ini3!=None:
+            self.v = new gkmath.Vector3(ini,ini2,ini3)
+        elif isinstance(ini, Vector):
+            self.v = new gkmath.Vector3()
+            self.v.assign((<Vector>ini).v[0])
+            memcpy((<gkmath.Vector3*>self.v).ptr(),(<Vector>ini).v.ptr(),sizeof(Real)*3)
+        elif ini!=None:
+            self.v = new gkmath.Vector3(ini[0],ini[1],ini[2])
+        else:
+            self.v = new gkmath.Vector3()
+
+    def __dealloc__(self):
+        del self.v
+            
+    property x:
+        def __get__(Vector self): return self.v.x
+        def __set__(Vector self, v): self.v.x=v 
+
+    property y:
+        def __get__(Vector self): return self.v.y
+        def __set__(Vector self, v): self.v.y=v 
+
+    property z:
+        def __get__(Vector self): return self.v.z
+        def __set__(Vector self, v): self.v.z=v
+        
+    property length:
+        def __get__(Vector self): return self.v.length()
+        
+    def normalize(Vector self):
+        return self.v.normalise()
+
+    def normalized(Vector self):
+        cdef Vector v = Vector(self)
+        v.v.normalise()
+        return v
+        
+    def copy(Vector self):
+        return Vector(self)
+
+    def __len__(self): return 3
+
+    def __getitem__(Vector self, i):
+        return self.v.getitem(i)
+        
+    def __add__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).iadd((<Vector>v).v[0])
+        else:
+            (ret.v).iadd(gkmath.Vector3(v[0],v[1],v[2]))
+        return ret
+
+    def __sub__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).isub((<Vector>v).v[0])
+        else:
+            (ret.v).isub(gkmath.Vector3(v[0],v[1],v[2]))
+        return ret
+
+    def __iadd__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).iadd((<Vector>v).v[0])
+        else:
+            (self.v).iadd(gkmath.Vector3(v[0],v[1],v[2]))
+        return self
+
+    def __isub__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (self.v).isub((<Vector>v).v[0])
+        else:
+            (self.v).isub(gkmath.Vector3(v[0],v[1],v[2]))
+        return self
+        
+    def __mul__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).imul((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (ret.v).imul(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (ret.v).imul(<Real>v)
+        return ret
+
+    def __div__(Vector self, v):
+        cdef Vector ret = Vector(self)
+        if isinstance(v, Vector):
+            (ret.v).idiv((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (ret.v).idiv(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (ret.v).idiv(<Real>v)
+        return ret
+    __truediv__ = __div__
+
+    def __imul__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).imul((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (self.v).imul(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (self.v).imul(<Real>v)
+        return self
+
+    def __idiv__(Vector self, v):
+        if isinstance(v, Vector):
+            (self.v).idiv((<Vector>v).v[0])
+        elif getattr(v, '__getitem__', False):
+            (self.v).idiv(gkmath.Vector3(v[0],v[1],v[2]))
+        else:
+            (self.v).idiv(<Real>v)
+        return self
+
+    def __pos__(Vector self): return self
+    
+    def __neg__(Vector self):
+        return self*-1 #optimize this?
+
+    def __getitem__(Vector self, i):
+        if isinstance(i,slice):
+            return [self.v.x,self.v.y,self.v.z][i]
+        elif i<3:
+            return self.v.ptr()[i%3]
+        else:
+            raise IndexError
+
+    def __setitem__(Vector self, i, v):
+        if not isinstance(i,slice) and i<3:
+            self.v.ptr()[i%3]=v
+        else:
+            raise IndexError
+        
+    def __repr__(Vector self):
+        return "Vector(%f, %f, %f)"%(self.v.x,self.v.y,self.v.z)
+        
+    def angleBetween(Vector self, other):
+        return self.v.angleBetween(Vector(other).v[0]).valueRadians()
+        
+    def getRotationTo(Vector self, other, fallbackAxis=None):
+        cdef Quaternion q = Quaternion()
+        if fallbackAxis!=None:
+            q.q.assign(self.v.getRotationTo(Vector(other).v[0], Vector(fallbackAxis).v[0]))
+        else:
+            q.q.assign(self.v.getRotationTo(Vector(other).v[0]))
+        return q
+        
+    def lerp(Vector self, other, factor):
+        factor = max(0.0,min(factor,1.0))
+        invf = 1.0-factor
+        return Vector(self.x*invf + other[0]*asfasdf,
+                      self.y*invf + other[1]*asfasdf,
+                      self.z*invf + other[2]*asfasdf)
+        
+    #cdef assignv(Vector self, gkmath.Vector3 v):
+    #    memcpy((<gkmath.Vector3*>self.v).ptr(),v.ptr(),sizeof(Real)*3)
+        
+cdef class Quaternion:
+    
+    def __init__(Quaternion self, ini=None, ini2=None, ini3=None, ini4=None):
+        if isinstance(ini, Quaternion):
+            self.q = new gkmath.Quaternion()
+            self.q.assign((<Quaternion>ini).q[0])
+        elif ini4!=None:
+            self.q = new gkmath.Quaternion(ini,ini2,ini3,ini4)
+        elif ini!=None:
+            self.q = new gkmath.Quaternion(ini[0],ini[1],ini[2],ini[3])
+        else:
+            self.q = new gkmath.Quaternion()
+            
+    property w:
+        def __get__(self): return self.q.w
+        def __set__(self, v): self.q.w=v 
+
+    property x:
+        def __get__(self): return self.q.x
+        def __set__(self, v): self.q.x=v 
+
+    property y:
+        def __get__(self): return self.q.y
+        def __set__(self, v): self.q.y=v 
+
+    property z:
+        def __get__(self): return self.q.z
+        def __set__(self, v): self.q.z=v
+        
+    def normalize(Quaternion self):
+        return self.q.normalise()
+
+    def normalized(Quaternion self):
+        cdef Quaternion v = Quaternion(self)
+        v.v.normalise()
+        return v
+        
+    def copy(Quaternion self):
+        return Quaternion(self)
+
+    def __len__(self): return 4
+
+    def __pos__(Quaternion self): return self
+    
+    def __neg__(Quaternion self):
+        return self*-1 #optimize this?
+
+    def __getitem__(Quaternion self, i):
+        if isinstance(i,slice):
+            return [self.q.w,self.q.x,self.q.y,self.q.z][i]
+        elif i<4:
+            return self.q.ptr()[i%4]
+        else:
+            raise IndexError
+
+    def __setitem__(Quaternion self, i, v):
+        if not isinstance(i,slice) and i<4:
+            self.q.ptr()[i%4]=v
+        else:
+            raise IndexError
+        
+    def __repr__(Quaternion self):
+        return "Quaternion(%f, %f, %f, %f)"%(self.q.w,self.q.x,self.q.y,self.q.z)
+ 
+    def __mul__(Quaternion self, v):
+        cdef Quaternion retq
+        cdef Vector retv
+        if isinstance(v, Quaternion):
+            retq = Quaternion()
+            (retq.q).assign((retq.q).mul((<Quaternion>v).q[0]))
+            return retq
+        if isinstance(v, Vector):
+            retv = Vector()
+            (retv.v).assign((<Quaternion>self).q.mul((<Vector>v).v[0]))
+            return retv
+        retq = Quaternion()
+        (retq.q).assign((retq.q).mul(<Real>v))
+        return retq
+        
+    def inverted(Quaternion self):
+        cdef Quaternion q = self.copy()
+        q.invert()
+        return q
+        
+    def invert(Quaternion self):
+        self.q.x=-(self.q.x)
+        self.q.y=-(self.q.y)
+        self.q.z=-(self.q.z)

File prerequisites.pxd

     TRANSFORM_LOCAL,
     TRANSFORM_PARENT,
     TRANSFORM_WORLD
-
+    
+cdef extern from "gkCommon.h":
+    enum:
+        GK_PLATFORM_WIN32
+        GK_PLATFORM_APPLE
+        GK_PLATFORM_APPLE_IOS
+        GK_PLATFORM_LINUX
+        GK_PLATFORM_ANDROID
+        GK_PLATFORM
+        
 cdef extern from "string": 
     cppclass std_string "std::string": 
         std_string()
         Real y
         Real z
         Real w
+        Real *ptr()
         
     cppclass gkMatrix3:
         gkVector3 mCol0
 
 from gameobject cimport *
+cimport gkmath
 
 cdef extern from "OgreSceneManager.h":
     cdef cppclass Ogre_SceneManager "Ogre::SceneManager":
         void setShadowTextureSize(int)
         void setShadowFarDistance(Real)
 
+cdef enum UPDATE_FLAGS:
+    UF_NONE                 = 0
+    UF_PHYSICS              = 1 << 0
+    UF_LOGIC_BRICKS = 1 << 1
+    UF_NODE_TREES   = 1 << 2
+    UF_ANIMATIONS   = 1 << 3
+    UF_SOUNDS               = 1 << 4
+    UF_DBVT                 = 1 << 5
+    UF_DEBUG                = 1 << 6
+    UF_ALL                  = 0xFFFFFFFF
+                
 cdef extern from "gkScene.h":
     
     cdef cppclass gkScene:
         void beginFrame()
         void setHorizonColor(gkColor&)
         void setAmbientColor(gkColor&)
-        void setGravity(gkVector3&)
+        void setGravity(gkmath.Vector3)
         
         void createInstance()
         
         gkGameObjectHashMap getObjects()
         
         Ogre_SceneManager* getManager()
+        
+        #gkDynamicsWorld* getDynamicsWorld()
+
+        int getUpdateFlags()
+        void setUpdateFlags(int)
+        
+#cdef extern from "gkDynamicsWorld.h":
+    #cppclass gkDynamicsWorld:
+        #btDynamicsWorld* getBulletWorld()
+        
+    #cppclass btDynamicsWorld:
+        #pass
 
 cdef class Scene(pywrap):
     
-    def setGravity(self,x,y,z):
-        cdef gkVector3 a
-        a.x=x
-        a.y=y
-        a.z=z
-        (<gkScene *>self._p).setGravity(a)
+    def setGravity(self,g):
+        (<gkScene *>self._p).setGravity(Vector(g).v[0])
     
     def getMainCamera(self):
         
     def objects(self):
         return GameObjectList().P(self._p)
         
+    def suspendDynamics(Scene self):
+        (<gkScene *>self._p).setUpdateFlags((<gkScene *>self._p).getUpdateFlags()&~UF_PHYSICS)
+        
+    def resumeDynamics(Scene self):
+        (<gkScene *>self._p).setUpdateFlags((<gkScene *>self._p).getUpdateFlags()|UF_PHYSICS)
+        
     def setShadowTextureSelfShadow(self,b):
         (<gkScene *>self._p).getManager().setShadowTextureSelfShadow(b)