Java 2D rotation problem?

How does the rotate funtionc in java really work? It seems to me that if you are rotating images, after you have rotated about 180 degrees the image flips so basically my image can never be backwards. I’m rotating my image according to the mouse and in this case using ready made graphics doesn’t work very well space wise, besides its not going to be seamless compared to the mouse.

Now the problem remains. I need to rotate my graphics object, but is it going to be fast enough if I rotate the images pixel by pixel with the trigonometric transformations using the image object?

I’m already having flickering problems(don’t know its speed specific problem) with even clearRect and clipping.

Since the the 2d rotate is a horrible cheater I’m implementing the pixel grabber thing for the images that turn around.

I need to know these things before I conclude anything.
How fast is the pixel grabber function? Lets say that I make make an array which stores 360/5=72 images which all are for the different positions of the mouse, now I take this array and recall the right image every time the mouse comes to its area. This doesn’t sound good to me, it is kind of complicated, but sure, if it is fast I’ll go for it.

The other method is that the program dynamically creates images every time the mouse moves to right position. This way the image is created each time the mouse is moved. This sounds good, but lets say if I have 35 other sprites, perhaps even more, which are animated and are using the exatly same strategy, wouldn’t it get slow? I think yes.

Does anyone have any experiences on this that you could possibly share? Does anyone know what is the pixel rotation math? Currently I have tried to do all kinds of fomulas, but the one I succeeded can be used only for 90 degree rotation since it blurs or craps up everything else.

I figured the rotation alright, I will post the code later. Thanks anyway. Still I needs to know how fast the pixel grabbing is compared to affine transform?

OK the math is fine, but I still have same sort of problem as with graphics2D rotate. I’m using this to get the cords of my mouse


rotateAngle=(int)java.lang.Math.round((java.lang.Math.atan((276-mouseY)/(376-mouseX)))*180/java.lang.Math.PI);

The problem doesn’t seem to be with the rotation functions, because when I tried andle = x++ in thread rotations everything worked out fine. When I use the code from above it seems to be it can’t draw certain areas.

I’m going to bed, perhaps tomorrow, will be better for this.

My bad… There is absolutely nothing wrong with the java rotation. It doesn’t cheat.

As my mind has been clarified with some natural sleep I immediatly found the problem. The problem how I calculate the cords of the mouse as I concluded last night.

Lets take example where mouse is at negative x and negative y side of the cordinates(I’m using polar)
atan((376 -400)/(276-400))

Now the negatives are going to take out each other and hence the angle which should be negative is now positive.

I’m sorry to flood this board with my stuff… I’m going to take my design doc elsewhere. Thanks anyway.

::)Mission Accomplished - Problem solved ::slight_smile:

I had to use atan2 instead of atan1, too bad I had figured out formulas for it before I realized that i was supposed to do so. Posting code to frequently asked pretty soon. The image rotation and the mouse angle.

Thanks!