ich habe eine Frage zu Rotationen mit QQuaternionen und QSlidern. Und zwar möchte ich mit 3 Slidern für jeweils jede Achse mein Objekt rotieren.
Also mit Hilfe des ersten Sliders kann man das Objekt um x rotieren, mit dem zweiten um y und mit dem dritten um z. Das hatte ich eigentlich auch schon mit QPushButtons realisiert. Der Code für die zuständige slot-Funktion sah so aus:
Code: Alles auswählen
void OpenGLScene::rotiere_x_plus()
{
qreal anglex = 2;
test->rotation *= (QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),anglex));
update();
}
void OpenGLScene::rotiere_x_minus()
{
qreal anglex = -2;
test->rotation *= (QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),anglex));
update();
}
Meine Slot-Funktionen hierfür habe ich folgendermaßen implementiert:
Code: Alles auswählen
QQuaternion cam_temp_x;
QQuaternion cam_temp_y;
QQuaternion cam_temp_z;
.....
void OpenGLScene::rotiere_x(int a)
{
qreal anglex = a;
cam_temp_x = (QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),anglex));
test->rotation = cam_temp_x * cam_temp_y * cam_temp_z;
update();
}
void OpenGLScene::rotiere_y(int a)
{
qreal angley = a;
cam_temp_y = (QQuaternion::fromAxisAndAngle(QVector3D(0,1,0),angley));
test->rotation = cam_temp_x * cam_temp_y * cam_temp_z;
update();
}
void OpenGLScene::rotiere_z(int a)
{
qreal anglez = a;
cam_temp_z = (QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),anglez));
test->rotation = cam_temp_x * cam_temp_y * cam_temp_z;
update();
}
Code: Alles auswählen
QQuaternion cam_temp_x;
QQuaternion cam_temp_y;
QQuaternion cam_temp_z;
.....
void OpenGLScene::rotiere_x(int a)
{
qreal anglex = a;
test->rotation = (QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),anglex));
update();
}
void OpenGLScene::rotiere_y(int a)
{
qreal angley = a;
test->rotation = (QQuaternion::fromAxisAndAngle(QVector3D(0,1,0),angley));
update();
}
void OpenGLScene::rotiere_z(int a)
{
qreal anglez = a;
test->rotation = (QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),anglez));
update();
}
Bei der Methode mit den QPushButtons konnte man mit einem konstanten Wert das Objekt drehen. Bei den Slidern ist das nicht möglich, da ja der wert sich beim sliden ändert. Zwar könnte man für die angle-Variablen konstante Werte einsetzen. Dann hätte ich aber das Problem dass beim Vor und Zurücksliden das Objekt sich die ganze Zeit die eine Richtung drehen würde.
Also es wäre ganz toll wenn ihr vielleicht eine Idee hättet wie man das Problem lösen kann.
Danke schonmal für eure Antworten