Okay, i've done some testing, and it seems to work fine x Axis, but messes up somewhere on the y Axis, as in, if i tell it to go from (0,0) to (10,0) it works fine, if i want to move just in the x Axis it has to be
1 2 3 4
| MoveOrder mo = (MoveOrder)orders.get(0); double xd = mo.x - x; double yd = mo.y - y; double rotation = Math.toDegrees(Math.atan2(yd,xd))+90; |
However, if i want to move in the y Axis it has to be
1 2 3 4
| MoveOrder mo = (MoveOrder)orders.get(0); double xd = mo.x - x; double yd = mo.y - y; double rotation = Math.toDegrees(Math.atan2(yd,xd))+270; |
Which even further confuses me...
I've got it to move in the right direction by doing it like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| double movementAngleX = Math.toRadians(rot); double movementAngleY = Math.toRadians(rot+180); x += Math.sin(movementAngleX) * 0.5; y += Math.cos(movementAngleY) * 0.5; if(orders.size() > 0){ if(orders.get(0) instanceof MoveOrder){ MoveOrder mo = (MoveOrder)orders.get(0); double xd = mo.x - x; double yd = mo.y - y; double rotation = Math.toDegrees(Math.atan2(yd,xd))+90; rot = rotation; System.out.println(rot); orders.remove(0); } } |
But then the rotation on the image is messed up, the rendering code is (im using LWJGL)
1 2 3 4 5 6 7 8 9
| GL11.glTranslated(x+32, y+32, 0); GL11.glRotated(rot, 0, 0, -1); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2f(-32, -32); GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2f(32, -32); GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2f(32, 32); GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2f(-32, 32); GL11.glEnd(); |
Anyone got any ideas?