Пример #1
0
class CFollowCamera(CCamera):
    __classname__ = 'follow_camera'
    __desc__ = 'A third person camera that can follow the target actor arround'
    __actortype__ = 'e'

    orientation = sylphis.CQuaternion()

    def update(self, timeDelta):
        pos = sylphis.CVector3(self.targetNode.getPosition())
        ori = sylphis.CQuaternion(self.targetNode.getOrientation())

        q = sylphis.CQuaternion()
        q.fromAngleAxis(sylphis.CVector3(1, 0, 0), -0.4)
        ori = ori * q

        self.orientation.lerp(1.0 * timeDelta, ori)

        dir = self.orientation * sylphis.CVector3(0, 0, 1)
        dir = dir * 250.0
        end = pos + dir

        tr = sylphis.CTraceResult()
        self.targetBody.setDisabled(True)
        self.mScene.raytrace(tr, pos, end, self.targetBody)
        self.targetBody.setDisabled(False)
        tr.frac -= 0.2
        self.node.setPosition(pos + dir * tr.frac)
        self.node.setOrientation(self.orientation)
Пример #2
0
    def update(self, timeDelta):
        pos = sylphis.CVector3(self.targetNode.getPosition())
        ori = sylphis.CQuaternion(self.targetNode.getOrientation())

        q = sylphis.CQuaternion()
        q.fromAngleAxis(sylphis.CVector3(1, 0, 0), -0.4)
        ori = ori * q

        self.orientation.lerp(1.0 * timeDelta, ori)

        dir = self.orientation * sylphis.CVector3(0, 0, 1)
        dir = dir * 250.0
        end = pos + dir

        tr = sylphis.CTraceResult()
        self.targetBody.setDisabled(True)
        self.mScene.raytrace(tr, pos, end, self.targetBody)
        self.targetBody.setDisabled(False)
        tr.frac -= 0.2
        self.node.setPosition(pos + dir * tr.frac)
        self.node.setOrientation(self.orientation)
Пример #3
0
class CMiscSkelModel(CSimpleActor):
    __classname__ = 'misc_skel_model'
    __desc__ = 'A skeletal model'
    __actortype__ = 'e'
    __specs__ = [
        {'name':'model', 'doc':'The filename that contains the model'},
        {'name':'anim', 'doc':'The animation to run on the model. e.g. ''idle'''},
        {'name':'skin', 'doc':'The skin to apply on the model. (Not implemented yet)'}
    ]
    model = ''
    anim = 'idle'
    skin = ''
    
    def __init__(self, *args):
        CSimpleActor.__init__(self, *args)
      
    def join(self, ent):
        CSimpleActor.join(self, ent)
        pi = 3.14159 # FIXME
        try:
            o = split(ent['angles'])
        except KeyError,x:
            ang = ent.get('angle', '0')
            o = ('0', ang, '0')
        self.angles = sylphis.CVector3(-pi * float(o[0]) / 180, pi * float(o[1]) / 180, pi * float(o[2]) / 180)

        model = CEngine.models.registerSkelModel(self.model)

        bt = manage(sylphis.CBoneControler)
        bt.setTranslation(sylphis.CVector3(0,0,0))
        q = sylphis.CQuaternion()
        q.fromAngleAxis(sylphis.CVector3(1,0,0), 10.0)
        bt.setRotation(q)
        bt.setBoneId(0)
        
        sa = manage(sylphis.CSkelAnimation)
        sa.setDuration(100.0)
        sa.addBoneTrack(bt)

        #print "Controlers :", bt, sa

        sm = self.mScene
        m = sylphis.CSceneModel(sm, model)
        m.setPosition(self.origin)
        m.blendAnimCycle(self.anim, 1.0, 0.1)

        m.executeAction(sa, 'test')
        
        m.yaw(self.angles.y)
        m.roll(self.angles.x)

        self.node = m
Пример #4
0
class CActors:
    def __init__(self, container):
        self.mCont = container
        self.actors = []
        self.updaters = []
        self.namedActors = {}
        self.queuedEvents = []
        self.watchers = []
        registerActorClasses('game/actors')

    def registerWatcher(self, func):
        self.watchers.append(func)

    def signalWatchers(self):
        for func in self.watchers:
            func()

    def printActors(self):
        i = 0
        print " Actors (Id / Name / Class) "
        print "-----------------------------------------"
        for a in self.actors:
            print "%d / %s  / %s" % (i, a.__dict__.get('name',
                                                       'none'), a.__class__)
            i += 1

    def getActors(self):
        return self.actors

    def addActor(self, ent):
        """
        The actor is not started, so a call to
        the start() method might be required.
        """
        cl = actorClasses.get(ent['classname'], CSimpleActor)

        try:
            script = ent['script']
            a = {}
            a['CBaseActor'] = cl
            import loader
            loader.execute(script, a, a)
            #for k in a.keys(): sylphis._object.__setattr__(newcl, k, a[k])
            cl = a['CScript']
        except KeyError:
            pass

        e = cl()
        # load the specifics
        try:
            updateKeepType(e, ent)
        except Exception, ex:
            raise Exception, ent.get('name', 'unnamed') + ' : ' + str(ex)

        e.origin.swapHand()

        e.angles = sylphis.CQuaternion()
        try:
            o = string.split(ent['angles'])
            pi = 3.14159
            angles = sylphis.CVector3(-pi * (float(o[0])) / 180,
                                      -pi * (float(o[1]) + 0.0) / 180,
                                      pi * float(o[2]) / 180)

            m = sylphis.CMatrix4()
            m.rotate(angles)

            o = sylphis.CQuaternion()
            o.fromRotationMatrix(m)
            print "Q", o
            e.angles = o

            #axis = sylphis.CVector3.UNIT_Y
            #e.angles.fromAngleAxis(axis, angles.y)
            #axis = sylphis.CVector3.UNIT_Z
            #q = sylphis.CQuaternion(e.angles)
            #q.invert()
            #q.fromAngleAxis(q * axis, angles.x)
            #e.angles = e.angles * q
        except KeyError, x:
            pass
Пример #5
0
            print "Q", o
            e.angles = o

            #axis = sylphis.CVector3.UNIT_Y
            #e.angles.fromAngleAxis(axis, angles.y)
            #axis = sylphis.CVector3.UNIT_Z
            #q = sylphis.CQuaternion(e.angles)
            #q.invert()
            #q.fromAngleAxis(q * axis, angles.x)
            #e.angles = e.angles * q
        except KeyError, x:
            pass

        try:
            o = string.split(ent['orientation'])
            e.orientation = sylphis.CQuaternion(float(o[0]), float(o[1]),
                                                float(o[2]), float(o[3]))
        except KeyError, x:
            pass

        e.join(ent)
        self.append(e)

        if ent['classname'] == 'info_player_start':
            self.mCont.player = e

        self.signalWatchers()

        return e

    def spawn(self, ent):
        """
Пример #6
0
def setLightDir(a,b = 10,c = 1):
    import entry
    entry.client.actors.getActorByName('l1').node.setOrientation(sylphis.CQuaternion(1,0,0,a)*sylphis.CQuaternion(0,1,0,0.2))