sgorsten / linalg

linalg.h is a single header, public domain, short vector math library for C++
The Unlicense
849 stars 68 forks source link

Convert a mat4 to a mat3 and back #33

Open mokafolio opened 1 year ago

mokafolio commented 1 year ago

Hi, I am not sure if I am missing something so please correct me if there already is an easier way to do this. Here's what I want to do:

This is a pretty common operation for a bunch of 3D rendering related tasks. I have been doing that manually so far (the types are just linalg typedefs):


auto skyboxViewRot = Mat3f { transform.x.xyz(), transform.y.xyz(), transform.z.xyz() };
auto skyboxView = Mat4f { Vec4f { skyboxViewRot.x, 0.0f },
                                        Vec4f { skyboxViewRot.y, 0.0f },
                                        Vec4f { skyboxViewRot.z, 0.0f },
                                        Vec4f { 0.0f, 0.0f, 0.0f, 1.0f } };

I am pretty sure in glm the mat3 and mat4 constructors allow you to do this as one liners. Is there a similar way to achieve this in linalg? Otherwise I think it might be useful to add utilities for these operations (not sure if this is beyond the scope of the library but these seem to be very common operations to me).

Thanks!