晴明的博客园 GitHub      CodePen      CodeWars     

[canvas] 移动物体

外接矩形判别法

1.mouse.x > rect.x
2.mouse.x < rect.x + rect.width
3.mouse.y > rect.y
4.mouse.y < rect.y + rect.height

外接圆判别法

//鼠标距球心的距离
dx = mouse.x - ball.x;
dy = mouse.y - ball.y;
dist = Math.sqrt(dx*dx + dy*dy)
if(dist < ball.radius){
   //碰上了
}

多边形和不规则图形

分离轴定理(SAT)和最小平移向量(MTV) (黑人问号脸)

物体的抛扔

oldPosition + velocity = newPosition

一般是上一个requestAnimationFrame时间的坐标,大概十几毫秒

posted @ 2016-12-16 16:04  晴明桑  阅读(345)  评论(0编辑  收藏  举报