0

The code i tried is rotating the image but i want to rotate the image vertically like rotating earth at 360 degrees with 0 inclination

The code i tried is

 public class MainClass extends JPanel {
    static ImageIcon icon = null;
    static RotatedIcon rotate = null;
    static JLabel label = null;

    public MainClass() {
        try {
            BufferedImage wPic = ImageIO.read(this.getClass().getResource(
                    "globe.png"));
            icon = new ImageIcon(wPic);
            rotate = new RotatedIcon(icon, 180);

            label = new JLabel(rotate);

        } catch (Exception e) {
            System.out.println("raise exception");
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        label.repaint();
    }

    public static void main(String[] args) throws IOException,
            InterruptedException {
        MainClass mainClass = new MainClass();
        JFrame frame = new JFrame();
        mainClass.add(label);
        frame.add(mainClass);
        frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        ActionListener taskPerformer = new ActionListener() {
            int degree = 360;

            public void actionPerformed(ActionEvent evt) {

                rotate.setDegrees(degree);
                degree = degree + 90;
                label.repaint();

                mainClass.repaint();

            }
        };
        Timer timer = new Timer(1000, taskPerformer);
        // timer.setRepeats(false);
        timer.start();
        Thread.sleep(5000);
    }
}

https://tips4java.wordpress.com/2009/04/06/rotated-icon/ Reference link of the RotatedIcon class i used. As Explained am able to rotate image but that is not vertically.

JAVA
  • 524
  • 11
  • 23
  • You should really give concrete examples of what you want to achieve, because the rotation that this class does is not around the x axis as you claim, but around the center of the icon. So what you want to achieve is quite unclear. – JB Nizet Jul 03 '17 at 18:39
  • I mean like rotating globe vertically along y-axis keeping centre constant – JAVA Jul 03 '17 at 18:43
  • Do you mean something like [this](https://stackoverflow.com/questions/30587938/is-there-any-easy-way-to-rotate-an-image-about-z-axis-using-java-without-jumping)? – Frakcool Jul 03 '17 at 18:45
  • like this https://www.youtube.com/watch?v=kki1kbmJ8x8 – JAVA Jul 03 '17 at 18:48
  • 1
    Tip, you can add @JBNizet (or whoever you want to reply, so they get notified, the `@` is important) – Frakcool Jul 03 '17 at 18:54
  • You could use JavaFX to make the desired output using the [Camera API](http://docs.oracle.com/javafx/8/3d_graphics/camera.htm) and then add it to your Swing application (however I'm not 100% sure it works) – Frakcool Jul 03 '17 at 19:20
  • this video is showing a 3D earth, an Icon is 2D - you must have an animated gif or a couple of icons for each 'angle' you want to show. – user85421 Jul 03 '17 at 19:24
  • @CarlosHeuberger might be that is the only possible way even i think. any other way you feel better to make the viewer think that it is rotating 360 degrees 0 inclination like in video ? – JAVA Jul 03 '17 at 19:32
  • Using [animated sprites](https://stackoverflow.com/questions/41877789/animated-sprites-with-java-swing) but that requires an image for every angle as suggested by @CarlosHeuberger, I can't think of other solution... – Frakcool Jul 03 '17 at 19:36
  • 1
    @Frakcool so only solution would be taking a group of icons for each angle in an arraylist ,loop it and draw image one by one by using the drawImage method in paintComponent method. right ? – JAVA Jul 03 '17 at 19:54
  • That was my solution, but I think @camickr has another way, try it and see C: – Frakcool Jul 03 '17 at 19:56
  • You're going to need more then one image - [for example](https://stackoverflow.com/questions/35472233/load-a-sprites-image-in-java/35472418#35472418) – MadProgrammer Jul 03 '17 at 22:23
  • @MadProgrammer OMG!! Thank you so much for the reference i will look in to it :) – JAVA Jul 04 '17 at 16:33

1 Answers1

1

If you only have a flat 2D image of the world then then best you might be able to do is use the Marquee Panel.

The Marquee Panel will allow you to scroll the image and you can set it to wrap when it reaches the end. You won't get a 3D effect buy you will scroll around the world with a flat 2D image.

camickr
  • 321,443
  • 19
  • 166
  • 288