Commits

Alberto Torres committed 1dee1c5

Removing ~ files.

  • Participants
  • Parent commits 422659e

Comments (0)

Files changed (4)

mathutils.pxd~

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

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]*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, 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)
-        
-    def lerp(self, Quaternion other, factor):
-        cdef Quaternion q = Quaternion()
-        q.q.assign(gkmath.Quaternion_nlerp(factor, (<Quaternion>self).q[0], other.q[0], False))
-        
-    def slerp(self, Quaternion other, factor):
-        cdef Quaternion q = Quaternion()
-        q.q.assign(gkmath.Quaternion_Slerp(factor, (<Quaternion>self).q[0], other.q[0], False))
-        

scene.pxd~

-
-from gameobject cimport *
-cimport gkmath
-
-cdef extern from "OgreSceneManager.h":
-    cdef cppclass Ogre_SceneManager "Ogre::SceneManager":
-        void setShadowTextureSelfShadow(bool)
-        void setShadowCasterRenderBackFaces(bool)
-        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:
-        
-        gkCamera*     getMainCamera()
-        bool          hasDefaultCamera()
-        bool          hasCameras()
-        #gkCameraSet&  getCameras(void)
-        void setMainCamera(gkCamera*)
-        
-        void update(Real tickRate)
-        void beginFrame()
-        void setHorizonColor(gkColor&)
-        void setAmbientColor(gkColor&)
-        void setGravity(gkmath.Vector3)
-        
-        void createInstance()
-        
-        void addObject(gkGameObject* obj)
-        void removeObject(gkGameObject* obj)
-        void destroyObject(gkGameObject* obj)
-        
-        gkGameObject* cloneObject(gkGameObject* obj, int lifeSpan, bool instantiate)
-        
-        gkGameObject* getObject(const_std_string& name)
-        gkGameObjectHashMap getObjects()
-        
-        Ogre_SceneManager* getManager()
-        
-        gkDynamicsWorld* getDynamicsWorld()
-
-        int getUpdateFlags()
-        void setUpdateFlags(int)
-        
-#cdef extern from "gkDynamicsWorld.h":
-    #cppclass gkDynamicsWorld:
-        #btDynamicsWorld* getBulletWorld()
-        
-    #cppclass btDynamicsWorld:
-        #pass

scene.pxi~

-
-from scene cimport *
-from gameobject cimport *
-    
-cdef enum:
-        OBJ_CAMERA  = 1 << 0
-        OBJ_LIGHT   = 1 << 1
-        OBJ_ENTITY  = 1 << 2
-        OBJ_OBJECT  = 1 << 3
-        OBJ_SKELETON = 1 << 4
-
-cdef extern from "gkSceneManager.h":
-    
-    cdef gkScene* createEmptyScene "gkSceneManager::getSingleton().createEmptyScene"(
-                                    const_std_string& sceneName, const_std_string& cameraName = "", const_std_string& group="")
-    cdef gkScene* copyObjects "gkSceneManager::getSingleton().copyObjects"(gkScene* fromScene, gkScene* toScene, int exceptObjectTypes)
-    
-    
-
-cdef class Scene(pywrap):
-
-    cdef public TickSensor tickSensor = None
-    
-    def __init__(self):
-        self.tickSensor = TickSensor()
-    
-    def setGravity(self,g):
-        (<gkScene *>self._p).setGravity(Vector(g).v[0])
-    
-    def getMainCamera(self):
-        
-        return Camera().P((<gkScene *>self._p).getMainCamera())
-    
-    #TODO: make sure you pass one of the correct types
-    
-    def setMainCamera(self, GameObject cam):
-        (<gkScene *>self._p).setMainCamera(<gkCamera *>cam._p)
-        
-    def addObject(self, GameObject ob):
-        (<gkScene *>self._p).addObject(<gkGameObject *>ob._p)
-        
-    def removeObject(self, GameObject ob):
-        (<gkScene *>self._p).removeObject(<gkGameObject *>ob._p)
-        
-    def destroyObject(self, GameObject ob):
-        (<gkScene *>self._p).destroyObject(<gkGameObject *>ob._p)
-        
-    def cloneObject(self, GameObject ob, lifeSpan=0, instantiate=False):
-        cdef gkGameObject* o = <gkGameObject *>ob._p
-        o = (<gkScene *>self._p).cloneObject(o, lifeSpan, instantiate)
-        return GameObject().P(o)
-
-    @property
-    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)
-        
-    def setShadowCasterRenderBackFaces(self,b):
-        (<gkScene *>self._p).getManager().setShadowCasterRenderBackFaces(b)
-        
-    def setShadowTextureSize(self,size):
-        (<gkScene *>self._p).getManager().setShadowTextureSize(size)
-        
-    def setShadowFarDistance(self,d):
-        (<gkScene *>self._p).getManager().setShadowFarDistance(d)
-        
-    
-    #def __init__(self, sceneName = "", cameraName = "", group = ""):
-        
-        #self.scn = create(to_stdstring(sceneName), to_stdstring(cameraName), to_stdstring(group))
-        #self.scn.setHorizonColor(gkColor(0.2,0.2,0.2))
-        #self.scn.setAmbientColor(gkColor(0.5,0.5,0.5))
-        
-    #cdef __init__(self, gkScene* scn):
-        #self.scn = scn
-        #self.objects = GameObjectList()
-        #self.objects.scn = scn
-        #self.objects.hashmap = scn.getObjects()
-