當前位置: 首頁>>代碼示例>>Python>>正文


Python Vector.setVector方法代碼示例

本文整理匯總了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)
開發者ID:blendmaster,項目名稱:Rokkit-Tanx,代碼行數:32,代碼來源:PhysicsObject.py

示例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
開發者ID:blendmaster,項目名稱:Rokkit-Tanx,代碼行數:26,代碼來源:PhysicsObject.py


注:本文中的Vector.setVector方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。