当前位置: 首页>>代码示例>>Python>>正文


Python Vector.dotp方法代码示例

本文整理汇总了Python中Vector.dotp方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.dotp方法的具体用法?Python Vector.dotp怎么用?Python Vector.dotp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.dotp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import dotp [as 别名]
 def update(self, acceleration, E):
     """ Responsible for time keeping. """
     # Update the velocity for gravity
     self.vy -= acceleration
     
     #Basic Wall interaction
     if self.x >= width - 10:
         self.x = width - 11
         self.vx = -self.vx*E
     if self.y >= height:
         return True
     if self.x <= 5:
         self.x = 6
         self.vx = abs(self.vx*E)
     if self.y <= 5:
         self.y = 6
         self.vy =  abs(self.vy*E)
         
     #Line interaction
     p0 = Vector(mouseX/10, mouseY/10)
     p1 = Vector(80 - mouseX/10, 60 - mouseY/10)
     be = Vector(self.x%80 + self.vx, self.y%60+ self.vy)
     bs = Vector(self.x%80, self.y%60)
     xblo = floor(self.x/80)
     yblo = floor(self.y/60)   
     temp = p0 - p1
     n = Vector(-temp.Y(),temp.X())   
     
     #No collision case
     if n.le() == 0:
         self.x += self.vx
         self.y += self.vy
         return
     
     n = n*(1/n.le())
     v = Vector(self.vx,self.vy) 
     d = self.R
     
     #if n.dotp(bs) - n.dotp(p0) < 0: #This is test code for preventing the ball from going through moving lines
         #d = -d
         
     t = (n.dotp(p0) - n.dotp(bs)) / n.dotp(v) #+d?
     #t2 = (n.dotp(p0) - n.dotp(bs)) / n.dotp(v) #+d?
     bi = bs + v*t
     #bi2 = bs + v*t2    
     
     q = bi - p0
     r = bi - p1
     d0 = (p0 - bi).le()
     d1 = (p1 - bi).le()
     
     #Another collision check
     if q.dotp(r)> 0 or (t<0 or t>1):
         self.x += self.vx
         self.y += self.vy
         return
     
     """ #Further line movement collision testing
     if (t<0 or t>1):
         if not (d0<self.R or d1<self.R):
             self.x += self.vx
             self.y += self.vy
             print("b")
             return
         else:
             print("a")
     """
     
     i = be - bi
     s = i.dotp(n) * n
     u = i-2*s
     bep = u + bi
     nv = u* (1 / u.le())
     speed = v.le()
     self.vx = nv.X()*speed*.95 #This slows it down a little
     self.vy = nv.Y()*speed*.95 #This slows it down a little
     self.x = bep.X() + xblo*80
     self.y = bep.Y() + yblo*60
     
     
     
     
     
     #VVVVVVVVV Old collision CODE DON"T UNCOMMENT ANY OF THIS VVVVVVV
     # Checks for Line interaction   
     #TF LOCAL COORDS
     #NEED FOR LOOP CHECKING FOR MORE THAN JUST ONE INTERACTION
     """
开发者ID:morirete,项目名称:CS167pgame,代码行数:90,代码来源:Ball.py


注:本文中的Vector.dotp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。