当前位置: 首页>>代码示例>>Python>>正文


Python Transform.normalize方法代码示例

本文整理汇总了Python中Transform.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.normalize方法的具体用法?Python Transform.normalize怎么用?Python Transform.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transform的用法示例。


在下文中一共展示了Transform.normalize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hit_test

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import normalize [as 别名]
    def hit_test(self, position, vector, max_distance=8):
        """ Line of sight search from current position. If a block is
        intersected it is returned, along with the block previously in the line
        of sight. If no block is found, return None, None.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position to check visibility from.
        vector : tuple of len 3
            The line of sight vector.
        max_distance : int
            How many blocks away to search for a hit.

        """
        m = 8
        x, y, z = position
        dx, dy, dz = vector
        previous = None
        for _ in xrange(max_distance * m):
            key = Transform.normalize((x, y, z))
            if key != previous and self.world.existsBlockAt(key):
                return key, previous
            previous = key
            x, y, z = x + dx / m, y + dy / m, z + dz / m
        return None, None
开发者ID:gentoomaniac,项目名称:Minecraft,代码行数:28,代码来源:Model.py

示例2: collide

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import normalize [as 别名]
    def collide(self, position, height):
        """ Checks to see if the player at the given `position` and `height`
        is colliding with any blocks in the world.

        Parameters
        ----------
        position : tuple of len 3
            The (x, y, z) position to check for collisions at.
        height : int or float
            The height of the player.

        Returns
        -------
        position : tuple of len 3
            The new position of the player taking into account collisions.

        """
        # How much overlap with a dimension of a surrounding block you need to
        # have to count as a collision. If 0, touching terrain at all counts as
        # a collision. If .49, you sink into the ground, as if walking through
        # tall grass. If >= .5, you'll fall through the ground.
        pad = 0.25
        p = list(position)
        np = Transform.normalize(position)
        for face in Block.FACES:  # check all surrounding blocks
            for i in xrange(3):  # check each dimension independently
                if not face[i]:
                    continue
                # How much overlap you have with this dimension.
                d = (p[i] - np[i]) * face[i]
                if d < pad:
                    continue
                for dy in xrange(height):  # check each height
                    op = list(np)
                    op[1] -= dy
                    op[i] += face[i]
                    if not self.model.world.existsBlockAt(tuple(op)):
                        continue
                    # check for non resiting block (no colision)
                    if not self._materialFactory.getMaterial(
                            self.model.world.getBlock(tuple(op)).getMaterial()).clipping:
                        continue

                    p[i] -= (d - pad) * face[i]
                    if face == (0, -1, 0) or face == (0, 1, 0):
                        # You are colliding with the ground or ceiling, so stop
                        # falling / rising.
                        self.dy = 0
                    break
        return tuple(p)
开发者ID:gentoomaniac,项目名称:Minecraft,代码行数:52,代码来源:engine.py

示例3: view_test

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import normalize [as 别名]
    def view_test(self, source, target):
        """ Check if plock at position has a line of sight to character.

        Parameters
        ----------
        source : tuple of len 3
            The (x, y, z) position to check visibility from.
        target :tuple of len 3
            The (x, y, z) position to check visibility to.
        """
        m = 8
        x, y, z = source
        dx, dy, dz = target
        previous = None
        for _ in xrange(max_distance * m):
            key = Transform.normalize((x, y, z))
            if key != previous and self.world.existsBlockAt(key):
                return key, previous
            previous = key
            x, y, z = x + dx / m, y + dy / m, z + dz / m
        return None, None
开发者ID:gentoomaniac,项目名称:Minecraft,代码行数:23,代码来源:Model.py


注:本文中的Transform.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。