69

The OpenGL designers were never afraid of mathematics, and knowledge of linear algebra is essential for all but the simplest OpenGL applications. I think it can safely be assumed that OpenGL programmers are familiar with angles in radians.

Mathematically, radians are more elegant than degrees in every respect. They also have practical advantages:

  • The C standard library uses radians.
  • Pretty much any other library out there uses radians as well.
  • Radians are more convenient in some computations, e.g. the length of a circular arc.

Why, then, did the OpenGL designers decide to specify functions like glRotatef and gluPerspective to use degrees?

(I know it's of no practical importance, and it's not going to change anyway. I'm just curious, and I couldn't find the answer on OpenGL.org.)

Thomas
  • 150,847
  • 41
  • 308
  • 421
  • Though I never worked with OpenGL very much - I wonder too, why degrees instead of radians !? It's clear radians are more elegant in every aspect as you said. – sabiland Jan 27 '10 at 12:54
  • 4
    To the person who voted to close: this is a real question, and there must be a definite and conclusive answer out there. Maybe some old minutes from some meeting at SGI, I don't know... – Thomas Jan 27 '10 at 13:03

5 Answers5

31

Because normal people are more used to calculating degrees -- OpenGL is meant to be used simple. Note that all the functions that operate on degrees are "high level" functions.

For OpenGL itself, it's no difference whether it receives radians or degrees -- they are internally converted to transformation matrices anyway, so there's no computational gain of using one or the other.

So why complicate stuff for people if you can allow them using degrees? Anyone coding seriously in OpenGL will provide their own matrices computated from quaternions anyway.

In the same spirit we could ask, why have glRotatef and gluPerspective anyway, since matrices are more elegant in every respect, and allow a higher grade of control.

Point by point:

  • Elegancy - matrices are more elegant in every aspect
  • C library - C library uses them because of computational reasons, GL functions taking angles are not meant to be used for computational heavy tasks (use matrices directly), and probably the implementation has a lookup table for degrees anyway.
  • any other library - following C library for the same reasons as Clib -- also, it's untrue -- many C++ libraries allow a choice, some use the latter
  • Computation conviniency - doesn't matter -- internal representation is matrices, calculations probablye done using lookup tables if meant to be efficient -- there's no direct operation on angles, so representation doesn't matter

Also note: all of the functions using degrees are in the current standard (3.2) deprecated. glRotatef is the only function taking degrees, or as a matter of fact, an angle at all. glu is a utility library not meant for heavy-duty deployment, hence it's tailored towards readability, and gluPerspective(... 60.0f..) is much more readable and "standard" in terms of supplying FOV than gluPerspective( ... M_PI / 3.0f ... ) would be.

Final notes:

Kornel Kisielewicz
  • 51,225
  • 12
  • 100
  • 147
  • 18
    Are you calling OpenGL programmers "normal people"? Using *degrees* is to complicate stuff, like I argued -- you have to convert them to radians at every corner (`atan2` output, to name just one example). – Thomas Jan 27 '10 at 13:00
  • 6
    May be another 'degree' of thinking from OGL developers which we will never know – Jey Geethan Jan 27 '10 at 13:03
  • 1
    @Thomas : if you use atan2 output, it would be shameful not to use quaternions and construct rotation matrices yourself ;) – Kornel Kisielewicz Jan 27 '10 at 13:04
  • I agree that `glRotatef` is not meant for heavy math tasks. `glRotatef` is meant more to test out stuff or be to be used by beginners. In times of OpenGL 3.0 `glRotatef` is deprecated anyway. – abenthy Jan 27 '10 at 13:05
  • @Kornel Kisielewicz (this is completely off-topic -sorry..) but..oh man just 41 days old at SO and 6359 reputation... awsome dude.. looks like doing nothing else than SO.. :) – ashishsony Jan 27 '10 at 13:51
  • @ashishony - there are people with much bigger daily growth : http://stackoverflow.com/questions/tagged?tagnames=&sort=stats&pagesize=30 . I just seem to enjoy the *game*, but usually no more than 2 hours daily :) – Kornel Kisielewicz Jan 27 '10 at 14:09
13

I'd say that since OpenGL was designed with the end-user in mind, degrees were used because one can specify important angles (90, 180, 270 ...) with integers only, and so there is no need for a floating point GL_PI constant.

abenthy
  • 773
  • 7
  • 22
  • 1
    Right! For example, if you are doing 2-d raster-style graphics and want to change the orientation of the screen by 90 degrees, the implementation might want to ensure a clean transform matrix with no floating point error...the representation of 90 degrees in floating point is unambiguous. – Ben Supnik Feb 26 '10 at 03:41
  • 2
    -1. I'm quite sure they are converted to radians internally to use in any trigonometrics :). – Kos Nov 11 '10 at 21:14
  • 1
    The user can still easily specify important angles without having to use GL_PI. That was the point of my answer, note that the interface and the implementation are different aspects of a library. – abenthy Feb 24 '13 at 18:56
  • 1
    Almost certainly they're converted to radians, but your -1 is downvoting the previous comment, not the answer, right? – Justin Jun 15 '13 at 16:29
6

I think it is because you should be able to get an exact rotation matrix for certain angles like 90 or 180 degrees. Like other people here has specified, if you use pi/2 instead of 90 degrees, rounding errors may lead to a transformation matrix that almost performs a rotation by 90 degrees.

Kristofer
  • 61
  • 1
  • 1
4

Code is easier to read, it eases learning curve for newbies and allows quick hacking.

As stated already - degrees HAVE advantage - humans are better used to degrees, compare: 0.78539816339744830961566084581988... to 45 degrees for example :/.

For advanced uses of OpenGL you provide your own matrices anyway.

MaR
  • 854
  • 4
  • 7
  • 4
    Humans are more used to degrees. People talk about turning 90 degrees or "doing a 180", or a 360, 720, 900, or 1080 spin. XBox 360, 1080 Snowboarding, PhotoShop operations are rotations in increments of 90 degrees, etc. No one says "he did a PI", or rotate that picture PI / 2 radians or 1.57 radians, because radians are fractional/irrational numbers, whereas degrees are often whole numbers representing some even division of a circle. Most FOV operations and rotations are done in degrees, and are thought about in increments of 90 degrees for each quadrant. – Triynko Jan 06 '14 at 19:25
  • 3
    45 degrees is PI / 4 radians, not 0.78539816339744830961566084581988. –  Mar 25 '14 at 17:57
1

Well, what happens in most cases is that you use a Math library to convert from radians to degrees and back to radians. I agree with most of what was said by the previous awesome posters.

It's more human readable.

Pieter Germishuys
  • 4,745
  • 1
  • 23
  • 34