I'm missing an essential step and it's been a while since I've taken trig.
Here is the code I'm using. It seems like maybe it's rotating around (0,0) instead of the players pos, which would explain the negative numbers and why the first point isn't always the same (or my math is simply off ). I've taken too much time on something that should be simple. Rescue me/point me in the right direction? I was using this article as a guide, but even in the figure I can see this formula is not rotating the rectangle how I was excpecting. -> https://msdn.microsoft.com/en-us/library/dd162943%28v=vs.85%29.aspx.
public Polygon toRectangle(Image image)
{
//determine verticies of rectangle after rotation
//original points
float x1 = image.getX();
float y1 = image.getY();
System.out.println("First set is: " + x1 + ", " + y1);
float x2 = image.getX() + image.getWidth();
float y2 = image.getY();
System.out.println("Second set is: " + x2 + ", " + y2);
float x3 = image.getX() + image.getWidth();
float y3 = image.getY() + image.getHeight();
System.out.println("Third set is: " + x3 + ", " + y3);
float x4 = image.getX();
float y4 = image.getY() + image.getHeight();
System.out.println("Fourth set is: " + x4 + ", " + y4);
//x' = (x * cos A) - (y * sin A)
//y' = (x * sin A) + (y * cos A)
//Points after rotation
float newX1 = (float)(x1 * Math.cos(image.getRotation())) - (float)(y1 * Math.sin(image.getRotation())));
float newY1 = (float)(x1 * Math.sin(image.getRotation())) + (float)(y1 * Math.cos(image.getRotation())));
float newX2 = (float)(x2 * Math.cos(image.getRotation())) - (float)(y2 * Math.sin(image.getRotation())));
float newY2 = (float)(x2 * Math.sin(image.getRotation())) + (float)(y2 * Math.cos(image.getRotation())));
float newX3 = (float)(x3 * Math.cos(image.getRotation())) - (float)(y3 * Math.sin(image.getRotation())));
float newY3 = (float)(x3 * Math.sin(image.getRotation())) + (float)(y3 * Math.cos(image.getRotation())));
float newX4 = (float)(x4 * Math.cos(image.getRotation())) - (float)(y4 * Math.sin(image.getRotation())));
float newY4 = (float)(x4 * Math.sin(image.getRotation())) + (float)(y4 * Math.cos(image.getRotation())));
System.out.println("First Point after rotation of " + image.getRotation() + ": " + newX1 +", " + newY1 );
System.out.println("Second Point: " + newX2 +", " + newY2 );
System.out.println("Third Point: " + newX3 +", " + newY3 );
System.out.println("Fourth Point: " + newX4 +", " + newY4 );
return new Polygon(new float[]{(float)newX1,(float)newY1,(float)newX2,(float)newY2,(float)newX3,(float)newY3,(float)newX4,(float)newY4});
And the output...
Attacking
Animation duration: 0.4
Animation ends at: 1437844348816
Curren time is: 1437844348416
First set is: 314.0, 208.0
Second set is: 349.0, 208.0
Third set is: 349.0, 283.0
Fourth set is: 314.0, 283.0
First Point after rotation of 90.0: -326.64642, 187.51566
Second Point: -342.32898, 218.80551
Third Point: -409.37872, 185.19998
Fourth Point: -393.69617, 153.91013
Attacking
Animation duration: 0.4
Animation ends at: 1437844353899
Curren time is: 1437844353499
First set is: 314.0, 207.0
Second set is: 349.0, 207.0
Third set is: 349.0, 282.0
Fourth set is: 314.0, 282.0
First Point after rotation of -180.0: -353.75507, 127.68069
Second Point: -374.70117, 155.72104
Third Point: -434.7876, 110.83652
Fourth Point: -413.8415, 82.79617
Attacking
Animation duration: 0.4
Animation ends at: 1437844357899
Curren time is: 1437844357499
First set is: 314.0, 207.0
Second set is: 349.0, 207.0
Third set is: 349.0, 282.0
Fourth set is: 314.0, 282.0
First Point after rotation of -90.0: 44.362198, -373.4662
Second Point: 28.679626, -404.75604
Third Point: 95.72937, -438.36157
Fourth Point: 111.41194, -407.07172
Attacking
Animation duration: 0.4
Animation ends at: 1437844361816
Curren time is: 1437844361416
First set is: 314.0, 210.0
Second set is: 349.0, 210.0
Third set is: 349.0, 285.0
Fourth set is: 314.0, 285.0
First Point after rotation of 0.0: 314.0, 210.0
Second Point: 349.0, 210.0
Third Point: 349.0, 285.0
Fourth Point: 314.0, 285.0
Mob Hit!
Should I be converting degrees to radians? I seriously didn't excpect this function to cause me any trouble
Any help is appreciated!