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

Accessing quaternion identity is currently not elegant #765

Closed
Robert42 opened this issue May 23, 2018 · 4 comments
Closed

Accessing quaternion identity is currently not elegant #765

Robert42 opened this issue May 23, 2018 · 4 comments
Assignees
Milestone

Comments

@Robert42
Copy link

Robert42 commented May 23, 2018

There's no easy way of getting an identity for quaternions

In the experimental headers, there's a function

quat_identity<T, Q>()

As quad_identity accepts no function arguments, you have to pass the template arguments T and Q explicitely resulting in calls like

glm::quat_identity<glm::quat::value_type, glm::highp>()

which in my opinion reveals more knowledge of glm implementation details than necessary.

My personal preference

My personally prefered would be to return to the old way of calling

glm::quat::IDENTITY

or something comparable like using static class functions for easy initialization in general:

glm::quat::identitfy()
glm::vec3::x_axis() // Returns glm::vec3(1, 0, 0)

But for some reason, this was removed, so I assume that's not an option. So here are two other suggestions:

Alternative suggestion1: initialization template class

A template class providing static functions with interesting values.
Something comparable to std::numeric_limits ;)

This would make typical values quickly accessible

glm::init<glm::quat>::identity()
glm::init<glm::vec3>::x_axis() // Returns glm::vec3(1, 0, 0)

Here the user has to provide only the quat type he wants to use as template argument

Alternative suggestion 2:

A function only accepting the whole quat type as only argument

template<typename quat_type>
inline quat_type quat_identity()
{
  quat_type q;
  q.x = q.y = q.z = typename quat_type::value_type(0);
  q.w = typename quat_type::value_type(1);
  return q;
}

This implemetation could be used like this:

glm::quat_identity<glm::quat>()

Here the user also has to provide only the quat type he wants to use as template argument

@gurki
Copy link

gurki commented May 28, 2018

/sign

I support your static class accessor proposal, which I implement myself for every project anyways. It's elegant and non-instrusive.

@Groovounet Groovounet self-assigned this Jul 24, 2018
@Groovounet
Copy link
Member

The idea is pretty interesting and could be generalized to others types.

Thanks!

@Groovounet Groovounet added this to the GLM 0.9.9 milestone Jul 24, 2018
@Groovounet
Copy link
Member

Based on your ideas I found an implementation that makes the function to look like this:
glm::quat const Q = glm::identity<glm::quat>(); glm::mat4 const M = glm::identity<glm::mat4x4>();

I should be able to extend this to glm::x_axis<glm::vec3>().

Groovounet pushed a commit that referenced this issue Jul 25, 2018
Groovounet added a commit that referenced this issue Jul 26, 2018
@Groovounet
Copy link
Member

This issue is fixed in master branch for GLM 0.9.9.1 release.

Thanks for contributing,
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants