I wanted to add a grass texture to my 3D polygon-based game, and thought the easiest way to do it was to use a TexturePaint. Currently, the texture stays fixed while the world rotates which isn't the look I'm going for. In order to fix this, I tried using an AffineTransform to rotate the actual image, so that the pattern would come out rotated and would follow the world as it rotated, but this lead to the texture cropping weirdly and didn't work.

This is the code I tried in order to rotate the texture (which doesn't work correctly):

    double rotationRequired = radSpin;
    double locationX = grassImage.getWidth()/2;
    double locationY = grassImage.getHeight()/2;
    AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);

    grassTexture = new TexturePaint(op.filter(grassImage, null), new Rectangle((int)worldX, (int)worldY, (int)(scale*128), (int)(scale*128*getShrink)));

This is run every time the game is painted.

This is what my game looks like when I run the failed code: https://youtu.be/9U-9RqyDyj4

  • \$\begingroup\$ If you can, please try to make your question more brief. The more the question is easy and quick to read, the more answers you will possibly get. \$\endgroup\$ – S. Tarık Çetin Jul 28 '16 at 3:29
  • \$\begingroup\$ @S.TarıkÇetin Alright, thanks for telling me. I shortened it a lot. \$\endgroup\$ – pete2fiddy Jul 28 '16 at 3:54
  • \$\begingroup\$ You are welcome! It is now nicer indeed. \$\endgroup\$ – S. Tarık Çetin Jul 28 '16 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.