Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 07 November 2012 - 11:26 PM
Posted 08 November 2012 - 09:45 AM
Edited by Álvaro, 08 November 2012 - 03:36 PM.
Posted 09 November 2012 - 01:51 PM
Posted 09 November 2012 - 02:11 PM
Posted 10 November 2012 - 11:03 PM
Posted 11 November 2012 - 12:31 AM
Not quite. You need to scale the unreal part of the quaternion (the coefficients of i, j and k) so that the whole quaternion is unit length. Something like this:Also I am not sure what you meant by scaling the other three parts after changing the W value. Do I need to just normalize it?
#include <boost/math/quaternion.hpp> #include <cmath> typedef boost::math::quaternion<double> Q; Q limit_rotation(Q q, double min_real_part) { if (q.real() <= -min_real_part || q.real() >= min_real_part) return q; if (q.real() < 0) q = -q; double desired_unreal_length = std::sqrt(1 - min_real_part * min_real_part); double old_unreal_length = abs(q.unreal()); return Q(min_real_part) + q.unreal() * (desired_unreal_length / old_unreal_length); }
Edited by Álvaro, 11 November 2012 - 12:33 AM.
Posted 13 November 2012 - 12:27 PM
return Q(min_real_part) + q.unreal() * (desired_unreal_length / old_unreal_length);
}
Posted 13 November 2012 - 01:23 PM
Posted 14 November 2012 - 10:31 PM
Posted 15 November 2012 - 01:41 AM
Sorry Alvaro, the documentation didn't help me as it does not show how they calculate the unreal part. If you say the unreal part is "0 + xi +yj +zk", then how do I get the value of i,j,k?
i, j and k are never 1 and they are never 0. I am not sure what you have seen that gave you that impression.Sorry for not understanding, I think I'm struggling to understand the imaginary part of quaternions. It seems sometimes i,j,k just get dropped (meaning value of 1), and sometimes they are zero. I really appreciate your help.
Posted 15 November 2012 - 02:43 AM
Posted 15 November 2012 - 07:53 AM
public Quaternion unreal() { return Quaternion(0, this.x, this.y, this.z); // or with `new', or however this is done in your language. }
Posted 18 November 2012 - 09:30 PM
Edited by JM33, 18 November 2012 - 09:34 PM.
Posted 18 November 2012 - 09:33 PM
Posted 11 December 2012 - 02:30 AM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.