示例#1
0
 def __init__(self):
     self.position = vec3(0, 0, 0)
     self.yaw = 0
     self.pitch = 0
     self.roll = 0
     self.frustrum = Frustrum()
     self.projection = GraphicsCard.screenProjection
     self.viewMatrix = None
     self.clipMatrix = None
示例#2
0
文件: Camera.py 项目: fathat/game-src
 def __init__(self):
     self.position = vec3( 0, 0, 0 )
     self.yaw   = 0
     self.pitch = 0
     self.roll  = 0
     self.frustrum = Frustrum()
     self.projection = GraphicsCard.screenProjection
     self.viewMatrix = None
     self.clipMatrix = None
示例#3
0
文件: Camera.py 项目: fathat/game-src
class Freecam (object):
    """Camera with free look"""

    def __init__(self):
        self.position = vec3( 0, 0, 0 )
        self.yaw   = 0
        self.pitch = 0
        self.roll  = 0
        self.frustrum = Frustrum()
        self.projection = GraphicsCard.screenProjection
        self.viewMatrix = None
        self.clipMatrix = None

    def apply(self):
        GraphicsCard.loadIdentity()
        GraphicsCard.multMatrix( self.getViewMatrix().toList() )

    def asFreecam(self):
        f = Freecam()
        f.position = vec3(self.position)
        f.yaw   = self.yaw
        f.pitch = self.pitch
        f.roll  = self.roll
        return f

    def move( self, move_vector ):
        r = self.getRotationMatrix()
        self.position = self.position + (r* move_vector )

    def turn( self, yaw, pitch, roll ):
        self.yaw += yaw
        self.pitch += pitch
        self.roll += roll

    def update(self, timestep):
        self._calcViewMatrix()
        self._calcClipMatrix()
        self.frustrum.update(self.getClipMatrix().toList() )

    def sphereVisible(self, sphere):
        c = sphere.center
        return self.frustrum.sphereInFrustrum( c.x, c.y, c.z, sphere.radius )

    def getRotationMatrix( self ):
        return MakeRotationMatrix( -self.yaw, -self.pitch, -self.roll )

    def getTransformMatrix(self):
        return MathUtil.buildTransformMatrix(self.position,
                                             self.yaw,
                                             self.pitch,
                                             self.roll)

    def getViewMatrix( self ):
        if self.viewMatrix is None: self._calcViewMatrix()
        return self.viewMatrix


    def getClipMatrix(self):
        if self.clipMatrix is None: self._calcClipMaptrix()
        return self.clipMatrix

    def _calcViewMatrix(self):
        #self.matrix = MathUtil.buildTransformMatrix(self.position,
        #                                           self.yaw,
        #                                           self.pitch,
        #                                           self.roll )
        self.viewMatrix = MakeViewMatrix( self.position, self.yaw, self.pitch, self.roll )

    def _calcClipMatrix(self):
        proj_m = self.projection.projectionMatrix
        modl_m = self.getViewMatrix()
        self.clipMatrix = (proj_m * modl_m)
示例#4
0
文件: Camera.py 项目: fathat/game-src
 def __init__(self, ent, fov=60,aspect=float(4/3),  zoom = 0 ):
     self.ent  = ent
     self.zoom = zoom
     self.projection = GraphicsCard.screenProjection
     self.frustrum = Frustrum()
示例#5
0
文件: Camera.py 项目: fathat/game-src
class AttachableCamera( object ):
    """First person camera -- attach to an entity of some sort."""
    def __init__(self, ent, fov=60,aspect=float(4/3),  zoom = 0 ):
        self.ent  = ent
        self.zoom = zoom
        self.projection = GraphicsCard.screenProjection
        self.frustrum = Frustrum()

    def asFreecam(self):
        f = Freecam()
        f.position = vec3(self.position)
        f.yaw   = self.yaw
        f.pitch = self.pitch
        f.roll  = self.roll
        return f

    def apply(self):
        GraphicsCard.loadIdentity()
        GraphicsCard.multMatrix( self.getViewMatrix().toList() )

    def move(self, move_vector ):
        #r = self.getRotationMatrix()
        self.ent.moveForward( move_vector )

    def turn( self, yaw, pitch, roll ):
        self.ent.turn( yaw, pitch, roll )

    def update(self, timestep):
        self._calcViewMatrix()
        self._calcClipMatrix()
        #self.getClipMatrix().toList()
        self.frustrum.update(self.getClipMatrix().toList() )

    def sphereVisible(self, sphere):
        c = sphere.center
        return self.frustrum.sphereInFrustrum( c.x, c.y, c.z, sphere.radius )

    def getRotationMatrix( self ):
        return MakeRotationMatrix( -self.ent.yaw, -self.ent.pitch, -self.ent.roll )

    def _calcViewMatrix(self):
        e = self.ent
        self.viewMatrix = MakeViewMatrix( e.headLocation, e.yaw, e.pitch, e.roll )
        #self.matrix = MathUtil.buildTransformMatrix(self.ent.headLocation,
        #                                           self.ent.yaw,
        #                                           self.ent.pitch,
        #                                           self.ent.roll )
        #self.viewMatrix = self.matrix.inverse()

    def _calcClipMatrix(self):
        proj_m = self.projection.projectionMatrix
        modl_m = self.getViewMatrix()
        self.clipMatrix = (proj_m * modl_m)

    def getViewMatrix(self ):
        if not self.viewMatrix: self._calcViewMatrix()
        return self.viewMatrix

    def getClipMatrix(self):
        if not self.clipMatrix: self._calcClipMatrix()
        return self.clipMatrix

    def getposition( self ):
        return self.ent.headLocation

    def getyaw( self ):
        return self.ent.yaw

    def setyaw( self, yaw ):
        self.ent.yaw = yaw

    def getpitch( self ):
        return self.ent.pitch

    def setpitch( self, pitch ):
        self.ent.pitch = pitch

    def getroll( self ):
        return self.ent.roll

    def setroll( self, roll ):
        self.ent.roll = roll

    position = property( getposition )
    yaw      = property( getyaw, setyaw )
    pitch    = property( getpitch, setpitch )
    roll     = property( getroll, setroll )
