本文整理汇总了Python中vector.Vector.len方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.len方法的具体用法?Python Vector.len怎么用?Python Vector.len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.len方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Protagonist
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import len [as 别名]
class Protagonist(object):
def __init__(self, texture, program, x, y, position, collisionMap, mesh):
super(Protagonist, self).__init__()
self.tex = texture
self.prog = program
self.x = float(x)
self.y = float(y)
self.cooldown = 0.0
self.collisionMap = collisionMap
self.health = 100
self.velocity = Vector(0.0, 0.0, 0.0)
self.position = Vector(position[0], self.y/2, position[1])
self.maxSpeed = 4
self.modelview = Matrix().translate(position[0], self.y/2, position[1])
self.moved = False
self.angle = 0
self.mesh = mesh
with nested(self.tex):
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
def update(self, delta, state):
self.cooldown-= delta
if self.moved:
self.moved = False
else:
self.velocity = self.velocity * 0.8
if self.velocity.len() < 0.1:
self.velocity = Vector()
facingVelocity = self.velocity.rotatey(self.angle)
movedBy = facingVelocity * delta
if not self.collisionMap.collision(self.position + movedBy, self.x/4):
self.position = self.position + movedBy
self.modelview = Matrix().translate(self.position.x, self.position.y, self.position.z) * Matrix().rotatey(-self.angle)
def move(self, dvel):
self.moved = True
if self.velocity.len() == self.maxSpeed:
return
else:
self.velocity = self.velocity + dvel
if self.velocity.len() > self.maxSpeed:
self.velocity.norm(self.maxSpeed)
def teleport(self, x, y):
self.position.x = x
self.position.z = y
def turn(self, angle):
self.angle = self.angle + angle
def point(self, angle):
self.angle = angle
def draw(self, projection, camera, player_position, r):
self.prog.vars.mvp = projection * camera * self.modelview
self.prog.vars.playerLight = r*0.1 + 0.9
self.prog.vars.playerPosition = player_position.tuple()
self.prog.vars.modelview = self.modelview
with nested(self.prog, self.tex):
self.mesh.draw(GL_QUADS)
def hit(self):
self.health -= 10
def within(self, position):
position = position - self.position
for i in xfrange(0.0, 1.0, 0.05):
point = self.position + (position * i)
if self.collisionMap.collision(point, self.x/4):
return False
return True
def depth(self, proj_cam):
mat = proj_cam * self.modelview
vector = mat.col(3)
return -vector.z
示例2: test_len
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import len [as 别名]
def test_len(self):
v = Vector(3,4)
assert v.len() == 5.0