vendredi 27 février 2015

Quaternion reaching gimbal lock


In attempt to avoid angle lock when performing rotations I've tried to switch over to Quaternions. Somehow, I'm still managing to reach gimbal lock.


I'm not sure if its due to the math I've implemented, or a design error, so please point out if I should change my approach for my object coordinates.


Each of my objects hold an X,Y,Z value, and a pitch,yaw,roll value. When I change a rotation value, the object recalculates its vertices based on the above information. This logic is as follows:



vertices[x] -= /*Offset by origin point*/;
Quaternion q1 = Quaternion(glm::vec3(1,0,0),pitch);
Quaternion q2 = Quaternion(glm::vec3(0,1,0),yaw);
Quaternion q3 = Quaternion(glm::vec3(0,0,1),roll);

Quaternion TotalRot = ( (q3 * q2) * (q1) );
Quaternion Point1 = Quaternion(0, vertices[x].x(), vertices[x].y(), vertices[x].z());

Quaternion Point2 = Quaternion( (TotalRot * Point1) * TotalRot.inverse() );

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

vertices[x]+= /*Undo origin point offset*/;



Aucun commentaire:

Enregistrer un commentaire