示例#6
0
class Freecam(object):
    """Camera with free look"""
    def __init__(self):
        self.position = vec3(0, 0, 0)
        self.yaw = 0
        self.pitch = 0
        self.roll = 0
        self.frustrum = Frustrum()
        self.projection = GraphicsCard.screenProjection
        self.viewMatrix = None
        self.clipMatrix = None

    def apply(self):
        GraphicsCard.loadIdentity()
        GraphicsCard.multMatrix(self.getViewMatrix().toList())

    def asFreecam(self):
        f = Freecam()
        f.position = vec3(self.position)
        f.yaw = self.yaw
        f.pitch = self.pitch
        f.roll = self.roll
        return f

    def move(self, move_vector):
        r = self.getRotationMatrix()
        self.position = self.position + (r * move_vector)

    def turn(self, yaw, pitch, roll):
        self.yaw += yaw
        self.pitch += pitch
        self.roll += roll

    def update(self, timestep):
        self._calcViewMatrix()
        self._calcClipMatrix()
        self.frustrum.update(self.getClipMatrix().toList())

    def sphereVisible(self, sphere):
        c = sphere.center
        return self.frustrum.sphereInFrustrum(c.x, c.y, c.z, sphere.radius)

    def getRotationMatrix(self):
        return MakeRotationMatrix(-self.yaw, -self.pitch, -self.roll)

    def getTransformMatrix(self):
        return MathUtil.buildTransformMatrix(self.position, self.yaw,
                                             self.pitch, self.roll)

    def getViewMatrix(self):
        if self.viewMatrix is None: self._calcViewMatrix()
        return self.viewMatrix

    def getClipMatrix(self):
        if self.clipMatrix is None: self._calcClipMaptrix()
        return self.clipMatrix

    def _calcViewMatrix(self):
        #self.matrix = MathUtil.buildTransformMatrix(self.position,
        #                                           self.yaw,
        #                                           self.pitch,
        #                                           self.roll )
        self.viewMatrix = MakeViewMatrix(self.position, self.yaw, self.pitch,
                                         self.roll)

    def _calcClipMatrix(self):
        proj_m = self.projection.projectionMatrix
        modl_m = self.getViewMatrix()
        self.clipMatrix = (proj_m * modl_m)
示例#7
0
 def makeFrustrum(self):
     return Frustrum(self)
示例#8
0
 def __init__(self, ent, fov=60, aspect=float(4 / 3), zoom=0):
     self.ent = ent
     self.zoom = zoom
     self.projection = GraphicsCard.screenProjection
     self.frustrum = Frustrum()
示例#9
0
class AttachableCamera(object):
    """First person camera -- attach to an entity of some sort."""
    def __init__(self, ent, fov=60, aspect=float(4 / 3), zoom=0):
        self.ent = ent
        self.zoom = zoom
        self.projection = GraphicsCard.screenProjection
        self.frustrum = Frustrum()

    def asFreecam(self):
        f = Freecam()
        f.position = vec3(self.position)
        f.yaw = self.yaw
        f.pitch = self.pitch
        f.roll = self.roll
        return f

    def apply(self):
        GraphicsCard.loadIdentity()
        GraphicsCard.multMatrix(self.getViewMatrix().toList())

    def move(self, move_vector):
        #r = self.getRotationMatrix()
        self.ent.moveForward(move_vector)

    def turn(self, yaw, pitch, roll):
        self.ent.turn(yaw, pitch, roll)

    def update(self, timestep):
        self._calcViewMatrix()
        self._calcClipMatrix()
        #self.getClipMatrix().toList()
        self.frustrum.update(self.getClipMatrix().toList())

    def sphereVisible(self, sphere):
        c = sphere.center
        return self.frustrum.sphereInFrustrum(c.x, c.y, c.z, sphere.radius)

    def getRotationMatrix(self):
        return MakeRotationMatrix(-self.ent.yaw, -self.ent.pitch,
                                  -self.ent.roll)

    def _calcViewMatrix(self):
        e = self.ent
        self.viewMatrix = MakeViewMatrix(e.headLocation, e.yaw, e.pitch,
                                         e.roll)
        #self.matrix = MathUtil.buildTransformMatrix(self.ent.headLocation,
        #                                           self.ent.yaw,
        #                                           self.ent.pitch,
        #                                           self.ent.roll )
        #self.viewMatrix = self.matrix.inverse()

    def _calcClipMatrix(self):
        proj_m = self.projection.projectionMatrix
        modl_m = self.getViewMatrix()
        self.clipMatrix = (proj_m * modl_m)

    def getViewMatrix(self):
        if not self.viewMatrix: self._calcViewMatrix()
        return self.viewMatrix

    def getClipMatrix(self):
        if not self.clipMatrix: self._calcClipMatrix()
        return self.clipMatrix

    def getposition(self):
        return self.ent.headLocation

    def getyaw(self):
        return self.ent.yaw

    def setyaw(self, yaw):
        self.ent.yaw = yaw

    def getpitch(self):
        return self.ent.pitch

    def setpitch(self, pitch):
        self.ent.pitch = pitch

    def getroll(self):
        return self.ent.roll

    def setroll(self, roll):
        self.ent.roll = roll

    position = property(getposition)
    yaw = property(getyaw, setyaw)
    pitch = property(getpitch, setpitch)
    roll = property(getroll, setroll)