Commits

Alberto Torres  committed 34088ad

Ray sensor and a bit of code refactoring.

  • Participants
  • Parent commits ad9207d

Comments (0)

Files changed (15)

File CMakeLists.txt

 
 set(PYGAMEKIT_SRC
     actuator.pxi
+    animation.pxd
     animation.pxi
     blendfile.pxi
+    collision.pxd
     collision.pxi
     controller.pxi
     engine.pxi
     pywrap.pxd
     pywrap.pxi
     scene.pxi
-    transformstate.pxd
     variable.pxd
     standalone.py
 )

File animation.pxd

+
+from prerequisites cimport *
+from gameobject cimport gkGameObject
+
+cdef extern from "Animation/gkAnimation.h":
+    cdef cppclass gkAnimation:
+        pass
+    cdef cppclass gkAnimationPlayer:
+        Real         getTimePosition()
+        Real         getWeight()
+        int          getMode()
+        Real         getSpeedFactor()
+        Real         getLength()
+
+        void         setMode(int v)
+        void         setAnimation(gkAnimation* v)
+        void         setSpeedFactor(Real v)
+
+        void         enable(bool v)
+        bool         isEnabled()
+        bool         isDone()
+
+        void setBlendFrames(Real v)
+        void setTimePosition(Real v)
+        void setWeight(Real w)
+
+        void evaluate(Real tick)
+        void reset()
+        
+        gkGameObject* getObject()
+        
+        

File collision.pxd

+
+cimport gkmath
+from prerequisites cimport *
+from gameobject cimport *
+
+cdef extern from "Physics/gkRayTest.h":
+    
+    cdef cppclass gkRay:
+        gkRay(gkmath.Vector3, gkmath.Vector3)
+        
+    cdef cppclass gkRayTest:
+        bool collides(gkRay&)
+        gkmath.Vector3& getHitPoint()
+        gkmath.Vector3& getHitNormal()
+        btCollisionObject* getCollisionObject()
+        gkGameObject* getObject()
+        Real getHitFraction()
+
+cdef extern from "btBulletDynamicsCommon.h":
+    
+    cdef cppclass btManifoldPoint
+    cdef cppclass btDynamicsWorld
+    cdef cppclass btCollisionObject
+    cdef cppclass btCollisionShape
+    
+cdef extern from "Physics/gkPhysicsController.h":
+    
+    
+    cdef struct gkContactInfo:
+        gkPhysicsController* collider
+        btManifoldPoint      point
+
+        #typedef utArray[gkContactInfo] Array
+        #typedef utArrayIterator[Array] Iterator
+
+    cdef cppclass gkPhysicsController:
+        
+        gkPhysicsController(gkGameObject* object, btDynamicsWorld* owner)
+        #virtual void setTransformState(const gkTransformState& state)
+        #virtual void updateTransform()
+
+        bool isStaticObject()
+
+        void suspend(bool v)
+        bool isSuspended()
+
+        #gkPhysicsProperties& getProperties()
+
+        void enableContactProcessing(bool v)
+
+        #gkContactInfo::Array&    getContacts()
+        #gkContactInfo::Iterator  getContactIterator()
+        
+        bool collidesWith(gkGameObject* ob, gkContactInfo* cpy) #cpy = 0
+        bool collidesWith(const_std_string& name, gkContactInfo* cpy, bool emptyFilter)#emptyFilter = true
+
+        # Sensor tests,
+        # If prop is empty and material is empty, return any old collision.
+        # If onlyActor is true, filter collision on actor settings (gkGameObjectProperties).
+        # If testAllMaterials is true, test all assigned opposed to only testing the first assigned.
+        bool sensorCollides(const_std_string& prop, const_std_string& material, bool onlyActor, bool testAllMaterials)
+        bool sensorCollides(const_std_string& prop, const_std_string& material, bool onlyActor, bool testAllMaterials, gkGameObjectArray*)
+        #sensorTest is below as a stand-alone function
+
+        # cast functions also below
+        
+        btCollisionObject* getCollisionObject()
+
+        btCollisionShape* getShape()
+
+        btDynamicsWorld* getOwner()
+
+        gkGameObject* getObject()
+
+
+        #gkBoundingBox getAabb()
+
+        #void setShape(btCollisionShape* shape)
+
+        #virtual void create()
+        #virtual void destroy()
+
+        #void _handleManifold(btPersistentManifold* manifold)
+        #void _resetContactInfo()
+        #bool _markDbvt(bool v)
+        
+        #btCollisionShape* _createShape()
+        
+    gkPhysicsController* gkPhysicsController_castController "gkPhysicsController::castController"(btCollisionObject* colObj)
+    gkPhysicsController* gkPhysicsController_castController "gkPhysicsController::castController"(void* colObj)
+    gkGameObject* gkPhysicsController_castObject "gkPhysicsController::castObject"(btCollisionObject* colObj)
+
+    bool gkPhysicsController_sensorTest "gkPhysicsController::sensorTest"(gkGameObject* ob, const_std_string& prop, const_std_string& material, 
+                        bool onlyActor, bool testAllMaterials)

