Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  adjusting points for rotation  (Read 1606 times)
0 Members and 1 Guest are viewing this topic.
Offline 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?
Offline 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:

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
Offline 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:

//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)
        playerRot = Math.atan2(mouseY - playerCenterY, mouseX - playerCenterX);
        swordRot1 = playerRot;
        subx = sword.getX1();
        suby = sword.getY1();
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen

JGO Kernel

Medals: 517

« Reply #3 - Posted 2013-01-14 11:11:58 »

Describe what you want.
Offline 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  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (25 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (202 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!