【发布时间】:2014-11-11 05:07:28
【问题描述】:
if(wIsPressed){
movement.x += sin((player.getRotation() * 3.141592654)/ 180) * .5; //accelerates ship at a rate of 0.5 ms^2
movement.y -= cos((player.getRotation() * 3.141592654)/ 180) * .5; //accelerates ship at a rate of 0.5 ms^2
}
else if(abs(movement.x) > 0 || abs(movement.y) > 0){
double angle = (atan2(movement.x, movement.y) * 3.141592654) / 180; //finds angle of current movement vector and converts fro radians to degrees
movement.x -= sin((angle)) * 0.5; //slows down ship by 0.5 using current vector angle
movement.y += cos((angle)) * 0.5; //slows down ship by 0.5 using current vector angle
}
基本上,使用此代码后发生的情况是我的船被直接拉到屏幕底部,并且就像地面有重力一样,我不明白我做错了什么
【问题讨论】:
-
您没有正确地将角度转换为度数。应该是:双角 = atan2(movement.x, motion.y) * 180 / 3.141592654;
-
atan2 返回弧度还是度数?
-
所有三角函数都期望并返回弧度。
-
因为我的加速代码正常,但我的减速代码没有
-
双角 = (atan2(movement.x, motion.y) * 180) / 3.141592654;
标签: c++ sfml trigonometry acceleration atan2