File collision.pxi

 
 
 from gameobject cimport *
+from collision cimport *
+cimport gkmath
 
 cdef list collision_callbacks = []
 
     cdef std_string *prop
     cdef gkGameObjectArray *objlist
     
-    def __init__(self, _prop):
-        self.prop = new std_string(_prop) #is this freed?
+    def __init__(self, prop):
+        del self.prop
+        self.prop = new std_string(prop)
         self.init_sensor([])
         
+    def __dealloc__(self):
+        del self.prop
+        del self.objlist
+        
     cdef void _set_owner(self, GameObject owner):
         self.owner = owner
         self.pc = (<gkGameObject*>self.owner._p).getPhysicsController()
         self.callback_list = collision_callbacks
         
     def __nonzero__(self):
+        return self._test()
+        
+    cdef bool _test(self):
         if self.pc!=NULL:
             return self.pc.sensorCollides(self.prop[0], to_stdstring(""), False, False, self.objlist)
             
             return GameObjectArray().P(self.objlist)
             
     def __str__(self):
-        if self: return "<Collision Active>"
+        if self._test(): return "<Collision Active>"
+        else: return "<Collision>"
+        
+    def __repr__(self):
+        if self._test(): return "<Collision Active>"
         else: return "<Collision>"
         
 cdef void evaluate_collision_callbacks() except *:
     
     for e in collision_callbacks:
         if e.pc:
-            s = e.pc.sensorCollides(e.prop[0], to_stdstring(""), False, False, <gkGameObjectArray*>e.objlist)
+            s = e._test()
             if e.prevstate!=s:
                 e.execute()
             e.prevstate = s
             
+cdef class Ray(Collision):
+    
+    cdef gkRayTest *test
+    cdef gkmath.Vector3 *ray_to
+    cdef gkGameObject *obj_to
+    cdef public bool only_actors
+    
+    property hit_point:
+        def __get__(self):
+            return Vector().assign(self.test.getHitPoint())
+    
+    property hit_normal:
+        def __get__(self):
+            return Vector().assign(self.test.getHitNormal())
+            
+    property hit_objects:
+        def __get__(self):
+            return to_GameObject(self.test.getObject())
+    
+    property hit_fraction:
+        def __get__(self):
+            return self.test.getHitFraction()
+
+    def __cinit__(self):
+        self.test = new gkRayTest()
         
+    def __dealloc__(self):
+        del self.test
+        del self.ray_to
+        
+    def __init__(self, prop, ray_to = None):
+        del self.prop
+        self.prop = new std_string(prop)
+        self.init_sensor([])
+        if isinstance(ray_to, GameObject):
+            self.obj_to = <gkGameObject*>(<GameObject>ray_to)._p
+        elif ray_to is not None:
+            self.ray_to = new gkmath.Vector3(ray_to[0], ray_to[1], ray_to[2])
+        
+    cdef bool _test(self):
+        cdef gkmath.Vector3 ray_from, ray_to
+        cdef gkGameObject *obj, *hit
+        
+        if self.owner is not None:
+            obj = <gkGameObject*>self.owner._p
+            ray_from = obj.getWorldPosition()
+            
+            if self.obj_to:
+                ray_to = self.obj_to.getWorldPosition()
+                ray_to.isub(ray_from)
+            else:
+                if self.ray_to==NULL:
+                    self.ray_to = new gkmath.Vector3(0,0,obj.getWorldScale().z)
+                ray_to = obj.getOrientation().mul(self.ray_to[0])
+            
+            if self.test.collides(gkRay(ray_from, ray_to)):
+                hit = gkPhysicsController_castObject(self.test.getCollisionObject())
+                if hit and hit != obj:
+                    return gkPhysicsController_sensorTest(hit, self.prop[0], to_stdstring(""), self.only_actors, False)
+                
+        return False
         int                     sceneManager       # TODO scene manager to use
         std_string              log                # Main log file name
         bool                    verbose            # Enable/Disable Ogre print-out
