OpenGL Math Library

Can you guess what the #1 thing on my list that is missing from OpenGL?

That’s right, a math library specific to OpenGL. Most of these functions we call
like glMatrix, glRotate, glScale, glTranslate, etc… use math to some degree, so I think
there should be at least a math library for OpenGL (like D3DX for DirectX).

I’m sick and tired and putting together my own math library. It’s bits and pieces of
other math functions I’ve found on the web. I need something that is not only consistent,
but covers everything from vectors, matrices, and quaternions, basic operations and

Welcome to the jungle!

While I can see the usefulness of an “OpenGL math library”, I would not like it. It’s not strictly necessary so it should not be included to mantain the GL as small and simple as possible.
By the way, I guess it’s pretty difficult to do a library which is well-behaved to all the applications GL has. Going to the lowest common denominator wouldn’t solve the problem.

Just to avoid any confusion, I mean more like a compiled .lib as a math library.
I don’t want a math library built into the ‘gl’ interface.

One of the areas that I get into trouble are conversions to/from the following:
Euler angles, matrices, quaternions, and axis/angle.

Euler angle->matrix
Euler angle->quaternion
Euler angle->axis/angle

Matrix->euler angle

Quaternion->euler angle

Axis/Angle->euler angle

Originally posted by gator:
[b]One of the areas that I get into trouble are conversions to/from the following:
Euler angles, matrices, quaternions, and axis/angle.


That’s fixed in C++ easily enough by creating special unit-knowing types like Degrees and Radians instead of floats. The compiler can do one implicit conversion automatically, so you could have a function that takes Radians and pass it a Degree (with appropriate operator const Radians) and it will convert for you. This sort of type-checking can catch most of those errors, including axis/angle.

I agree we need a standard lib and I’m happy to help write one in my free time. God knows most companies have crap math libs due to the pain-in-the-ass factor. All the time wasted debugging some client’s pre/post matrix multiply routines could be better spent writing a solid math lib.


There are good reasons why providing this sort of standard is not a trivial issue. Most of these reasons have to do with the fact that developers usually taylor the math libs down to the needs of specific applications. They have to pull all these tricks in favor of stability and performance.

One could always rip off math libs from some successful open source 3d engines. After all, this is what open source is all about.

Having said that, how would we know the math lib we just got is a good one? What would be really useful is to establish a set of tests which a successful math library should be able to pass.

That’s a good idea, but I’ve never encountered any math lib testing tools before?

And even if I grabbed some open source math lib, I’m sure there has to be an easy way
to interface it with the testing part?

I would probably use #define macros to interface the testing part. Maybe could also use
Mathematica, Matlab, Excel to get good values, instead of writing it around an existing
math library? But I don’t have any math software.

The DirectX math lib can actually be used with OpenGL too. (Just be carefull as the coordinate systems have the z axis reversed)

I know that sounds frankly dodgy but it links into your code without any external dependencies.

If your after cross platform compatibility, hmm, as madmortigan said, welcome to the jungle.

Personally I liked the challenge of writing my own maths lib but I realise that’s not for everyone. Just for a reference, the Quake III mod lib has a math section with most of the complex core functions such as SLERP which is quite good to learn from.

Testing a math library

One option is to write some sort of layer, a set of adaptor classes, which will bind the math lib under test and the classes that are actually used for the definitions of the tests.

There is going to be an overhead using these classes, but this can measured and analysed, and in any case, we only want to see how one lib compares to another.

There are probably many ways to implement the test suite. The difficulty is to find a sufficient set of tests and say to everyone, here are the tests, pass these and your math lib is good.

A starting point could be some weird old theorems from Euclidean geometry.

Well, there is a math-library which inherits almost everything you might need in your application. Try the matlab library. Ok, matlab is not the cheapest tool, but if you want to start coding your own math-library keep in mind, that there are several more methods needed than transform from location a to b. Start with dynamic resizing of matrices for dimensions greater than 3. The Gauss Algorithm is nice to have, but useless if you want to handle matrices with dimensions of 500+. Only better algorithms gives you acces to determinants, inverse matrices, eigenvalues and so on.
But hey, I’d like to have a math-lib, too.

Regards xDigital

I’m writing a repot on the math behind the I-DEAS (NURBS). Can anyone help letting me know any information availabe on that on any book/ any link or giving some information?



The thickest book about NURBS is “The NURBS Book” written by L. Piegl and W. Tiller.
It is an excellent book, but it is thick (646 pages).
There are numerous books/web stuff about NURBS, I would google “NURBS” to find our more.

Thanks a lot. But, actually my problem is to know how I-DEAS use NURBS surfaces. I need some information about basic mathmematics behind I-DEAS.

I’ve some information about NURB , but how I-DEAS use those, I dont know that in details.

Would you pls suggest me something about that??

Thanks again

One more thing, I was looking for some relative advantages and disadvantages of I-DEAS over CATIA,UG, PE,SE etc…

I’ve searched online, but don’t get anything helpful…

Can u please suggest me where can i get those informations? any book/ link…?



I’ve got the beginnings of an opengl oriented math lib for C++ written and am just about ready to make it publicly available under a BSD-style license. It’s pretty heavily templated, and is done in such a way as to allow things like SSE optimizations to take place automagically via operator overloading. I haven’t implimented these yet, but I hope to get to that soon.

So far I have vectors, matrices, quaternions, and 2d lines in there, as well as some interpolators (catmull-rom, slerp).

In addition to the math classes, it also has a set of wrapper classes for dealing with vertex attributes in a generic way.

For some preliminary docs, check out

I hope to be able to get things cleaned up a bit and put on sourceforge or something similar over spring break (next week). Let me know what you think.