本文整理汇总了Python中Vector.setVector方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.setVector方法的具体用法?Python Vector.setVector怎么用?Python Vector.setVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.setVector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: elasticCollision
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import setVector [as 别名]
def elasticCollision(self,o):
"""
Elastic collision with another object
This changes the velocity of both objects
"""
normal = Vector( o.x - self.x, self.y - o.y )
normal.setVector( normal.getUnitVector() )
tangent = Vector( -normal.y, normal.x )
m1 = self.mass
m2 = o.mass
v1n = normal.dotProduct( self.velocity )
v1t = tangent.dotProduct( self.velocity )
v2n = normal.dotProduct( o.velocity )
v2t = tangent.dotProduct( o.velocity )
v1tPrime = v1t
v2tPrime = v2t
v1nPrime = (v1n*(m1-m2)+v2n*m2*2)/(m1+m2)
v2nPrime = (v2n*(m2-m1)+v1n*m1*2)/(m1+m2)
vectorV1nPrime = normal.multiply(v1nPrime)
vectorV1tPrime = tangent.multiply(v1tPrime)
vectorV2nPrime = normal.multiply(v2nPrime)
vectorV2tPrime = tangent.multiply(v2tPrime)
self.velocity = vectorV1nPrime.add(vectorV1tPrime).multiply(ELASTIC_COLLISION_DAMPENING)
o.velocity = vectorV2nPrime.add(vectorV2tPrime).multiply(ELASTIC_COLLISION_DAMPENING)
示例2: uncollide
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import setVector [as 别名]
def uncollide(self,o):
"""
moves this object out of the other object
which prevents collision detection from changing velocity moar than once
DOESN'T CHANGE VELOCITY
"""
if o.isCircle():
normal = Vector( o.centerx - self.centerx, self.centery - o.centery )
distanceToMove = self.width/2.0 + o.width/2.0 - normal.getMagnitude()
normal.setVector( Vector (-normal.x, -normal.y ) )
normal.setVector( normal.getUnitVector() ) # set's to 1 so we can multiply better
normal = normal.multiply( distanceToMove ); #gets short vector
self.setX( self.x + normal.x)
self.setY( self.y - normal.y)
else:
posRel = self.posRelTo(o)
if posRel == 1: self.setY( self.y - ( self.y + self.height - o.y ) )
elif posRel == 2: self.setX( self.x - ( self.x + self.width - o.x ) )
elif posRel == 3: self.setX( self.x + ( o.x + o.width - self.x ) )
elif posRel == 4: self.setY( self.y + ( o.y + o.height - self.y ) )
else: self.setY( self.y - ( self.y + self.height - o.y ) ) #just move it up