-        gkVector2               winsize            # Window width & height
+        gkmath.Vector2          winsize            # Window width & height
         std_string              wintitle           # Window title
         std_string              extWinhandle       # External Window Handle
         bool                    fullscreen         # Fullscreen mode

File gameobject.pxd

 from prerequisites cimport *
 from variable cimport *
 from scene cimport *
+from collision cimport *
+from animation cimport *
 cimport gkmath
 
 #cdef class GameObject(pywrap):
         void removeChild(gkGameObject* ob)
         bool hasChild(gkGameObject* ob)
     
-        gkTransformState&  getTransformState()
-        gkMatrix4&         getTransform()
-        gkVector3&         getPosition()
-        gkmath.Quaternion& getOrientation()
-        gkVector3&         getScale()
-        gkEuler          getRotation()
+        gkmath.TransformState&  getTransformState()
+        gkmath.Matrix4&         getTransform()
+        gkmath.Vector3&         getPosition()
+        gkmath.Quaternion&      getOrientation()
+        gkmath.Vector3&         getScale()
+        gkmath.Euler            getRotation()
 
-        gkTransformState&  getWorldTransformState()
-        gkMatrix4&         getWorldTransform()
-        gkVector3&         getWorldPosition()
-        gkVector3&         getWorldScale()
-        gkmath.Quaternion& getWorldOrientation()
-        gkEuler            getWorldRotation()
+        gkmath.TransformState&  getWorldTransformState()
+        gkmath.Matrix4&         getWorldTransform()
+        gkmath.Vector3&         getWorldPosition()
+        gkmath.Vector3&         getWorldScale()
+        gkmath.Quaternion&      getWorldOrientation()
+        gkmath.Euler            getWorldRotation()
 
 
-        void applyTransformState(gkTransformState& newstate, Real& weight)
-        void setTransform(gkMatrix4& v)
-        void setTransform(gkTransformState& v)
-        void setPosition(gkVector3& v)
-        void setScale(gkVector3& v)
+        void applyTransformState(gkmath.TransformState& newstate, Real& weight)
+        void setTransform(gkmath.Matrix4& v)
+        void setTransform(gkmath.TransformState& v)
+        void setPosition(gkmath.Vector3& v)
+        void setScale(gkmath.Vector3& v)
 
         void setOrientation(gkmath.Quaternion& q)
-        void setOrientation(gkEuler& v)
+        void setOrientation(gkmath.Euler& v)
 
-        void rotate(gkEuler& drot, int tspace)
+        void rotate(gkmath.Euler& drot, int tspace)
         void rotate(gkmath.Quaternion& q, int tspace)
-        void translate(gkVector3& dloc, int tspace)
-        void scale(gkVector3& dscale)
+        void translate(gkmath.Vector3& dloc, int tspace)
+        void scale(gkmath.Vector3& dscale)
 
-        void yaw(gkRadian& v, int tspace)
-        void pitch(gkRadian& v, int tspace)
-        void roll(gkRadian& v, int tspace)
+        void yaw(gkmath.Radian& v, int tspace)
+        void pitch(gkmath.Radian& v, int tspace)
+        void roll(gkmath.Radian& v, int tspace)
 
         # Rigid body
 
-        void        applyTorque(gkVector3& t, int tspace)
-        void        applyForce(gkVector3& f, int tspace)
-        void        setLinearVelocity(gkVector3& linv, int tspace)
-        void        setAngularVelocity(gkVector3& angv, int tspace)
-        gkVector3   getLinearVelocity()
-        gkVector3   getAngularVelocity()
+        void        applyTorque(gkmath.Vector3& t, int tspace)
+        void        applyForce(gkmath.Vector3& f, int tspace)
+        void        setLinearVelocity(gkmath.Vector3& linv, int tspace)
+        void        setAngularVelocity(gkmath.Vector3& angv, int tspace)
+        gkmath.Vector3   getLinearVelocity()
+        gkmath.Vector3   getAngularVelocity()
         
         # physics
 
         bool isOccluder()
         bool isGhost()
     
