1
我正在試圖製作一個類似形狀的四軸飛行器,所以我必須圍繞不同點旋轉不同的形狀。如何使用Graphics2D在兩個不同點上旋轉兩個形狀?
下面的代碼片段適用於第一個矩形,而不是第二個矩形。
public void render(Graphics2D g) {
// cx and cy is the center of the shape these spin near
// add prop rotation
at = g.getTransform();
at.rotate(Math.toRadians(prop_rotation), cx, cy-42);
g.setTransform(at);
// Rect 1 spins correctly!
g.fillRect(cx-14, cy-45, 28, 6);
at = g.getTransform();
at.rotate(Math.toRadians(prop_rotation), cx, cy+38);
g.setTransform(at);
// Rect 2 spins around rect 1
g.fillRect(cx-14, cy+35, 28, 6);
}
那麼,如何做到這一點與多中心?