android开源项目DivideAndConquer中的小球碰撞问题
2011-07-05 14:22
435 查看
1.
2.
3.
对于以上问题,尤其是后两个,不是很明白,有明白的客官,路过后可以留言,灰常感谢!
/*看小球是否重叠*/ public boolean isCircleOverlapping(Ball otherBall) { final float dy = otherBall.mY - mY; final float dx = otherBall.mX - mX; final float distance = dy * dy + dx * dx;//两小球间的距离 return (distance < ((2 * mRadiusPixels) * (2 *mRadiusPixels)))//如果距离小于半径的两倍并且不是碰撞后离开的状态,即重叠 // avoid jittery collisions && !movingAwayFromEachother(this, otherBall); }
2.
/*如何判定连个球朝相反方向运动??*/ private boolean movingAwayFromEachother(Ball ballA, Ball ballB) { double collA = Math.atan2(ballB.mY - ballA.mY, ballB.mX - ballA.mX); double collB = Math.atan2(ballA.mY - ballB.mY, ballA.mX - ballB.mX); double ax = Math.cos(ballA.mAngle - collA); double bx = Math.cos(ballB.mAngle - collB); return ax + bx < 0; }
3.
/** * Given that ball a and b have collided, adjust their angles to reflect their state * after the collision. * 弹性碰撞中的能量守恒和动量守恒定律 * This method works based on the conservation of energy and momentum in an elastic * collision. Because the balls have equal mass and speed, it ends up being that they * simply swap velocities along the axis of the collision, keeping the velocities tangent * to the collision constant. * * @param ballA The first ball in a collision * @param ballB The second ball in a collision */ /*碰撞后两个小球的方向??*/ public static void adjustForCollision(Ball ballA, Ball ballB) { final double collA = Math.atan2(ballB.mY - ballA.mY, ballB.mX - ballA.mX); final double collB = Math.atan2(ballA.mY - ballB.mY, ballA.mX - ballB.mX); final double ax = Math.cos(ballA.mAngle - collA); final double ay = Math.sin(ballA.mAngle - collA); final double bx = Math.cos(ballB.mAngle - collB); final double by = Math.cos(ballB.mAngle - collB); final double diffA = Math.atan2(ay, -bx); final double diffB = Math.atan2(by, -ax); ballA.mAngle = collA + diffA; ballB.mAngle = collB + diffB; }
对于以上问题,尤其是后两个,不是很明白,有明白的客官,路过后可以留言,灰常感谢!
相关文章推荐
- Android 开源项目PhotoView遇到问题
- 上百个Android开源项目分享,对andr…
- 开源项目 apk cfg and android app path profiling
- DivideAndConquer-最大子数组问题
- 分治 Divide and Conquer 局部最小值 local optimal 棋盘问题
- 开源异步处项目Droid-Fu详解 For Android: BetterActivity, BetterService And BetterAsyncTask
- eclipse运行android项目出现"The connection to adb is down, and a severe error has occured."的问题
- Android开源项目 "Issue",疑难问题解决方案
- Android 开源项目android-open-project优秀项目解析 ZXing, github-android,Notes,weicuiyuan和gnucash-and,photup
- android 导入开源项目代码常见问题
- android引入开源项目方法,和解决android-support-v4.jar冲突问题
- Android studio导入项目时的问题(Re-download dependencies and sync project (requires network))
- Android处理6.0获取权限问题的第三方框架------开源项目-Easypermissions
- 参考的开源项目中使用Android Support V4, V7, V13等,带来的一堆问题
- android 将开源项目发布到JCenter及问题总结
- android+zip4j开源项目问题汇总
- Android在github上下载的开源项目出现这个问题
- eclipse运行android项目出现"The connection to adb is down, and a severe error has occured."的问题
- android引入开源项目方法,和解决android-support-v4.jar冲突问题
- 关于android运行项目The connection to adb is down, and a severe error has occured。让我们重启eclipse问题