本文整理匯總了Python中Vector.getMagnitude方法的典型用法代碼示例。如果您正苦於以下問題:Python Vector.getMagnitude方法的具體用法?Python Vector.getMagnitude怎麽用?Python Vector.getMagnitude使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Vector
的用法示例。
在下文中一共展示了Vector.getMagnitude方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: uncollide
# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import getMagnitude [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