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.

9
  • That is how rotations work... Commented Mar 1, 2015 at 2: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. Commented Mar 1, 2015 at 2:14
  • To clarify, that "other application" is not actually doing the rotations you think it' s doing. It's probably using Euler angles. Commented Mar 1, 2015 at 2:15
  • This might be a little helpful. stackoverflow.com/questions/6721544/… Commented Mar 1, 2015 at 2: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. Commented Mar 1, 2015 at 2:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.