javaswingdrawingquadrilaterals

Java swing how to draw an image as a quadrilateral by using 4 points


I want to draw an image as a quadrilateral by using the points of the 4 corners as parameters. Does Java have anything already built in for that? I've seen a similar post but the solution given did not seem to do what I want. The function call would look like this:

wall.drawTexture(Point topLeft, Point topRight, Point bottomLeft, Point bottomRight);

My wall class already contains an attribute "BufferedImage texture".

enter image description here

Context: I'm doing a raycaster engine. I can split my image into smaller columns to correspond to my pixel columns on the 3D view but the texture integrity isn't very high. I thought by only using the first and last ray to hit the same wall face and convert to a parallelogram instead would solve my problem. It would also probably be faster than drawing column by column.


Solution

  • You could use drawLine. Something where it draws a line between 1-2, 1-3, 4-2, 4-3 .