Rotate image around Y axis in Java?
I need to rotate the 2nd sprite around the y-axis. For example, I have a 2nd top view of an airplane sprite. When the user turns the plane, the wings must tilt in (or out of) the screen to indicate that they are turning.
Is there a way to put an image in java3d, rotate it, and then put it back into a buffered image? Or maybe it is somehow known how the pixels are supposed to change as they get closer to / away from the screen, and I can just fiddle with the bitmaps to get it done. I know how to get the resulting x positions of each pixel after being rotated around the y-axis, but of course, just having this knowledge makes the image look like it's shrinking as the pixels overlap after rotation.
a source to share
I believe you can achieve YZ rotation using shear transforms, something similar has been used to draw objects in isometric perspective in design applications such as Adobe Illustrator.
Maybe this document will help you, PDF seems to be disabled but there is a copy in google cache.
3D volume expansion using shear transforms
Let us show that an arbitrary three-dimensional rotation can be decomposed into four two-dimensional ray scissors.
a source to share
If you have it in BufferedImage format, you can use AffineTransform to rotate it. See BufferedImage Rotation Issues for an example.
a source to share
Ok, if you need to rotate the image, transformation is the way to go, as Tom said. If you are working with vector graphics, this is just a little math. In this example, the plane is just a triangle with an extra line to indicate that it is headed:
public void rotateRight() {
heading = (heading + vectorIncrement);
}
public void rotateLeft() {
heading = (heading - vectorIncrement);
}
public synchronized void render(Graphics2D g) {
g.setColor(COLOR_SHIP);
// Main line ship
g.drawLine((int)xPos, (int)yPos, (int)(xPos+Math.cos(heading) * width), (int)(yPos+Math.sin(heading) * height) );
g.drawLine((int)xPos, (int)yPos, (int)(xPos-Math.cos(heading) * width/2), (int)(yPos-Math.sin(heading) * height/2) );
// Wings
p = new Polygon();
p.reset();
p.addPoint((int)(xPos+Math.cos(heading) * width), (int)(yPos+Math.sin(heading) * height) );
p.addPoint((int)(xPos+Math.cos((heading+90)%360) * width), (int)(yPos+Math.sin((heading+90)%360) * height) );
p.addPoint((int)(xPos+Math.cos((heading-90)%360) * width), (int)(yPos+Math.sin((heading-90)%360) * height) );
g.drawPolygon(p);
}
This kind of interpolation can also be applied to images to get the required rotation.
a source to share