开发者

Interpolating angles

开发者 https://www.devze.com 2023-01-11 03:54 出处:网络
I am trying to do a rotation of a game object by setting a start and end point and X frames to do the movement. Then interpolate start and end angle to get it done.

I am trying to do a rotation of a game object by setting a start and end point and X frames to do the movement. Then interpolate start and end angle to get it done.

It works well, but I am trying to do the shortest possible route as an option (as opposed to "do the longest route"). In most cases it works, but if the rotation goes above 360 or below 0, I don't know how to detect it and alter th开发者_开发知识库e numbers. (for example if I want to take the shortest route from 270 to 90, the shortest route goes above 360/0, so is never used, so 270 should become -45 to interpolate to 90). I am terrible at explaining and I am not native English to round it up, so I will use pseudocode of what I have.

 thing.start_angle = 180
 thing.end_angle = 90
 thing.angle = interpolate(thing.start_angle, thing.end_angle, position)

I like this way (for the detailed time control over a "if angle > max_angle then angle - 1"), but I can't find a "rule" for how to detect if the angle will rotate... How can I find if the rotation will go below 0 or above 360, to act accordingly?


The angle will wrap if

thing.end_angle - thing.start_angle >= 180 or < -180

(assuming an angle range of 0 to 379).

0

精彩评论

暂无评论...
验证码 换一张
取 消