Is there any need for a math library doing vectors and matrices operations?

Hi, For a 3D programmers using vectors and matrices is as common as using integers. Actually, it's probably even more common! For this reason, every 3D programmer relies on a math library but as they usually don't need much … they implement their own basic math library and that fine. However, most of the time a single graphics software could uses several math libraries because it uses several external libraries that each of them use there own math library. It involves: - A lot of unnecessary copy and conversion of data. - Different meanings for overloaded operators. - Unspecified conventions: row major matrix, column major matrix, left or right handed? - Use of poor math libraries. - Several libraries to understand, to learn: a waste of time for trivial and common need! GPU programmers get some really convenient languages to do graphics on GPU. Cg: http://developer.download.nvidia.com/cg/Cg_2.0/2.1.0012/Cg-2.1_October2008_L... HLSL: http://msdn.microsoft.com/en-us/library/bb509561(VS.85).aspx<http://msdn.microsoft.com/en-us/library/bb509561%28VS.85%29.aspx> GLSL: http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.08.withchanges.pdf These languages are the result of a lot of experimented developers in 3D graphics and are basically the same. I decided to build a C++ math library based on all the rules that those developers agreed to be good rules and it result in GLM: http://glm.g-truc.net. However, those GPU languages provide good features but limited features: No quaternion, no transformation, lot of limitation on types and rules that couldn't apply directly in C++ (swizzle operators). GLM has limitations because it results of too few developers to think about it. I would like to get more feedback and makes it even more useful. I would lie to making it better find more agreement so that one day it could be ready to be integrated to Boost and hopefully to C++ standard. I'm afraid that such kind of library already have been submitted and rejected, I know it need more work but I believe on my approach and I'm not afraid to change the library so that everyone agree it's good. Thanks, Christophe Riccio

Christophe Riccio wrote:
I'm afraid that such kind of library already have been submitted and rejected, I know it need more work but I believe on my approach and I'm not afraid to change the library so that everyone agree it's good.
Read the archives to see the challenges people have faced trying to get everyone (or just a majority) happy. Cheers, /Marcus

I'm afraid that such kind of library already have been submitted and rejected, I know it need more work but I believe on my approach and I'm not afraid to change the library so that everyone agree it's good.
I'm sorry but I'll state the obvious: did you take a look at boost::ublas? Maybe I'm missunderstanding your email but it does basic vectors and matrices operations (and much more). Philippe

