Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (808) Games in Android Showcase (239) games submitted by our members Games in WIP (872) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Rotating A Point  (Read 2128 times) 0 Members and 1 Guest are viewing this topic.
DDDBOMBER

Junior Devvie

Projects: 1

 « Posted 2013-03-01 22:22:41 »

I am rotating a sprite in game around the center, and need to find out where a certain point is, from the original, so for example in the original a point at (1, 1) on the 64 x 128 image. I need to find that point after the rotation. I am using slick2d as my graphics library
cubemaster21
 « Reply #1 - Posted 2013-03-01 22:26:16 »

This is what I use to rotate points, only I use Vector2D, but it works the same way.
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 `   public static Vector2D rotate(Vector2D origin,Vector2D point, double theta){      double s = Math.sin(theta);      double c = Math.cos(theta);      // get the deltaX and deltaY      point.x -= origin.x;          point.y -= origin.y;          // rotate point            double xnew = point.x * c - point.y * s;          double ynew = point.x * s + point.y * c;        // translate point back to global coords:       Vector2D TranslatedPoint = new Vector2D(0,0);       TranslatedPoint.x = xnew + origin.x;         TranslatedPoint.y = ynew + origin.y;        return TranslatedPoint;          }`

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
DDDBOMBER

Junior Devvie

Projects: 1

 « Reply #2 - Posted 2013-03-01 22:43:24 »

Oh cool thanks, i found a way like this of wikipedia's rotation page, but thanks for the help anyways
Pages: [1]
 ignore  |  Print

 mercenarius (4 views) 2020-06-04 19:26:01 mercenarius (2 views) 2020-06-04 19:13:43 Riven (850 views) 2019-09-04 15:33:17 hadezbladez (5834 views) 2018-11-16 13:46:03 hadezbladez (2635 views) 2018-11-16 13:41:33 hadezbladez (6251 views) 2018-11-16 13:35:35 hadezbladez (1504 views) 2018-11-16 13:32:03 EgonOlsen (4739 views) 2018-06-10 19:43:48 EgonOlsen (5797 views) 2018-06-10 19:43:44 EgonOlsen (3282 views) 2018-06-10 19:43:20
 A NON-ideal modular configuration for Eclipse with JavaFXby philfrei2019-12-19 19:35:12Java Gaming Resourcesby philfrei2019-05-14 16:15:13Deployment and Packagingby philfrei2019-05-08 15:15:36Deployment and Packagingby philfrei2019-05-08 15:13:34Deployment and Packagingby philfrei2019-02-17 20:25:53Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org