Using setCamera[XY]Rotation in Q3DScatterWidgetItem to move camera above a point
-
I'm building a 3D scatter graph for a magnetometer calibration tool. The graph is centered on [0,0,0], I'd like to make sure the camera points through the most recent point (call it v) to [0,0,0].
I'm struggling finding the right incantation. I'm not really sure how CameraXRotation and CameraYRotation should relate to the euler angles of v. Here's my latest effort (which doesn't work):QVector3D v = QVector3D(x,y,z); v.normalize(); // camera vector QVector3D camera = QVector3D(0,1,0); // camera along y axis // compute rotation QQuaternion rotation = QQuaternion::rotationTo(camera,v); rotation.getEulerAngles(&pitch,&yaw,&roll); // set camera rotation graph->setCameraXRotation(roll); graph->setCameraYRotation(pitch);
-
After much digging to understand how qtgraphs handles vectors, I did finally crack this. Camera direction is -z, coordinates are y-up. So X rotation angle is from yaw.
QVector3D v = QVector3D(x,y,z); v.normalize(); // camera vector QVector3D camera = QVector3D(0,0,-1); // camera along z axis // compute rotation QQuaternion rotation = QQuaternion::rotationTo(camera,v); rotation.getEulerAngles(&pitch,&yaw,&roll); // set camera rotation graph->setCameraXRotation(yaw); graph->setCameraYRotation(pitch);