|
Boost : |
From: Olivier Grant (olivier.grant_at_[hidden])
Date: 2006-09-20 12:25:39
Hi,
I have written a bit of code to handle geometric vectors in a generic way,
abstracting their dimension. The idea behind this code is to be able to
apply one operation between two vectors, or a vector and a scalar, whatever
their dimension, and writing it in an expandable way without having to
modify any manipulation functions if a new geometric vector class is
created. The other advantage is that the resulting assembly code is just as
fast as if the functions had all been explicitly written.
Right now I have three simple vector classes - ranging from vector2d to
vector4d - that are not templetized since I like the idea of being able to
access coordinates directly by their name
vector3d vec;
vec.x += 10.0f;
to give you an example of the syntax, here is how you would add two vectors
of different dimensions :
vector2d v1(1.0f, 2.0f);
vector3d v2(-1.0f, 3.0f, 2.0f);
vector4d res;
vector_add(v1, v2, res);
/* res now contains (0.0f, 5.0f, 2.0f, 1.0f) */
the result is determined by the dimension of the third vector passed to
vector_add.
v1 is auto-promoted to act like a vector3d.
v2 does not change.
res gets (v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, default_w_value).
I didn't seem to find any information on a lib currently under development
that provides geometric vector manipulation in that way - maybe apart from
uBLAS - so I thought I would share this if anyone seems to be interested.
BR,
Olivier.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk