0

Lets say I have an object, and that object has a quaternion representing its orientation.

Currently, I can rotate on all 3 axes without gimbal lock, however, each rotation on any axis SHOULD rotate the other 2 axes of rotation.

What I mean by this is if I pitch an object towards the camera, but then yaw the object 90 degrees away, pitching the object will still rotate it relative to where it was before, not where it is now.

Here's a visual example of my problem: enter image description here

I'm using quaternions and not euler rotations because these objects can rotate on all 3 axes, and I don't want to gimbal lock/reach singularity

I rotate my object's orientation quaternion like this:

orientation = Quaternion(Vector(0,1,0),angle) * orientation;

I then trigger a rebuilding of my object's vectors, and apply it to them (after transforming the object relative to 3D space origin point):

Quaternion Point = Quaternion(( orientation * (Vertex) ) * (orientation.inverse()));

vertices[x] = QVector3D(round(Point.v.x),round(Point.v.y),round(Point.v.z));

And when I multiply my quaternions by other quaternions, this is the multiplication operator's function:

Quaternion Quaternion::operator*(Quaternion& q) const
{
    Quaternion r;

    //"w" is the angle, "v" is the vector
    r.w = w*q.w - glm::dot(v, q.v);
    r.v = v*q.w + q.v*w + glm::cross(v,q.v);
    //r.normalize();

    return r;
}

I swear to god, I'm only posting because this topic is confusing me to no end. Solidifying this system will be make me unfathomably happy.

Yattabyte
  • 1,280
  • 14
  • 28
  • That is how rotations work... – user253751 Mar 01 '15 at 02:12
  • Rotation has to be done in a specific order, as rotation about each axis has subsequent effects in another. If you wish to undo your rotation, it must be performed in the reverse order. – Mapsy Mar 01 '15 at 02:14
  • To clarify, that "other application" is not actually doing the rotations you think it' s doing. It's probably using Euler angles. – user253751 Mar 01 '15 at 02:15
  • This might be a little helpful. http://stackoverflow.com/questions/6721544/circular-rotation-around-an-arbitrary-axis/21793196#21793196 – Mapsy Mar 01 '15 at 02:15
  • @immibis Other programs like that use quaternions to avoid gimbal lock. That application for example doesn't reach gimbal lock, nor does any other editor I've used in the past. I'm trying to achieve what they all achieve. – Yattabyte Mar 01 '15 at 02:17
  • @AlexT. Using euler rotations leads to gimbal lock/singularity. I've switched over from that system to quaternions to avoid gimbal lock, but now I get this. – Yattabyte Mar 01 '15 at 02:20
  • My function for making a quaternion to rotate around an axis is here: http://stackoverflow.com/questions/4436764/rotating-a-quaternion-on-1-axis/4436915#4436915...I suspect you might need to normalize the quaternion you return from your * function. Also, why write `operator *` everywhere? Just `*` will work. – sje397 Mar 01 '15 at 02:22
  • Okay, I just realized what the actual problem is. Updating post. – Yattabyte Mar 01 '15 at 02:57
  • Check order of rotation compositions, depending on order (right or left) we do rotate in global frame or local (object) frame. – minorlogic Mar 02 '15 at 08:50

0 Answers0