简体   繁体   English

Java围绕中心旋转对象?

[英]Java Rotate object around center point?

Hello I am making a programme that shows you the different planets in space. 您好,我正在编写一个程序,向您显示太空中的不同行星。 I have the sun in the very center of the window and all the planets around it. 我把太阳放在窗户的正中央,周围还有所有行星。 I want the planets to rotate around the sun but I have no idea how I could do this. 我希望行星绕太阳旋转,但我不知道该如何做。 Please help me. 请帮我。 Here is the code where I draw the planets and sun onto the screen: 这是我在屏幕上绘制行星和太阳的代码:

public class Solar1 extends BasicSystem {

private Image img;

public int px = 300,py = 300,px1 = 200,py1 = 200;


public Solar1() {

}

public void tick() {

}

public void render(Graphics g) {

    ImageIcon i = new ImageIcon("res/bg/bg1.png");
    img = i.getImage();
    g.drawImage(img, 0,0, null);

    ImageIcon i2 = new ImageIcon("res/planets/sun.png");
    img = i2.getImage();
    g.drawImage(img, Comp.size.width / 2 - 50, Comp.size.height / 2 - 50, null);

    ImageIcon i12 = new ImageIcon("res/planets/blue.png");
    img = i12.getImage();
    g.drawImage(img, px,py, null);

    ImageIcon i1112 = new ImageIcon("res/planets/green.png");
    img = i1112.getImage();
    g.drawImage(img, px1,py1, null);

}

}
        int i=0;

        while(true){
            planet1.setX(Math.cos(Math.toRadians(i)))*widthOfFrame;         
            planet1.setY(Math.sin(Math.toRadians(i)))*heightOfFrame;
            i++;
        }

...where i is the number of iteration. ...其中i是迭代次数。 You will also need to find out how to set the speed, distance from the central point, etc... 您还需要了解如何设置速度,距中心点的距离等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM