【发布时间】:2017-06-12 01:14:38
【问题描述】:
在我正在制作的游戏中,枪支有一个传播(浮动),我想给每个子弹的角度一个随机值,范围为 [-spread, spread]。为此,我认为我可以使用glm::rotate,但问题是子弹几乎向各个方向扩散。
我使用的代码是:
void Gun::fire(const glm::vec2& direction, const glm::vec2& position, std::vector<Bullet>& bullets) {
static std::mt19937 randomEngine(time(nullptr));
// For offsetting the accuracy
std::uniform_real_distribution<float> randRotate(-_spread, _spread);
for (int i = 0; i < _bulletsPerShot; i++) {
// Add a new bullet
bullets.emplace_back(position,
glm::rotate(direction, randRotate(randomEngine)),
_bulletDamage,
_bulletSpeed);
}
}
(在顶部我包括了vector 和glm/gtx/rotate_vector.hpp)
【问题讨论】:
-
来自glm.g-truc.net/0.9.5/updates.html
Finally, here is a list of all the functions that could use degrees in GLM 0.9.5.4 that requires radians in GLM 0.9.6: rotate (matrices and quaternions), [etc.] -
randRotate(randomEngine)) 部分返回一个度数,而 glm::rotate 需要一个弧度。这就是解决方案!谢谢! :)
标签: c++ vector rotation glm-math