In this example我对使用旋转和翻译感到困惑,更具体地说,
// The earth rotates around the sun
pushMatrix();
rotate(theta);
translate(50,0);
fill(50,200,255);
ellipse(0,0,10,10);
rotate(theta);
旋转了什么?旋转和翻译的关系是什么?
答案 0 :(得分:1)
旋转和平移作用于当前坐标系。
即。绘制动作(rect(),ellipse()等...)将应用于当前坐标系。旋转& translate将移动坐标系。
在您提供的代码块之前,当前点被转换为窗口的中心以便绘制太阳。
pushMatrix()保存该位置,然后相对于太阳中心,“一切”(坐标系)由theta旋转,“一切”由(50,0)平移,有效地将“当前点”移动到然后使用椭圆(0,0,10,10)绘制地球的正确位置。
注意你可以省略翻译步骤并使用ellipse(50,0,10,10)来获得相同的视觉效果,如果不是因为下一个代码块依赖于该翻译来获得月球位置正确。
Here is an interesting link which explains this in terms of "moving the graph paper";