1. Alberto Torres
  2. pygamekit

Source

pygamekit / 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 "OgreTerrain.h":
    
    #cdef cppclass Ogre_Terrain "Ogre::Terrain":
        #Ogre_Terrain(Ogre_SceneManager *sm)
        #void addLayer (gkScalar worldSize, Ogre_StringVector*)
        #void dirty()
        #void update()
        #void updateGeometry()
    #cppclass Terrain_ImportData:
        #pass
    #cppclass Terrain_LayerInstanceList:
        #pass
    
    #cdef enum Alignment:
        #ALIGN_X_Z = 0, 
        #ALIGN_X_Y = 1, 
        #ALIGN_Y_Z = 2

    #cdef cppclass Ogre_TerrainGroup "Ogre::TerrainGroup":
        #Ogre_TerrainGroup(Ogre_SceneManager *sm, Alignment, unsigned short terrainSize, gkScalar terrainWorldSize)
        #void defineTerrain (long x, long y)
        #void defineTerrain (long x, long y, float constantHeight)
        #void defineTerrain (long x, long y, Terrain_ImportData *importData)
        ##void defineTerrain (long x, long y, Image *img, Terrain_LayerInstanceList *layers=0)
        #void defineTerrain (long x, long y, float *pFloat, Terrain_LayerInstanceList *layers=0)
        #void defineTerrain (long x, long y, gkString &filename)

cdef class Scene(pywrap):

    cdef public TickSensor tickSensor
    #cdef Ogre_Terrain *terrain
    
    def __init__(self):
        self.tickSensor = TickSensor()
        
    property name:
        '''
        The name of the scene. It's guaranteed to be unique.
        '''
        def __get__(self):
            return (<gkScene*>self._p).getName().c_str()
        
    property gravity:
        def __get__(self):
            return Vector().assign((<gkScene *>self._p).getGravity())
        def __set__(self,g):
            (<gkScene *>self._p).setGravity(Vector(g).v[0])
    
    property main_camera:
        def __get__(self):
            return wrap(Camera, (<gkScene *>self._p).getMainCamera())
        
        def __set__(self, Camera cam):
            (<gkScene *>self._p).setMainCamera(<gkCamera *>cam._p)
        
    def add_object(self, GameObject ob):
        cdef gkGameObject* gkob = <gkGameObject *>ob._p
        (<gkScene *>self._p).addObject(gkob)
        gkob.reinstance()
        
    def remove_object(self, GameObject ob):
        cdef gkGameObject* gkob = <gkGameObject *>ob._p
        (<gkScene *>self._p).removeObject(gkob)
        gkob.destroyInstance()
        
    def destroy_object(self, GameObject ob):
        (<gkScene *>self._p).destroyObject(<gkGameObject *>ob._p)
        
    def clone_object(self, GameObject ob, lifeSpan=0, instantiate=False):
        cdef gkGameObject* o = <gkGameObject *>ob._p
        o = (<gkScene *>self._p).cloneObject(o, lifeSpan, instantiate)
        return wrap(GameObject, o)

    @property
    def objects(self):
        return wrap(GameObjectList, self._p)
        
    def suspend_dynamics(Scene self):
        (<gkScene *>self._p).setUpdateFlags((<gkScene *>self._p).getUpdateFlags()&~UF_PHYSICS)
        
    def resume_dynamics(Scene self):
        (<gkScene *>self._p).setUpdateFlags((<gkScene *>self._p).getUpdateFlags()|UF_PHYSICS)
    
    property shadow:
        def __get__(self):
            return _ShadowProperties()
        
    
    #def __init__(self, sceneName = "", cameraName = "", group = ""):
        
        #self.scn = create(gkString(sceneName), gkString(cameraName), gkString(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()
        
cdef class _ShadowProperties(pywrap):
    @property
    def texture_self_shadow(self,b):
        (<gkScene *>self._p).getManager().setShadowTextureSelfShadow(b)
        
    @property
    def cast_backfaces(self,b):
        (<gkScene *>self._p).getManager().setShadowCasterRenderBackFaces(b)
    
    @property
    def texture_size(self,size):
        (<gkScene *>self._p).getManager().setShadowTextureSize(size)
    
    @property
    def far_distance(self,d):
        (<gkScene *>self._p).getManager().setShadowFarDistance(d)