How can I convert coordinates on a square to coordinates on a circle?

后端 未结 3 778
夕颜
夕颜 2020-12-14 22:46

I\'m developing an indie video game, and have been operating under the assumption that because the thumbstick on my controller has a circular range of motion, it returns \"c

3条回答
  •  春和景丽
    2020-12-14 23:23

    Divide each value by the magnitude to normalize all values to a unit vector, e.g.

    magn = sqrt(x * x + y * y);
    newx = magn > 1.0 ? x / magn : x;
    newy = magn > 1.0 ? y / magn : y;
    

    However, this may have the effect of clipping the magnitude instead of normalizing for the interior values.. That is, you'll get the same value for a controller pushed "fully" into the upper-left and a controller almost pushed fully into the same direction.

提交回复
热议问题