Hi Christophe, The most recent thread on the ublas mailing list about "math library doing vectors and matrices operations" (http://lists.boost.org/MailArchives/ublas/2008/08/2892.php) mentioned the following libraries: ublas glas mtl4 eigen blitz++ TNT It looks like glas, mtl4 and eigen are still in very active development. How does GLM differs from these libraries in features and scope? It looks to me like your library has a similar scope than eigen, but I might be wrong. Regards, Thomas

Christophe Riccio wrote:
GPU programmers get some really convenient languages to do graphics on GPU. [...] GLSL: http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.08.withchanges.pdf
These languages are the result of a lot of experimented developers in 3D graphics and are basically the same. I decided to build a C++ math library based on all the rules that those developers agreed to be good rules and it result in GLM: http://glm.g-truc.net.
So basically, this is an implementation of GLSL in C++. You believe the GLSL API should be the standard API for linear algebra. But do other people agree? Even in the shading language world, isn't Cg more popular? Aren't those APIs very C-ish? There is no genericity in the types.
lot of limitation on types and rules that couldn't apply directly in C++ (swizzle operators).
You can probably implement a simple DSEL to describe swizzle operators. Also, I read on your site you require anonymous unions for some things. Why is that?

On Mon, Nov 3, 2008 at 12:26 PM, Christophe Riccio <g.truc.creation@gmail.com> wrote:
However, those GPU languages provide good features but limited features: No quaternion, no transformation, lot of limitation on types and rules that couldn't apply directly in C++ (swizzle operators).
Take a look at the Boost Vault for a swizzle implementation in C++. http://www.boostpro.com/vault/index.php?&directory=Math%20-%20Geometry You'll want swizzle_demo_01.zip. I'll try to take a look at your library soon. --Michael Fawcett

Am Montag, 3. November 2008 18:26 schrieb Christophe Riccio:
Hi,
For a 3D programmers using vectors and matrices is as common as using integers. Actually, it's probably even more common!
For this reason, every 3D programmer relies on a math library but as they usually don't need much … they implement their own basic math library and that fine. However, most of the time a single graphics software could uses several math libraries because it uses several external libraries that each of them use there own math library.
You are welcome to extend ublas. There seems to be some demand for fixed size vectors and matrices and I'll gladly support any one who is going to implement improvements. mfg Gunter

Gunter Winkler <guwi17 <at> gmx.de> writes:
Am Montag, 3. November 2008 18:26 schrieb Christophe Riccio:
Hi,
For a 3D programmers using vectors and matrices is as common as using integers. Actually, it's probably even more common!
For this reason, every 3D programmer relies on a math library but as they usually don't need much … they implement their own basic math library and that fine. However, most of the time a single graphics software could uses several math libraries because it uses several external libraries that each of them use there own math library.
You are welcome to extend ublas. There seems to be some demand for fixed size vectors and matrices and I'll gladly support any one who is going to implement improvements.
mfg Gunter
@ Michael Fawcett I had a look on the implementation of swizzle operators "swizzle_demo_01.zip". I seems that just allow permutations like: vec4 v1; vec4 v2; ... v1.zyxw = v2.wxyz; Other implementations could provide something like this: v1.zyx = v2.xwx; @ Mathias Gaunard yes basically it is a subset of GLSL but I widelyextend the feature by extensions like it usually done with GLSL. These extensions allows programmers to use GLM as they could use Cg or HLSL ... But there are so few differences ... "Also, I read on your site you require anonymous unions for some things. Why is that?" These could be used but are disabled by default. Half floating numbers have become widely used on GPU first for 64 bits HDR textures and now even for geometry data. This imply that GLM provides vector and matrix types based on half floating point number. However, such type doesn't exist in C++ so GLM provide the a half. This type is used for vectors and matrices of half numbers using a template argument. GLSL specification specify that we can access to a vec4 using x,y,z,w but also r,g,b,a and s,t,p,q. I use union for this. However, unions imply POD types for the template parameter which imply that half types can't be used to instantiate my vec4 template class. I provide a setup option that use anonymous union so that the vec4 template class can be instantiated with a class type and make the multiple names for components access worked ... That's awful to understand? It's an awful problem to solve... Some code to give you an idea: template <typename valType> struct tvec4 { typedef valType value_type; # if defined(GLM_USE_ONLY_XYZW) value_type x, y, z, w; # else//GLM_USE_ONLY_XYZW # ifdef GLM_USE_ANONYMOUS_UNION union { struct{value_type x, y, z, w;}; struct{value_type r, g, b, a;}; struct{value_type s, t, p, q;}; }; # else//GLM_USE_ANONYMOUS_UNION union {value_type x, r, s;}; union {value_type y, g, t;}; union {value_type z, b, p;}; union {value_type w, a, q;}; # endif//GLM_USE_ANONYMOUS_UNION # endif//GLM_USE_ONLY_XYZW And my goal was to not make the rules but to respect others rules, that more or less the best I could get from the rules! @ Thomas Klimpel I had a look on all the library you give me, thanks! Basically, ublas provides tool but not for graphics programmers. We don't need to solve larger linear equation most of the time. We need at least transformations which it doesn't provide. MTL4 seems to provide quite the same features that ublas. blitz++, TNT are not active anymore and not really advanced... However, Eigen look really good I didn't know it actually and have quite the same target than GLM. I definitly have to have a closer look on it! @ Gunter Winkler ublas and GLM seem to be complementary. For example, I think ublas will have a great use to solve dynamic physic but after it comes to the rasterazer or raytracing renderer, it need GLM or Eigen type of library to do the job. I could study the idea to extend ublas. I saved your email to contact you later. @ everyone Thanks for the answers!

On Tue, Nov 4, 2008 at 8:48 PM, Christophe Riccio <g.truc.creation@gmail.com> wrote:
I had a look on the implementation of swizzle operators "swizzle_demo_01.zip". I seems that just allow permutations like:
vec4 v1; vec4 v2; ... v1.zyxw = v2.wxyz;
Other implementations could provide something like this: v1.zyx = v2.xwx;
No, it allows any permutation: float4 v1; float4 v2; ... v1.zy() = v2.wx(); v1.zyw() = v2.ywx(); v1.zyzz() = v2.zxwx(); --Michael Fawcett

Christophe Riccio wrote:
"Also, I read on your site you require anonymous unions for some things. Why is that?" These could be used but are disabled by default. Half floating numbers have become widely used on GPU first for 64 bits HDR textures and now even for geometry data. This imply that GLM provides vector and matrix types based on half floating point number. However, such type doesn't exist in C++ so GLM provide the a half. This type is used for vectors and matrices of half numbers using a template argument. GLSL specification specify that we can access to a vec4 using x,y,z,w but also r,g,b,a and s,t,p,q. I use union for this.
You could perfectly use member functions, that will only add "()" at the end.
participants (7)
-
Christophe Riccio
-
Gunter Winkler
-
Marcus Lindblom
-
Mathias Gaunard
-
Michael Fawcett
-
Philippe Vaucher
-
Thomas Klimpel