bool PxrUsdMayaTranslatorXformable::ConvertUsdMatrixToComponents( const GfMatrix4d &usdMatrix, GfVec3d *trans, GfVec3d *rot, GfVec3d *scale) { GfVec3d rotation, scaleVec, scaleOrientation; _MatrixToVectorsWithPivotInvariant( usdMatrix, //const TransformRotationOrder rotationOrder, XYZ GfVec3d(0,0,0), // const GfVec3d pivotPosition GfVec3d(0,0,0), // const GfVec3d pivotOrientation trans, &rotation, &scaleVec, &scaleOrientation); for (int i=0; i<3; ++i) { // Note that setting rotation via Maya API takes radians, even though // the MEL attribute itself is encoded in degrees. #wtf (*rot)[i] = GfDegreesToRadians(rotation[i]); (*scale)[i] = scaleVec[i]; } return true; }
void GfCamera::SetPerspectiveFromAspectRatioAndFieldOfView( float aspectRatio, float fieldOfView, GfCamera::FOVDirection direction, float horizontalAperture) { // Perspective _projection = Perspective; // Set the vertical and horizontal aperture to achieve the aspect ratio _horizontalAperture = horizontalAperture; _verticalAperture = horizontalAperture / (aspectRatio != 0.0 ? aspectRatio : 1.0); // Pick the right dimension based on the direction parameter const float aperture = (direction == GfCamera::FOVHorizontal) ? _horizontalAperture : _verticalAperture; // Compute tangent for field of view const float tanValue = tan(0.5 * GfDegreesToRadians(fieldOfView)); if (tanValue == 0) { // To avoid division by zero, just set default value _focalLength = 50.0; return; } // Do the math for the focal length. _focalLength = aperture * GfCamera::APERTURE_UNIT / ( 2 * tanValue) / GfCamera::FOCAL_LENGTH_UNIT; }