Ich will mein Auto im Spiel, das ich habe, um 90 Grad nach links drehen.Wie man eine GLM-Quaternion korrekt rotiert?
Wenn ich diesen Code verwenden:
glm::quat rot(info.Rotation.w,info.Rotation.x,info.Rotation.y,info.Rotation.z);
glm::quat done(glm::rotate(rot,glm::eulerAngles(rot)+glm::vec3(90.0f,0.0,0.0)));
info.Rotation.x = done.x;
info.Rotation.y = done.y;
info.Rotation.z = done.z;
info.Rotation.w = done.w;
Das Auto bekommt eine seltsame Rotation.
jedoch die folgenden Codes nicht die Autos Rotation überhaupt ändern (genau das, was ich erwartet habe, nur um sicher zu sein, dass GLM mit dem Quats aus dem Spiel kompatibel ist):
glm::quat rot(info.Rotation.w,info.Rotation.x,info.Rotation.y,info.Rotation.z);
glm::quat done(rot);
info.Rotation.x = done.x;
info.Rotation.y = done.y;
info.Rotation.z = done.z;
info.Rotation.w = done.w;
und wenn ich versuche, dies zu überprüfen, ob die Rotation mit ihr verändert wird:
glm::quat rot(info.Rotation.w,info.Rotation.x,info.Rotation.y,info.Rotation.z);
glm::quat done(glm::rotate(rot,vec3(0.0,0.0,0.0)));
info.Rotation.x = done.x;
info.Rotation.y = done.y;
info.Rotation.z = done.z;
info.Rotation.w = done.w;
die Autos Drehung wird auf die 0,0,0,0 Rotationen im Spiel gerade eingestellt hat. Ich erwartete die Drehungen mit diesem Code unberührt zu bleiben, weil ich den folgenden Code erwartet, dass das Auto um 90 Grad nach links zu drehen:
glm::quat rot(info.Rotation.w,info.Rotation.x,info.Rotation.y,info.Rotation.z);
glm::quat done(glm::rotate(rot,vec3(90.0,0.0,0.0)));
info.Rotation.x = done.x;
info.Rotation.y = done.y;
info.Rotation.z = done.z;
info.Rotation.w = done.w;
aber das funktioniert nicht so, wie ich will. Es stellt nur die Rotation ein, fügt sie nicht zu 'rot' hinzu.
Was mache ich falsch?
Werfen Sie einen Blick auf http://www.arcsynthesis.org/gltut/Positioning/Tut08%20Quaternions.html – user1929959
den Code von dort abgerichtet, aber mein Auto nicht wirklich drehen, was muss ich in der "Winkel" Parameter, der Winkel des Autos, damit es richtig funktioniert? Z Winkel oder etwas? –
@Gizmo: [Sehen Sie sich diese Frage und Antworten an.] (Http://stackoverflow.com/q/9715776/734069) –