Boost logo

Boost :

Subject: Re: [boost] Is there any need for a math library doing vectors and matrices operations?
From: Christophe Riccio (g.truc.creation_at_[hidden])
Date: 2008-11-04 20:48:35


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!


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk