| 845 | } |
| 846 | |
| 847 | Pose GetCameraTransform(int sequence, float alpha, bool loop) |
| 848 | { |
| 849 | constexpr auto BLEND_RANGE = 0.1f; |
| 850 | constexpr auto BLEND_START = BLEND_RANGE; |
| 851 | constexpr auto BLEND_END = 1.0f - BLEND_RANGE; |
| 852 | |
| 853 | alpha = std::clamp(alpha, 0.0f, 1.0f); |
| 854 | |
| 855 | if (sequence < 0 || SpotCamRemap.find(sequence) == SpotCamRemap.end()) |
| 856 | { |
| 857 | TENLog("Wrong flyby sequence number provided for getting camera coordinates.", LogLevel::Warning); |
| 858 | return Pose::Zero; |
| 859 | } |
| 860 | |
| 861 | // Retrieve camera count in sequence. |
| 862 | int cameraCount = CameraCnt[SpotCamRemap[sequence]]; |
| 863 | if (cameraCount < 2) |
| 864 | { |
| 865 | TENLog("Not enough cameras in flyby sequence to calculate the coordinates.", LogLevel::Warning); |
| 866 | return Pose::Zero; |
| 867 | } |
| 868 | |
| 869 | // Find first ID for sequence. |
| 870 | int firstSeqID = 0; |
| 871 | for (int i = 0; i < SpotCamRemap[sequence]; i++) |
| 872 | firstSeqID += CameraCnt[i]; |
| 873 | |
| 874 | // Determine number of spline points and spline position. |
| 875 | int splinePoints = cameraCount + 2; |
| 876 | int splineAlpha = int(alpha * (float)USHRT_MAX); |
| 877 | |
| 878 | // Extract camera properties into separate vectors for interpolation. |
| 879 | std::vector<int> xOrigins, yOrigins, zOrigins, xTargets, yTargets, zTargets, rolls; |
| 880 | for (int i = -1; i < (cameraCount + 1); i++) |
| 881 | { |
| 882 | int seqID = std::clamp(firstSeqID + i, firstSeqID, (firstSeqID + cameraCount) - 1); |
| 883 | |
| 884 | xOrigins.push_back(SpotCam[seqID].x); |
| 885 | yOrigins.push_back(SpotCam[seqID].y); |
| 886 | zOrigins.push_back(SpotCam[seqID].z); |
| 887 | xTargets.push_back(SpotCam[seqID].tx); |
| 888 | yTargets.push_back(SpotCam[seqID].ty); |
| 889 | zTargets.push_back(SpotCam[seqID].tz); |
| 890 | rolls.push_back(SpotCam[seqID].roll); |
| 891 | } |
| 892 | |
| 893 | // Compute spline interpolation of main flyby camera parameters. |
| 894 | auto getInterpolatedPoint = [&](float t, std::vector<int>& x, std::vector<int>& y, std::vector<int>& z) |
| 895 | { |
| 896 | int tAlpha = int(t * (float)USHRT_MAX); |
| 897 | return Vector3(Spline(tAlpha, x.data(), splinePoints), |
| 898 | Spline(tAlpha, y.data(), splinePoints), |
| 899 | Spline(tAlpha, z.data(), splinePoints)); |
| 900 | }; |
| 901 | |
| 902 | auto getInterpolatedRoll = [&](float t) |
| 903 | { |
| 904 | int tAlpha = int(t * (float)USHRT_MAX); |