Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add explicit matrix conversion operators to quat #275

Merged
merged 4 commits into from
Nov 24, 2014

Conversation

plasmacel
Copy link

as you stated in issue #274, adding explicit constructors to matrix types would break the spirit of the library. however this feature can be achieved by adding explicit conversion operators to glm::quat. this way the core profile (the matrix types) remains unpolluted, according to the GLSL standard. so the feature only available if GTC_quaternion extension is used. it is a more C++11 friendly way of type conversion and also preserves the concept of the library.

@richardeakin
Copy link

IMO, I don't think overloading operator() is very explicit at all and can make code refactoring a headache. I personally prefer the mat3_cast() if that's what you need. Or, something like a to_mat3() member function (though possibly this isn't really in functional spirit of the library).

@plasmacel plasmacel closed this Nov 24, 2014
@plasmacel plasmacel reopened this Nov 24, 2014
@plasmacel
Copy link
Author

you overload "operator tmat3x3<T,P>" and "operator tmat4x4<T,P>", not at all "operator()".

in C++11 you can define explicit cast operators: http://en.cppreference.com/w/cpp/language/cast_operator

this way you can cast a quat to mat3 or mat4 with a standard static_cast

@richardeakin
Copy link

Ah I see, sorry my mistake as this is very much explicit. :) Personally I'd use the conversion function as it is less typing, but I can see how others might prefer to use this technique.

@plasmacel
Copy link
Author

yeah :), however you can use it with c-style casts too, they are also less typing:

glm::quat q(1.0f, 0.0f, 0.0f, 0.0f);
glm::mat3 m = glm::mat3(q);

@Groovounet Groovounet added this to the GLM 0.9.6 milestone Nov 24, 2014
@Groovounet Groovounet self-assigned this Nov 24, 2014
@Groovounet
Copy link
Member

Very nice. I'll pull to master branch.

Thanks for contributing,
Christophe

Groovounet added a commit that referenced this pull request Nov 24, 2014
add explicit matrix conversion operators to quat #275
@Groovounet Groovounet merged commit 3c0b3c4 into g-truc:master Nov 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants