Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (574) Games in Android Showcase (154) games submitted by our members Games in WIP (620) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
 1 Game Development / Game Mechanics / Re: Corners of rotated rectangle wrong on: 2014-03-02 10:12:21 Ok I found the wrong line Thanks for your help
 2 Game Development / Game Mechanics / Re: Corners of rotated rectangle wrong on: 2014-03-01 21:04:07 After a few tries I noticed that even if the angle is 0 the rotation is wrong.But I have no idea why
3  Game Development / Game Mechanics / Corners of rotated rectangle wrong on: 2014-03-01 19:32:42
I have a problem calculating the corners of a rotated rectangle.
For the calculation I use a rotation matrix but there is somewhere a little mistake in my code.

As you can see the corners have a wrong positions but were rotated correctly.
Code:

 1  2  3  4 `corners[0] = translatePoint(x, y);corners[1] = translatePoint(x + width, y);corners[2] = translatePoint(x + width, y + height);corners[3] = translatePoint(x, y + height);`

 1  2  3  4  5 `private Point translatePoint(double x, double y) {        double xNew = (x * Math.cos(getAngleInRadians()) - y * Math.sin(getAngleInRadians()));        double yNew = (x * Math.sin(getAngleInRadians()) + y * Math.cos(getAngleInRadians()));        return new Point(xNew, yNew);}`

(x,y) is the left top corner of the unrotated rectangle.