旋转命令将rect转换为另一个位置处理

问题描述

在处理中我将rect旋转了35。这是我的代码

manage.py migrate

但是,如果我将旋转度更改为40,则rect旋转并平移到另一个位置。该如何解决

解决方法

您的问题是,当您第一次使用rotate()时,您是相对于整个画布旋转的,因此,当您使用canon1PositionXcannon1PositionY时,取决于您当前所面对的角度画布位置变化。

您需要执行的操作如下:

pushMatrix();
// Go to the cannon position
translate(cannon1PositionX,cannon1PositionY);
// Rotate to the right angle
rotate(35);
// Draw the cannon at the current position and with the right angle
rect(0,25,60,50);
// Draw the second cannon next to the current one
rect(3,4,20,50,50);
popMatrix();