Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (654) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 adjusting points for rotation  (Read 912 times) 0 Members and 1 Guest are viewing this topic.
PRW56

Senior Newbie

 « Posted 2013-01-01 01:37:12 »

_________
|________| *   <-- pretend that is a rectangle and the * behind it is the point, if the rectangle is rotated about the point, how do you know what its new coordinates are?
sproingie

JGO Kernel

Medals: 202

 « Reply #1 - Posted 2013-01-01 05:56:20 »

This is basic coordinate transformation.   The gist is "translate first, then rotate".  Mathematically it's expressed as the multiplication of the transformation matrices of those two operations.

For Java2D:
http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html#Java2D-Tutorial-Transforms

For OpenGL, the same concepts apply, but the API differs, depending on whether you're using fixed function or programmable pipeline.  Doing it by hand will be a nice learning exercise, but if you just want to draw geometry with transformations, you should probably just learn the API for LibGDX or Slick2D
PRW56

Senior Newbie

 « Reply #2 - Posted 2013-01-14 09:06:30 »

Rotation matricies seem to be what I was looking for, but when I try to implement them (at the moment the sword is just a line), I just see the sword rotating from what looks like 90 degrees to 180 degress as fast as it can, and the sword itself is much longer than it should be, this is what pertains to the sword in the game loop:

 1  2  3  4  5  6  7  8  9  10  11  12 `//test is the game character, who is holding the sword        double subx = test.getXloc();        double suby = test.getYloc();        playerCenterX = test.getXloc() + (test.getWidth()/2);        playerCenterY = test.getYloc() + (test.getHeight()/2);        if(cooldown > 0)            cooldown--;                playerRot = Math.atan2(mouseY - playerCenterY, mouseX - playerCenterX);        swordRot1 = playerRot;        subx = sword.getX1();        suby = sword.getY1();        sword.setLine(subx*Math.cos(swordRot)-suby*Math.sin(swordRot),subx*Math.sin(swordRot)+suby*Math.cos(swordRot),sword.getX2(),sword.getY2());`
Roquen
 « Reply #3 - Posted 2013-01-14 11:11:58 »

Describe what you want.
PRW56

Senior Newbie

 « Reply #4 - Posted 2013-01-14 20:08:57 »

I wanted to be able to have the sword about 30 degrees to the right of where the character is facing, then after the mouse is clicked the sword swings around 90 degrees in the leftward direction. What I have in that bit of code is what I thought would work for a stationary sword, but it doesn't stay stationary (as I described in the previous post).
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 bilznatch (20 views) 2015-08-04 11:03:17 SHC (38 views) 2015-08-01 03:58:20 Jesse (24 views) 2015-07-29 04:35:27 Riven (45 views) 2015-07-27 16:38:00 Riven (25 views) 2015-07-27 15:35:20 Riven (27 views) 2015-07-27 12:26:13 Riven (18 views) 2015-07-27 12:23:39 BurntPizza (41 views) 2015-07-25 00:14:37 BurntPizza (50 views) 2015-07-24 22:06:39 BurntPizza (33 views) 2015-07-24 06:06:53
 theagentd 50x wessles 49x basil_ 33x KaiHH 26x orangepascal 22x Riven 21x ags1 17x mooman219 17x bornander 16x KudoDEV 13x CelestialCreator 11x klaus 11x princec 11x pquiring 11x Jesse 9x philfrei 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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