-cdef extern from "Animation/gkAnimation.h":
-    cdef cppclass gkAnimation:
-        pass
-    cdef cppclass gkAnimationPlayer:
-        Real         getTimePosition()
-        Real         getWeight()
-        int          getMode()
-        Real         getSpeedFactor()
-        Real         getLength()
-
-        void         setMode(int v)
-        void         setAnimation(gkAnimation* v)
-        void         setSpeedFactor(Real v)
-
-        void         enable(bool v)
-        bool         isEnabled()
-        bool         isDone()
-
-        void setBlendFrames(Real v)
-        void setTimePosition(Real v)
-        void setWeight(Real w)
-
-        void evaluate(Real tick)
-        void reset()
-        
-        gkGameObject* getObject()
-    
 cdef extern from "gkBone.h":
     cdef cppclass gkBone:
-        void applyChannelTransform(gkTransformState& channel, Real weight)
-        void applyPoseTransform(gkTransformState& pose)
-        gkTransformState&        getPose()
+        void applyChannelTransform(gkmath.TransformState& channel, Real weight)
+        void applyPoseTransform(gkmath.TransformState& pose)
+        gkmath.TransformState&        getPose()
     
 cdef extern from "gkSkeleton.h":
     cdef cppclass gkSkeleton:
         gkAnimationsIterator iterator()
         unsigned int size()
         
-cdef extern from "btBulletDynamicsCommon.h":
-    
-    cdef cppclass btManifoldPoint
-    cdef cppclass btDynamicsWorld
-    cdef cppclass btCollisionObject
-    cdef cppclass btCollisionShape
-    
-cdef extern from "Physics/gkPhysicsController.h":
-    
-    
-    cdef struct gkContactInfo:
-        gkPhysicsController* collider
-        btManifoldPoint      point
-
-        #typedef utArray[gkContactInfo] Array
-        #typedef utArrayIterator[Array] Iterator
-
-    cdef cppclass gkPhysicsController:
-        
-        gkPhysicsController(gkGameObject* object, btDynamicsWorld* owner)
-        #virtual void setTransformState(const gkTransformState& state)
-        #virtual void updateTransform()
-
-        bool isStaticObject()
-
-        void suspend(bool v)
-        bool isSuspended()
-
-        #gkPhysicsProperties& getProperties()
-
-        void enableContactProcessing(bool v)
-
-        #gkContactInfo::Array&    getContacts()
-        #gkContactInfo::Iterator  getContactIterator()
-        
-        bool collidesWith(gkGameObject* ob, gkContactInfo* cpy) #cpy = 0
-        bool collidesWith(const_std_string& name, gkContactInfo* cpy, bool emptyFilter)#emptyFilter = true
-
-        # Sensor tests,
-        # If prop is empty and material is empty, return any old collision.
-        # If onlyActor is true, filter collision on actor settings (gkGameObjectProperties).
-        # If testAllMaterials is true, test all assigned opposed to only testing the first assigned.
-        bool sensorCollides(const_std_string& prop, const_std_string& material, bool onlyActor, bool testAllMaterials)
-        bool sensorCollides(const_std_string& prop, const_std_string& material, bool onlyActor, bool testAllMaterials, gkGameObjectArray*)
-        bool sensorTest(gkGameObject* ob, const_std_string& prop, const_std_string& material, 
-                        bool onlyActor, bool testAllMaterials)
-
-        gkPhysicsController* castController(btCollisionObject* colObj)
-        gkPhysicsController* castController(void* colObj)
-        gkGameObject* castObject(btCollisionObject* colObj)
-
-
-        btCollisionObject* getCollisionObject()
-
-        btCollisionShape* getShape()
-
-        btDynamicsWorld* getOwner()
-
-        gkGameObject* getObject()
-
-
-        #gkBoundingBox getAabb()
-
-        #void setShape(btCollisionShape* shape)
-
-        #virtual void create()
-        #virtual void destroy()
-
-        #void _handleManifold(btPersistentManifold* manifold)
-        #void _resetContactInfo()
-        #bool _markDbvt(bool v)
-        
-        #btCollisionShape* _createShape()
-

File gameobject.pxi

-
-#TODO: function for getting the appropiate python object from a gkGameObject pointer, instead of elifs everywhere
 
 from variable cimport *
 from gameobject cimport *
 from mathutils cimport *
 cimport gkmath
 
+
 OBJECT_TYPES = 'NULL', 'CAMERA', 'LIGHT', 'ENTITY', 'OBJECT', 'SKELETON', 'PARTICLES'
 
