Hello..
Im having troubles rotating a bufferedImage. I use this code:
public void rotarDer(){
AffineTransform aff = AffineTransform.getRotateInstance(this.info.getRotacion(),this.info.getPosX(),this.info.getPosY());
AffineTransformOp op = new AffineTransformOp(aff,null);
this.info.setImagen(op.filter(this.info.getImagen(),null));
this.info.setAngulo(-this.info.getRotacion());
}
Its a system that redraws itself many times each second... it is something like a gravity simulator and the problem comes when i want to rotate the ship (it is a small ship that is influenced by gravity)... when i do rotate, the image distorts and if i keep rotating, java is left without heap space and the program crashes.
The code that paints the whole thing is:
protected void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
if(this.nave!=null){
g2.drawImage(this.nave.info.getImagen(),null,(int)this.nave.info.getPosX(),(int)this.nave.info.getPosY());
}
Ive really tried to do many things but none of them seems to work.
I tried to do all this without the affinetransformop and just rotate the affinetransform, then just apply it when painting the ship.. but then the gravity gets messed up... instead of falling down, the ship would start to go to one side or the other... i know that its because the affinetransform changed the coordinate system but i didnt know how to prevent that.
Any help would be REALLY REALLY appreciated..