如何每秒旋转一个点
How to rotate a point every second
我有一个点想要旋转,它对应于每一秒的时间,就像时钟中的秒针一样,它应该每秒旋转 6 度,但我试着给它计时,它不需要一分钟完整的旋转,这里是代码
void rotate(const float& ox, const float& oy, float &x, float &y, const float& rotation) {
float tx = x-ox;
float ty = y-oy;
float nx = tx*cos(rotation) - ty*sin(rotation);
float ny = tx*sin(rotation) + ty*cos(rotation);
x = nx+ox;
y = ny+oy;
}
float origx = 1280/2, origy = 720/2, pntx = origx, pnty = origy-300, rotation=6; // variables
rotate(origx, origy, pntx, pnty, rotation*timer.delta); // update point, timer is an object that gets the delta time between frames of the main loop
我有一个点想要旋转,它对应于每一秒的时间,就像时钟中的秒针一样,它应该每秒旋转 6 度,但我试着给它计时,它不需要一分钟完整的旋转,这里是代码
void rotate(const float& ox, const float& oy, float &x, float &y, const float& rotation) {
float tx = x-ox;
float ty = y-oy;
float nx = tx*cos(rotation) - ty*sin(rotation);
float ny = tx*sin(rotation) + ty*cos(rotation);
x = nx+ox;
y = ny+oy;
}
float origx = 1280/2, origy = 720/2, pntx = origx, pnty = origy-300, rotation=6; // variables
rotate(origx, origy, pntx, pnty, rotation*timer.delta); // update point, timer is an object that gets the delta time between frames of the main loop