+cdef to_GameObject(gkGameObject *ob):
+    if ob!=NULL:
+        t = ob.getType()
+        if t == GK_ENTITY:
+            return Entity().P(ob)
+        elif t == GK_SKELETON:
+            return Skeleton().P(ob)
+        else:
+            return GameObject().P(ob)
+    else:
+        return None
 
 cdef gkGameObject* cloneRecursiveImpl(gkGameObject* ob, int lifespan=0, bool instance=True):
     
 
 cdef class GameObject(pywrap):
     
+    #cdef public Vector look_vector
+    #cdef public Vector up_vector
+    
     @property
     def type(self):
         return OBJECT_TYPES[(<gkGameObject*>self._p).getType()]
         
     def clone_recursive(self, lifespan=0):
         cdef gkGameObject *ob = cloneRecursiveImpl(<gkGameObject*>self._p, lifespan)
-        if ob:
-            return GameObject().P(ob)
+        return to_GameObject(ob)
 
     property parent:
 
         def __get__(self):
-            cdef gkGameObject* o = (<gkGameObject*>self._p).getParent()
-            if o!=NULL: return GameObject().P(o)
-            return None
+            cdef gkGameObject* ob = (<gkGameObject*>self._p).getParent()
+            return to_GameObject(ob)
             
         def __set__(self, GameObject ob):
             if ob:
     property position:
         
         def __get__(self):
-            cdef gkVector3 v = (<gkGameObject*>self._p).getPosition()
+            cdef gkmath.Vector3 v = (<gkGameObject*>self._p).getPosition()
             return Vector(v.x, v.y, v.z)
             
         def __set__(self,pos):
-            cdef gkVector3 v = gkVector3()
+            cdef gkmath.Vector3 v = gkmath.Vector3()
             v.x = pos[0]
             v.y = pos[1]
             v.z = pos[2]
     property position_world:
         
         def __get__(self):
-            cdef gkVector3 v = (<gkGameObject*>self._p).getWorldPosition()
+            cdef gkmath.Vector3 v = (<gkGameObject*>self._p).getWorldPosition()
             return Vector(v.x, v.y, v.z)
 
     property rotation:
 
         def __get__(self):
-            cdef gkEuler r = (<gkGameObject*>self._p).getRotation()
+            cdef gkmath.Euler r = (<gkGameObject*>self._p).getRotation()
             return Vector(r.x.valueRadians(), r.y.valueRadians(), r.z.valueRadians())
 
         def __set__(self,rot):
-            cdef gkEuler r = gkEuler()
-            r.x = gkRadian(rot[0])
-            r.y = gkRadian(rot[1])
-            r.z = gkRadian(rot[2])
+            cdef gkmath.Euler r = gkmath.Euler()
+            r.x = gkmath.Radian(rot[0])
+            r.y = gkmath.Radian(rot[1])
+            r.z = gkmath.Radian(rot[2])
             (<gkGameObject*>self._p).setOrientation(r)
             
     property rotation_world:
 
         def __get__(self):
-            cdef gkEuler r = (<gkGameObject*>self._p).getWorldRotation()
+            cdef gkmath.Euler r = (<gkGameObject*>self._p).getWorldRotation()
             return Vector(r.x.valueRadians(), r.y.valueRadians(), r.z.valueRadians())
 
     property orientation:
     property scale:
         
         def __get__(self):
-            cdef gkVector3 v = (<gkGameObject*>self._p).getScale()
+            cdef gkmath.Vector3 v = (<gkGameObject*>self._p).getScale()
             return Vector(v.x, v.y, v.z)
             
         def __set__(self,pos):
-            cdef gkVector3 v = gkVector3()
+            cdef gkmath.Vector3 v = gkmath.Vector3()
             v.x = pos[0]
             v.y = pos[1]
             v.z = pos[2]
     property linear_velocity:
         
         def __get__(self):
-            cdef gkVector3 v = (<gkGameObject*>self._p).getLinearVelocity()
+            cdef gkmath.Vector3 v = (<gkGameObject*>self._p).getLinearVelocity()
             return Vector(v.x, v.y, v.z)
             
         def __set__(self,pos):
-            cdef gkVector3 v = gkVector3()
+            cdef gkmath.Vector3 v = gkmath.Vector3()
             v.x = pos[0]
             v.y = pos[1]
             v.z = pos[2]
     property angular_velocity:
         
         def __get__(self):
-            cdef gkVector3 v = (<gkGameObject*>self._p).getAngularVelocity()
+            cdef gkmath.Vector3 v = (<gkGameObject*>self._p).getAngularVelocity()
             return Vector(v.x, v.y, v.z)
             
         def __set__(self,pos):
