I assume that you are using only Swing / AWT frames for graphics. If this is not the case, please update your question.
If you use Swing and the Graphics2D class (which uses the components of the swing class), you are dealing with a 2D framework. It just means that the fantastic 3D material is not built-in - you will have to implement the transformations yourself (or start capturing 3D classes to do your job).
So, you are on the right track - you need to first set the clip (so that it matches your shape), and then perform the rotation (therefore, it is displayed at the right angle).
Saying this, making basic rotary transformations is not so difficult. There is a good outline of the (main) turns here . Of course, this gets a little trickier if you have turns based on more than just one axis. But, as explained later in the article, if you multiply matrices (Rx) (Ry) (Rz), you can use the resulting matrix to determine the location of your pixel.
I created a quick example with rotation along the Y axis. Notice that I compiled a silent algorithm (Magic Vanishingpoint Technology®) to give a vague illusion of depth. I assume that you already have something for this - this is probably more correct.
import java.awt.*; import java.awt.image.*; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class Rotation3D extends JPanel{ Image img; BufferedImage rotatedImage; final int ROTATION_DEGREES = 70; int vanishX = 0; int vanishY = 0; int vanishZ = -1000; public Rotation3D(){ try {
source share