void CoordinateFrame::getXYZYPRRadians(float& x, float& y, float& z, float& yaw, float& pitch, float& roll) const { x = translation.x; y = translation.y; z = translation.z; const Vector3& look = lookVector(); if (abs(look.y) > 0.99f) { // Looking nearly straight up or down yaw = G3D::pi() + atan2(look.x, look.z); pitch = asin(look.y); roll = 0.0f; } else { // Yaw cannot be affected by others, so pull it first yaw = G3D::pi() + atan2(look.x, look.z); // Pitch is the elevation of the yaw vector pitch = asin(look.y); Vector3 actualRight = rightVector(); Vector3 expectedRight = look.cross(Vector3::unitY()); roll = 0;//acos(actualRight.dot(expectedRight)); TODO } }
void Camera::move(float elapsedMsecs) { // Quit if the camera is not moving in any direction if(!_movementFlags) return; const bool front= _movementFlags & (1 << Front); const bool right= _movementFlags & (1 << Right); const bool back = _movementFlags & (1 << Back ); const bool left = _movementFlags & (1 << Left ); const QVector3D lookDir= lookVector(); // For left/right sidestep, rotate the XZ projection of lookDir QVector3D sideStep(0, 0, 0); if(right xor left) { QTransform transform; transform.rotate(90.0f * (right-left)); const QPointF rotated= transform.map(QPointF(lookDir.x(), lookDir.z())); sideStep= QVector3D(rotated.x(), 0, rotated.y()).normalized(); } const QVector3D moveDir= ((front-back) * lookDir + sideStep).normalized(); _position += elapsedMsecs/1e6d * _moveSpeed * moveDir; updateViewMatrix(); }
Ray CoordinateFrame::lookRay() const { return Ray::fromOriginAndDirection(translation, lookVector()); }
Ray CoordinateFrame::lookRay() const { return Ray(translation,lookVector()); }
void Camera::updateViewMatrix() { _viewMatrix.setToIdentity(); _viewMatrix.lookAt(_position, _position + lookVector(), QVector3D(0,1,0)); }