我有一个包含 40 个旋转图像的图像。
实际上,图像索引从 0. 0-39 开始。
这是将 0-39 转换为度数的代码
int image_direction = 0; //Can be 0-39
int facing_degrees = (int)(360.0 * (-(image_direction- 10.0))/40.0);
while(facing_degrees < 0)
facing_degrees += 360;
while (facing_degrees > 360)
facing_degrees -= 360;
所以是的,它也可以给出负度数以及超过 360 度数。这就是为什么有 2 个 while 循环。
现在我想扭转这个过程说我指定90度我想回到0..
我正在考虑做类似的事情
if(degrees == 90 || degrees >= 80 && degrees <= 99)
image_direction = 0;
elseif(degrees == 100 || degrees >= 91 && degrees <= 109)
image_direction = 39;
//etc.......
好吧,我不擅长数学,好吧,我忘记了这种东西。
我想知道如何反转从 image_direction 给出度数的函数以在一个简单的方程中向后运行,以避免 if 语句的巨大情况。
这是一些结果
Image Index = 0 Image Degree = 90
Image Index = 1 Image Degree = 81
Image Index = 2 Image Degree = 72
Image Index = 3 Image Degree = 63
Image Index = 4 Image Degree = 54
Image Index = 5 Image Degree = 45
Image Index = 6 Image Degree = 36
Image Index = 7 Image Degree = 27
Image Index = 8 Image Degree = 18
Image Index = 9 Image Degree = 9
Image Index = 10 Image Degree = 0
Image Index = 11 Image Degree = 351
Image Index = 12 Image Degree = 342
Image Index = 13 Image Degree = 333
Image Index = 14 Image Degree = 324
Image Index = 15 Image Degree = 315
Image Index = 16 Image Degree = 306
Image Index = 17 Image Degree = 297
Image Index = 18 Image Degree = 288
Image Index = 19 Image Degree = 279
Image Index = 20 Image Degree = 270
Image Index = 21 Image Degree = 261
Image Index = 22 Image Degree = 252
Image Index = 23 Image Degree = 243
Image Index = 24 Image Degree = 234
Image Index = 25 Image Degree = 225
Image Index = 26 Image Degree = 216
Image Index = 27 Image Degree = 207
Image Index = 28 Image Degree = 198
Image Index = 29 Image Degree = 189
Image Index = 30 Image Degree = 180
Image Index = 31 Image Degree = 171
Image Index = 32 Image Degree = 162
Image Index = 33 Image Degree = 153
Image Index = 34 Image Degree = 144
Image Index = 35 Image Degree = 135
Image Index = 36 Image Degree = 126
Image Index = 37 Image Degree = 117
Image Index = 38 Image Degree = 108
Image Index = 39 Image Degree = 99
Image Index = 0 Image Degree = 90
Image Index = 1 Image Degree = 81
Image Index = 2 Image Degree = 72
Image Index = 3 Image Degree = 63
Image Index = 4 Image Degree = 54
Image Index = 5 Image Degree = 45
Image Index = 6 Image Degree = 36
Image Index = 7 Image Degree = 27
Image Index = 8 Image Degree = 18