18
\$\begingroup\$

I'm looking for a fast opensource C++ math-library for my game engine with the following features:

  • fast (sse?)
  • vectors
  • matrices
  • quaternions

suitable for both opengl and directx

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I don't see why a maths library would be dependent on a graphics API anyway. :P \$\endgroup\$ Mar 18, 2011 at 18:15
  • 3
    \$\begingroup\$ afaik opengl uses column major matrices and directx row major. so it would be nice if the library supported both \$\endgroup\$ Mar 18, 2011 at 18:28
  • 1
    \$\begingroup\$ In GL, you can always set the transposed matrix, and in DX, you can specify the layout in the shaders. Manually adjusting is also no big deal. \$\endgroup\$
    – Anteru
    Mar 18, 2011 at 21:37
  • 1
    \$\begingroup\$ Platform is important here, because it's quite easy to make a mathematics library that works great on a PC but awful on a console, or vice versa. \$\endgroup\$
    – Kylotan
    Mar 20, 2011 at 0:11

6 Answers 6

11
\$\begingroup\$

XNA Math might be for you. It's a header only C++ math library that is distributed with the latest DirectX SDK and uses SSE intrinsics. I can't talk much about its performance but from what I read about it, it seems to be pretty decent.

XNA Math Reference

XNA Math programming guide

DX SDK download

EDIT: I'm also not sure about the licensing terms. The DX SDK Eula states that "Distributable Code" may not be

"run on a platform other than the Windows, Xbox and Windows Mobile platforms;"

I'm not entirely sure whether this applies for xna math as only sample and utility code is explicitly marked as "Distributable Code"

\$\endgroup\$
2
  • \$\begingroup\$ I have no idea whatsoever about XNA's licensing terms, e.g, is it ok to use them in non-microsoft operating systems, for instance. That said, I've used d3dx math library (which is pretty much the same thing) in a software rendering project at one point, so it's not dependent on directx in any means. \$\endgroup\$ Mar 19, 2011 at 11:01
  • 1
    \$\begingroup\$ Clarification: d3dx math is probably pretty much the same thing in licensing terms - implementation-wise it's different though. According to SDK documentation d3dx math relies heavily on inlining and pass by pointer whereas xnamath relies on SIMD and intrinsics. \$\endgroup\$
    – Koarl
    Mar 19, 2011 at 12:54
15
\$\begingroup\$

We use OpenGL Mathematics

Even though the name implies it's just for OpenGL I see no reason it wouldn't work for DirectX. It's a header only library, easy to use and is very actively updated.

Check it out.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ uses MIT license \$\endgroup\$ Mar 19, 2011 at 10:59
5
\$\begingroup\$

Try Eigen -- fast, expression templates, vectorized, easy to use, and is licensed under the MPL2

\$\endgroup\$
0
4
\$\begingroup\$

Maybe CML http://www.cmldev.net/

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Boost software license. \$\endgroup\$ Mar 19, 2011 at 11:00
1
\$\begingroup\$

Sony's vectormath library, used as part of Bullet Physics, meets all your requirements. Some work is involved to separate it from Bullet, but nothing serious - it doesn't depend on bullet, just that no one ever packaged it officially apart from it.

The version currently in the bullet tree supports SSE optimizations, and has a C++ interface.

An older version (probably now unsupported) also supports SOA formats, and a pure C interface.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Seems like zlib/libpng license. \$\endgroup\$ Mar 19, 2011 at 10:59
  • \$\begingroup\$ I'm interested in this. You mentioned that some work is involved in separation, do you have any links or other information about what kind of work that entails? \$\endgroup\$
    – user14497
    Mar 19, 2012 at 15:25
0
\$\begingroup\$

Or, for speed, http://sourceforge.net/projects/simdx86/.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ LGPL, so it's pretty useless. A math library is meant to be inlined, so this pretty much forces your project to be (L)GPL too. \$\endgroup\$ Mar 19, 2011 at 10:55

Not the answer you're looking for? Browse other questions tagged .