Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

closed as not constructive by Byte56, Tetrad Dec 24 '12 at 20:20

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I don't see why a maths library would be dependent on a graphics API anyway. :P –  The Communist Duck Mar 18 '11 at 18:15
3  
afaik opengl uses column major matrices and directx row major. so it would be nice if the library supported both –  pragmascript Mar 18 '11 at 18:28
1  
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. –  Anteru Mar 18 '11 at 21:37
1  
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. –  Kylotan Mar 20 '11 at 0:11
add comment

6 Answers 6

up vote 9 down vote accepted

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"

share|improve this answer
    
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. –  Jari Komppa Mar 19 '11 at 11:01
1  
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. –  Koarl Mar 19 '11 at 12:54
add comment

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.

share|improve this answer
2  
uses MIT license –  Jari Komppa Mar 19 '11 at 10:59
add comment

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

share|improve this answer
1  
LGPL/GPL. They claim the version of LGPL they're using is compatible with closed-source projects, but I'd be wary. –  Jari Komppa Mar 19 '11 at 10:58
    
@Jari See eigen.tuxfamily.org/… –  Carnby Mar 19 '11 at 11:27
1  
@Carnby: Their FAQ is awkward. If they are arguing that section 3 applies, then they can't ask for the source for changes under section 4. If they are asking for the source for changes under section 4, they can't argue that people are using it under section 3. The email from Brett Smith at the FSF does not clarify this issue, as far as I can tell - all he says is that yes, the section 3 exception can apply. All in all, it is tricky enough I might want to talk to a lawyer, or the FSF/Eigen developers directly. –  user744 Mar 19 '11 at 13:38
1  
Eigen is now under MPL2. –  Martin Berger May 4 at 11:37
add comment

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

share|improve this answer
1  
Boost software license. –  Jari Komppa Mar 19 '11 at 11:00
add comment

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.

share|improve this answer
1  
Seems like zlib/libpng license. –  Jari Komppa Mar 19 '11 at 10:59
    
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? –  K.G. Mar 19 '12 at 15:25
add comment

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

share|improve this answer
2  
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. –  Jari Komppa Mar 19 '11 at 10:55
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.