0

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

1

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

Smartsav10
  • 123
  • 9
  • Im not sure i understand what you are suggesting. Im trying to take an image and draw it as a quadrilateral. Ive added an image to help clarify. – Frédéric Bélanger May 25 '20 at 20:23
  • Once you get your 4 points from the image, use draw line to connect them maybe. – Smartsav10 May 25 '20 at 21:20
  • yes, i think i can use a double shear to get the desired result. Some math would be needed to get the proper scale factors in order for the image to align with my points but i believe it can work. Big tks! Edit: actually i dont need to shear twice, even better. – Frédéric Bélanger May 26 '20 at 15:54
1

All I can suggest is that you consider the following:

paintComponent(Graphics g) {
     super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    // Rendering hints can visually smooth out the graphics with
    // anti aliasing.
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
}

Other possibilities would be looking at the AffineTransform and related classes where you can manipulate various aspects of a graphics context (e.g. shearing, blurring, etc).

WJS
  • 36,363
  • 4
  • 24
  • 39