-            cdef gkVector3 v = gkVector3()
+            cdef gkmath.Vector3 v = gkmath.Vector3()
             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()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = pos[0]
         v.y = pos[1]
         v.z = pos[2]
         (<gkGameObject*>self._p).translate(v, TRANSFORM_PARENT)
 
     def translate_local(self, pos):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = pos[0]
         v.y = pos[1]
         v.z = pos[2]
         (<gkGameObject*>self._p).translate(v, TRANSFORM_LOCAL)
 
     def translate_world(self, pos):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = pos[0]
         v.y = pos[1]
         v.z = pos[2]
         (<gkGameObject*>self._p).translate(v, TRANSFORM_WORLD)
 
     def rotate(self, drot):
-        cdef gkEuler r = gkEuler()
-        r.x = gkRadian(drot[0])
-        r.y = gkRadian(drot[1])
-        r.z = gkRadian(drot[2])
+        cdef gkmath.Euler r = gkmath.Euler()
+        r.x = gkmath.Radian(drot[0])
+        r.y = gkmath.Radian(drot[1])
+        r.z = gkmath.Radian(drot[2])
         (<gkGameObject*>self._p).rotate(r, TRANSFORM_PARENT)
 
     def rotate_local(self, drot):
-        cdef gkEuler r = gkEuler()
-        r.x = gkRadian(drot[0])
-        r.y = gkRadian(drot[1])
-        r.z = gkRadian(drot[2])
+        cdef gkmath.Euler r = gkmath.Euler()
+        r.x = gkmath.Radian(drot[0])
+        r.y = gkmath.Radian(drot[1])
+        r.z = gkmath.Radian(drot[2])
         (<gkGameObject*>self._p).rotate(r, TRANSFORM_LOCAL)
 
     def rotate_world(self, drot):
-        cdef gkEuler r = gkEuler()
-        r.x = gkRadian(drot[0])
-        r.y = gkRadian(drot[1])
-        r.z = gkRadian(drot[2])
+        cdef gkmath.Euler r = gkmath.Euler()
+        r.x = gkmath.Radian(drot[0])
+        r.y = gkmath.Radian(drot[1])
+        r.z = gkmath.Radian(drot[2])
         (<gkGameObject*>self._p).rotate(r, TRANSFORM_WORLD)
         
     # Rigid body stuff
     
     def apply_torque(self, t):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = t[0]
         v.y = t[1]
         v.z = t[2]
         (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_PARENT)
 
     def apply_torque_local(self, t):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = t[0]
         v.y = t[1]
         v.z = t[2]
         (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_LOCAL)
 
     def apply_torque_world(self, t):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = t[0]
         v.y = t[1]
         v.z = t[2]
         (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_WORLD)
 
     def apply_force(self, f):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = f[0]
         v.y = f[1]
         v.z = f[2]
         (<gkGameObject*>self._p).applyForce(v, TRANSFORM_PARENT)
 
     def apply_force_local(self, f):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = f[0]
         v.y = f[1]
         v.z = f[2]
         (<gkGameObject*>self._p).applyForce(v, TRANSFORM_LOCAL)
 
     def apply_force_world(self, f):
-        cdef gkVector3 v = gkVector3()
+        cdef gkmath.Vector3 v = gkmath.Vector3()
         v.x = f[0]
         v.y = f[1]
         v.z = f[2]
         #cdef gkBone *b2 = (<gkSkeleton*>self._p).getBone(to_stdstring('tder'))
         #cdef gkTransformState t1 = gkTransformState()
         #cdef gkTransformState t2 = gkTransformState()
-        #cdef gkVector3 v1, v2
+        #cdef gkmath.Vector3 v1, v2
         #t1.loc.x = a
         #t1.loc.z = b
         #t2.loc.x = c
         ret = []
         
         while it.hasMoreElements():
-            ret.append(GameObject().P(it.getNext().second))
+            ret.append(to_GameObject(it.getNext().second))
             
         return ret
         
         
     def __getitem__(self,item):
         cdef gkGameObject *ob = (<gkScene*>self._p).getObject(to_stdstring(item))
-        if ob:
-            t = ob.getType()
-            if t == GK_ENTITY:
-                return Entity().P(ob)
-            if t == GK_SKELETON:
-                return Skeleton().P(ob)
-            else:
-                return GameObject().P(ob)
-        else:
-            return None
+        return to_GameObject(ob)
 
     def __len__(self):
         return (<gkScene*>self._p).getObjects().size()
         ret = []
         
         while (it.hasMoreElements()):
