google / mathfu

C++ math library developed primarily for games focused on simplicity and efficiency.
http://google.github.io/mathfu
Apache License 2.0
1.39k stars 189 forks source link

Vector and matrix copy to C array. #23

Closed panzergame closed 7 years ago

panzergame commented 7 years ago

I'm trying to use mathfu in this project: https://github.com/UPBGE/blender, but i could not find a simple way to copy data from a vector or matrix to a C array. The current library we use has a function named getValue which is used as below:

float a[3];
vec.getValue(a); // content of vec is copied to the a array

But i can't found a way to do similar work using VectorPack and Vector::Pack.

So, what is the simple way to copy the vector content to an array assuming this array could not be replaced by VectorPack ?

aardappel commented 7 years ago

Yeah, there's no convenient function for that, and I agree that be nice to have.

For now you'd have to do:

memcpy(&a[0], &vec[0], sizeof(a));
panzergame commented 7 years ago

In this commit : https://github.com/UPBGE/blender/commit/77dee105559d552e3a4d5835cba9af5765d2fb30 I implemented some operator to copy to a C array and to get a constant C array pointer.

Is these functions safe with SIMD ?

aardappel commented 7 years ago

Yes, looks safe to me.