Пример #1
0
    def getRenderShape(self):

        matrix = Matrix33()
        matrix.rotate_update(self.rotation)
        matrix.transform_vector2d_list(self.rockShape)

        renderShape = copy.deepcopy(self.rockShape)
        matrix = Matrix33()
        matrix.translate_update(self.pos.x, self.pos.y)
        matrix.transform_vector2d_list(renderShape)

        return renderShape
Пример #2
0
    def transform_points(self,
                         points,
                         pos,
                         forward,
                         side,
                         scale=Vector2D(1, 1)):
        ''' Transform the given list of points, using the provided position,
			direction and scale, to object world space. '''
        # make a copy of original points (so we don't trash them)
        wld_pts = Util.copyPoints(points)

        # create a transformation matrix to perform the operations
        mat = Matrix33()

        # scale,
        mat.scale_update(scale.x, scale.y)

        # rotate
        mat.rotate_by_vectors_update(forward, side)

        # and translate
        mat.translate_update(pos.x, pos.y)

        # now transform all the points (vertices)
        mat.transform_vector2d_list(wld_pts)

        # done
        return wld_pts
Пример #3
0
    def swayShape(self):

        # TODO: Optimise this somehow.
        # At the very least cache it so that both sway functions can use it without recalculating
        sqrtSpeed = self.speedSqrt

        # Speed up fins as we slow down, illusion of swimming harder
        frequency = sqrtSpeed * 0.4

        # The bigger the fish, the slower it should paddle
        # frequency /= (1 + self.body * 0.25)

        # if(self.chosenOne):	print 'spedFreq', frequency
        frequency = Util.clamp(2, frequency, 3)
        # if(self.chosenOne):	print 'clampedFreq', frequency

        # print 'sqrtSpeed', self.speedSqrt(), 'freq', frequency

        swayAngle = sin(self.world._clock * frequency)
        # print 'frequency', frequency

        swayRange = sqrtSpeed / 80
        # print 'swayRange', swayRange

        matrix = Matrix33()
        matrix.scale_update(1 + (swayAngle * 0.2 * sqrt(swayRange)), 1)
        # self.matrix.rotate_update(swayAngle * swayRange)

        shape = deepcopy(self.fishShape)
        matrix.transform_vector2d_list(shape)

        return shape
Пример #4
0
    def transform_point(selfs, point, pos, forward, side):
        wld_pt = point.copy()
        mat = Matrix33()
        mat.rotate_by_vectors_update(forward, side)
        mat.translate_update(pos.x, pos.y)
        mat.transform_vector2d(wld_pt)

        return wld_pt
Пример #5
0
def VectorToLocalSpace(vec, forward, side):
    ''' Return a new vector with the translated direction '''
    # make a copy of the point
    TransVec = vec.copy()
    # create the transformation matrix and plug values straight in
    m = [forward.x, side.x, 0.0, forward.y, side.y, 0.0, 0, 0, 1.0]
    matTransform = Matrix33(m)    
    # now transform the vector
    matTransform.transform_vector2d(TransVec)
    return TransVec
Пример #6
0
def VectorToWorldSpace(vec, forward, side):
    ''' Transforms a vector from the agent's local space into world space '''
    # make a copy of the point
    TransVec = vec.copy()
    # create a transformation matrix
    matTransform = Matrix33()
    # rotate
    matTransform.rotate_by_vectors_update(forward, side)
    # now transform the vertices
    matTransform.transform_vector2d(TransVec)
    return TransVec
Пример #7
0
def PointToLocalSpace(point, pos, forward, side):
    ''' Transform point to local space. '''
    # make a copy of the point
    TransPoint = point.copy() 
    # We'll plug the changes straight in a matrix... save some time (perhaps)
    Tx = -pos.dot(forward)
    Ty = -pos.dot(side)
    m = [forward.x, side.x, 0.0, forward.y, side.y, 0.0, Tx, Ty, 1.0]
    matTransform = Matrix33(m)
    # now transform the vertices
    matTransform.transform_vector2d(TransPoint)
    return TransPoint
Пример #8
0
def PointToWorldSpace(point, pos, forward, side):
    ''' Transforms a point from the agent's local space into world space'''
    # make a copy of the point
    TransPoint = point.copy()
    # create a transformation matrix
    matTransform = Matrix33()
    # rotate
    matTransform.rotate_by_vectors_update(forward, side)
    # and translate
    matTransform.translate_update(pos.x, pos.y)  
    # now transform the vertices
    matTransform.transform_vector2d(TransPoint)
    return TransPoint
Пример #9
0
def WorldTransform(points, pos, forward, side):
    ''' Transform the given list of points, using the provided position and 
        direction, to objects world space. '''
    # make a copy of original points (so we don't trash them)
    tran_points = [ pt.copy() for pt in points ]
    # create a transformation matrix to perform the operations
    matTransform = Matrix33()
    # rotate
    matTransform.rotate_by_vectors_update(forward, side)
    # and translate
    matTransform.translate_update(pos.x, pos.y)
    # now transform all the points (vertices)
    matTransform.transform_vector2d_list(tran_points)
    # done
    return tran_points
Пример #10
0
 def transform_point(self, point, pos, forward, side):
     ''' Transform the given single point, using the provided position,
     and direction (forward and side unit vectors), to object world space. '''
     # make a copy of the original point (so we don't trash it)
     wld_pt = point.copy()
     # create a transformation matrix to perform the operations
     mat = Matrix33()
     # rotate
     mat.rotate_by_vectors_update(forward, side)
     # and translate
     mat.translate_update(pos.x, pos.y)
     # now transform the point (in place)
     mat.transform_vector2d(wld_pt)
     # done
     return wld_pt
Пример #11
0
    def swayShape(self):

        # TODO: Optimise this more
        sqrtSpeed = self.speedSqrt

        # Speed up fins as we slow down, gives the illusion of swimming harder
        frequency = sqrtSpeed * 0.4

        frequency = Util.clamp(2, frequency, 2.5)
        swayAngle = sin(self.world._clock * frequency)
        swayRange = sqrtSpeed / 80

        matrix = Matrix33()
        matrix.scale_update(1 + (swayAngle * 0.2 * sqrt(swayRange)), 1)

        shape = deepcopy(self.fishShape)
        matrix.transform_vector2d_list(shape)

        return shape
Пример #12
0
def Vec2DRotateAroundOrigin(vec, rads):
    ''' Rotates a vector a given angle (in radians) around the origin. 
        Note: the vec parameter is altered (does not return a new vector. '''
    mat = Matrix33()
    mat.rotate_update(rads)
    mat.transform_vector2d(vec)