本文整理匯總了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
示例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)
示例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