-            ret.append(GameObject().P(it.getNext()))
+            ret.append(to_GameObject(it.getNext()))
             
         return ret
         
     cppclass Vector2:
         Real x
         Real y
+        bool isZeroLength()
+        #Real *ptr()
     cppclass Vector3:
         Vector3()
         Vector3(Real,Real,Real)
     
     cppclass Radian:
         Radian(Real)
+        Real mRad
         Real valueRadians()
+        Real valueDegrees()
         
     cppclass Degree:
         Real mDeg
     
     
 cdef extern from "gkMathUtils.h":
-    cppclass gkEuler:
-        gkEuler()
+    cppclass Euler "gkEuler":
+        Euler()
         Radian x
         Radian y
         Radian z
 
+    cppclass TransformState "gkTransformState":
+        TransformState()
+        TransformState(Vector3, Quaternion, Vector3)
+        Vector3           loc
+        Quaternion        rot
+        Vector3           scl
 
 
 from prerequisites cimport *
+cimport gkmath
 
 cdef enum gkInputState:
     GK_NullState = 0
         int key_mod
         
     cdef cppclass gkMouse:
-        gkVector2 getPosition()
-        gkVector2 getRelative()
+        gkmath.Vector2 getPosition()
+        gkmath.Vector2 getRelative()
         bool isButtonDown(int)
         bool mouseMoved()
         clear()
 cdef list mousebutton_callbacks = []
 cdef int previous_keys[256] #TODO: use KC_MAX
 cdef int previous_mb[3]
-cdef gkVector2 prev_mouse
+cdef gkmath.Vector2 prev_mouse
 prev_mouse.x = -1
 
 cdef class Key(Sensor):
         
     @property
     def position(self):
-        cdef gkVector2 v = self.mouse.getPosition()
+        cdef gkmath.Vector2 v = self.mouse.getPosition()
         return v.x, v.y
         
     @property
     def relative(self):
-        cdef gkVector2 v = self.mouse.getRelative()
+        cdef gkmath.Vector2 v = self.mouse.getRelative()
         return v.x, v.y
         
     #def isButtonDown(self, button):
 cdef void evaluate_input_callbacks() except *:
     global prev_mouse
     cdef int k, *keys = getKeyboard().keys
-    cdef gkVector2 pos = getMouse().getPosition(), rel
+    cdef gkmath.Vector2 pos = getMouse().getPosition(), rel
     cdef Sensor e
     cdef int *mousebuttons = getMouse().buttons, b
     

File prerequisites.pxd

+
+
+# C defines that are too small or don't fit anywhere else
 
 from libcpp cimport bool
 
 cdef extern from *:
     ctypedef char* const_char_ptr "const char*"
     ctypedef std_string const_std_string "const std_string"
-     
-cdef extern from "gkMathUtils.h":
-    cppclass gkVector2:
-        Real x
-        Real y
-        bool isZeroLength()
-        Real *ptr()
-    cppclass gkVector3:
-        gkVector3()
-        gkVector3(Real,Real,Real)
-        Real x
-        Real y
-        Real z
-    cppclass gkVector4:
-        Real x
-        Real y
-        Real z
-        Real w
-    cppclass gkQuaternion:
-        Real x
-        Real y
-        Real z
-        Real w
-        Real *ptr()
-        
-    cppclass gkMatrix3:
-        gkVector3 mCol0
-        gkVector3 mCol1
-        gkVector3 mCol2
-        
-    cppclass gkMatrix4:
-        gkVector4 mCol0
-        gkVector4 mCol1
-        gkVector4 mCol2
-        gkVector4 mCol3
-    
-    cppclass gkRadian:
-        gkRadian(Real)
-        Real mRad
-        Real valueRadians()
-        Real valueDegrees()
-        
-    cppclass gkDegree:
-        Real mDeg
 
