I have a bullet transform and i would like to make it accessible as glm::mat3 type.
However, I am wondering if there is a good to way to do that without copying (like make_mat3x3).
I have a bullet transform and i would like to make it accessible as glm::mat3 type.
However, I am wondering if there is a good to way to do that without copying (like make_mat3x3).
After I skimmed the GLM, I found that - without modifying source code - it is impossible.
The copying is required.
Both Bullet and GLM cache the matrix by value, not pointer or reference.
For Bullet, see an evidence : http://bulletphysics.org/Bullet/BulletFull/btMatrix3x3_8h_source.html
For GLM, see an example : https://glm.g-truc.net/0.9.2/api/a00132_source.html.
It might be faster if you use memcpy
, but I am not sure if it is possible.
It depends on how the values are ordered.
(I have limited knowledge about GLM)
Even you manage to let two objects reside in the same address,
there will be a horrible issue that hard to be managed. (e.g. double delete)
However, before you try to avoid copying, did you profile it?
Copying is not expensive, really.
A few years ago, I wasted a few hours with a similar problem.
In my case, I want to copy Bullet's matrix to Opengl buffer.
Nonetheless, after I profiled it, I found that in all of my game prototypes, this operation cost less than 1% of the whole logic.
Not worth the effort, really.
Premature optimization is the root of evil.