【发布时间】:2020-01-23 08:34:41
【问题描述】:
我正在开发一个简单的小游戏/模拟游戏,我想在其中反弹一个球。我试图让球弹跳得不是很逼真,而是更多地以“游戏世界”的方式。
我可以使用这些变量:
Vector ball_direction; // Direction the ball was moving in prior to impact
Vector ball_bounce_direction; // New direction of the ball computed from the collided face's normal
Vector collide_face_normal; // The normal of the collided face
Vector collide_face_perp; // perpendicular to the normal of the collided face
Vector gravity; // The gravity of the world-- doesn't really factor in since I want to do this operation based on the collision normal
所以基本上我想做的是:
在 collide_face_normal 方向上将 ball_bounce_direction 乘以 0.6。 在 collide_face_perp 的方向上将 ball_bounce_direction 乘以 1.0。
所以一个在平坦表面上的弹跳球,我希望弹跳变得更小,同时它完全保持其侧向速度。
谁能告诉我我需要对 ball_bounce_direction 做些什么来实现这一点?
【问题讨论】:
-
到底是什么问题?这背后的数学原理? (在那种情况下,这不是真正要问的地方)如何在 C++ 中做到这一点? (如果有,
Vector是什么?) -
Vector 只是一个包含 float x、float y、float z 的类(以及辅助函数)