-    cppclass gkEuler:
-        gkEuler()
-        gkRadian x
-        gkRadian y
-        gkRadian z
-
-cdef extern from "gkTransformState.h":
-    cppclass gkTransformState:
-        gkTransformState()
-        gkTransformState(gkVector3, gkQuaternion, gkVector3)
-        gkVector3           loc
-        gkQuaternion        rot
-        gkVector3           scl
-
-
-
-#    ctypedef Ogre::Math              gkMath;
-#    ctypedef Ogre::Real              gkScalar;
-#    ctypedef Ogre::Degree            gkDegree;
-#    ctypedef Ogre::Radian            gkRadian;
-#    ctypedef Vector2 gkVector2;
-#    ctypedef Ogre::Vector3           gkVector3;
-#    ctypedef Ogre::Vector4           gkVector4;
-#    ctypedef Ogre::Quaternion        gkQuaternion;
-#    ctypedef Ogre::Matrix3           gkMatrix3;
-#    ctypedef Ogre::Matrix4           gkMatrix4;
-#    ctypedef Ogre::ColourValue       gkColor;
-#    ctypedef Ogre::AxisAlignedBox    gkBoundingBox;
-#    ctypedef Ogre::Ray               gkRay;
-
-cdef extern from *:
     cppclass gkColor:
         gkColor(float r, float g, float b, float a)
         gkColor(float r, float g, float b)
         void setShadowCasterRenderBackFaces(bool)
         void setShadowTextureSize(int)
         void setShadowFarDistance(Real)
-
+        
 cdef enum UPDATE_FLAGS:
     UF_NONE                 = 0
     UF_PHYSICS              = 1 << 0
         int getUpdateFlags()
         void setUpdateFlags(int)
         
+        void setOverlaysEnabled "getViewport()->getViewport().setOverlaysEnabled"(bool)
+        
 #cdef extern from "gkDynamicsWorld.h":
     #cppclass gkDynamicsWorld:
         #btDynamicsWorld* getBulletWorld()
             for f in self.links:
                 try:
                     f(self)
+                except SystemExit:
+                    exit()
                 except:
                     exc_type, exc_value, exc_traceback = sys.exc_info()
                     if self.stackdata is not None:

File transformstate.pxd

-
-cdef extern from "gkTransformState.h":
-    cdef cppclass gkTransformState:
-        pass

File variable.pxd

 
 from prerequisites cimport *
+cimport gkmath
 
 cdef enum PropertyTypes:
     VAR_NULL = 0
             gkVariable(int v, const_std_string&)
             gkVariable(Real v, const_std_string&)
             gkVariable(const_std_string&, const_std_string&)
-            gkVariable(gkVector2& v, const_std_string&)
-            gkVariable(gkVector3& v, const_std_string&)
-            gkVariable(gkVector4& v, const_std_string&)
-            gkVariable(gkQuaternion& v, const_std_string&)
-            gkVariable(gkMatrix3& v, const_std_string&)
-            gkVariable(gkMatrix4& v, const_std_string&)
+            gkVariable(gkmath.Vector2& v, const_std_string&)
+            gkVariable(gkmath.Vector3& v, const_std_string&)
+            gkVariable(gkmath.Vector4& v, const_std_string&)
+            gkVariable(gkmath.Quaternion& v, const_std_string&)
+            gkVariable(gkmath.Matrix3& v, const_std_string&)
+            gkVariable(gkmath.Matrix4& v, const_std_string&)
 
             gkVariable* clone()
 
             void setValue(int v)
             void setValue(Real v)
             void setValue(const_std_string&)
-            void setValue(gkVector2& v)
-            void setValue(gkVector3& v)
-            void setValue(gkVector4& v)
-            void setValue(gkQuaternion& v)
-            void setValue(gkMatrix3& v)
-            void setValue(gkMatrix4& v)
+            void setValue(gkmath.Vector2& v)
+            void setValue(gkmath.Vector3& v)
+            void setValue(gkmath.Vector4& v)
+            void setValue(gkmath.Quaternion& v)
+            void setValue(gkmath.Matrix3& v)
+            void setValue(gkmath.Matrix4& v)
             void setValue(gkVariable& v)
 
 
             int          getValueInt()
             Real     getValueReal()
             std_string     getValueString()
-            gkVector2    getValueVector2()
-            gkVector3    getValueVector3()
-            gkVector4    getValueVector4()
-            gkQuaternion getValueQuaternion()
-            gkMatrix3    getValueMatrix3()
-            gkMatrix4    getValueMatrix4()
+            gkmath.Vector2    getValueVector2()
+            gkmath.Vector3    getValueVector3()
+            gkmath.Vector4    getValueVector4()
+            gkmath.Quaternion getValueQuaternion()
+            gkmath.Matrix3    getValueMatrix3()
+            gkmath.Matrix4    getValueMatrix4()
 
             bool operator < (gkVariable& o)
             bool operator > (gkVariable& o)