mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-29 03:43:50 +02:00
Simplify/fix 3d matrix rotation extraction (#330)
This commit is contained in:
@@ -3177,22 +3177,16 @@ const offsetFragmentTrackDataByTimestamp = (trackData: FragmentTrackData, timest
|
||||
|
||||
/** Extracts the rotation component from a transformation matrix, in degrees. */
|
||||
const extractRotationFromMatrix = (matrix: TransformationMatrix) => {
|
||||
const [m11, , , m21] = matrix;
|
||||
const [a, b] = matrix; // (1, 0) projects onto (a, b), so that's all we need
|
||||
|
||||
const scaleX = Math.hypot(m11, m21);
|
||||
const radians = Math.atan2(b, a);
|
||||
|
||||
const cosTheta = m11 / scaleX;
|
||||
const sinTheta = m21 / scaleX;
|
||||
|
||||
// Invert the rotation because matrices are post-multiplied in ISOBMFF
|
||||
const result = -Math.atan2(sinTheta, cosTheta) * (180 / Math.PI);
|
||||
|
||||
if (!Number.isFinite(result)) {
|
||||
if (!Number.isFinite(radians)) {
|
||||
// Can happen if the entire matrix is 0, for example
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
return radians * (180 / Math.PI);
|
||||
};
|
||||
|
||||
const sampleTableIsEmpty = (sampleTable: SampleTable) => {
|
||||
|
||||
Reference in New Issue
Block a user