adjusting points for rotation


|________| * <-- 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?

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

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)
            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());

Describe what you want.

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).