4

I am porting some of the Slick Graphics class to work with AWT, but I've run into a problem. Slick, being run on OpenGL, draws arcs clockwise. AWT defines them as being drawn counter-clockwise, like in math. I'm wondering how I can draw Slick's arc counter-clockwise, so that it matches AWT.

An image of what I'd expect:

http://i.imgur.com/mmMHjhU.png

An image of what I get:

enter image description here

Octavia Togami
  • 4,186
  • 4
  • 31
  • 49

1 Answers1

4

This is the function to draw an arc in Slick2D:

public void drawArc(float x1,
                    float y1,
                    float width,
                    float height,
                    float start,
                    float end)

Since it appears that Slick draws these arcs clock-wise (0 - 360 degrees) then you can do some simple arithmetic to get the effect that you wish.

enter image description here

A and B are your original angles that you wish to draw the arc in between like 0 and 90 degrees. drawArc(0,0,1,1,A,B) will render an arc from A to B, but we want an arc from C to D which is the same arc as A to B but counter-clock wise. Since you already know the values of A and B (like 0 and 90) you can get the values for C and D with the following:

C = 360 - B

D = 360 - A

So now we can just use drawArc(0,0,1,1,C,D).

Test it with values:

A = 0

B = 90

C = 360 - 90 = 270

D = 360 - 0 = 360

This will plot an arc from 270 to 360 which is the same as an arc from 0 to 90 counter-clock wise.

lambda
  • 1,225
  • 2
  • 14
  • 40
  • Does it need to be radians? I'm currently using that function with degrees and it's fine so far. – Octavia Togami Apr 23 '14 at 14:19
  • NVM, it seems to be degrees. But the problem is this: Negative values draw backwards, but they don't change the degree; it ends up looking like this: http://prntscr.com/3co1ua instead of this: http://prntscr.com/3co201 – Octavia Togami Apr 23 '14 at 14:24
  • Oh, it's so close. But for a 180 -> 270, slick is drawing like your circle up there, but AWT is on the other side of the x-axis. – Octavia Togami Apr 24 '14 at 18:28
  • Yes! It works! I didn't notice that `C` used `B` and `D` used `A`, and now it works perfectly! – Octavia Togami Apr 24 '14 at 22:50