package androidx.media3.exoplayer.video.spherical;

import androidx.media3.common.util.Assertions;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/* JADX INFO: loaded from: classes.dex */
final class Projection {
    public static final int DRAW_MODE_TRIANGLES = 0;
    public static final int DRAW_MODE_TRIANGLES_FAN = 2;
    public static final int DRAW_MODE_TRIANGLES_STRIP = 1;
    public static final int POSITION_COORDS_PER_VERTEX = 3;
    public static final int TEXTURE_COORDS_PER_VERTEX = 2;
    public final Mesh leftMesh;
    public final Mesh rightMesh;
    public final boolean singleMesh;
    public final int stereoMode;

    @Target({ElementType.TYPE_USE})
    @Documented
    @Retention(RetentionPolicy.SOURCE)
    public @interface DrawMode {
    }

    public static final class Mesh {
        private final SubMesh[] subMeshes;

        public Mesh(SubMesh... subMeshArr) {
            this.subMeshes = subMeshArr;
        }

        public SubMesh getSubMesh(int i6) {
            return this.subMeshes[i6];
        }

        public int getSubMeshCount() {
            return this.subMeshes.length;
        }
    }

    public static final class SubMesh {
        public static final int VIDEO_TEXTURE_ID = 0;
        public final int mode;
        public final float[] textureCoords;
        public final int textureId;
        public final float[] vertices;

        public SubMesh(int i6, float[] fArr, float[] fArr2, int i7) {
            this.textureId = i6;
            Assertions.checkArgument(((long) fArr.length) * 2 == ((long) fArr2.length) * 3);
            this.vertices = fArr;
            this.textureCoords = fArr2;
            this.mode = i7;
        }

        public int getVertexCount() {
            return this.vertices.length / 3;
        }
    }

    public Projection(Mesh mesh, int i6) {
        this(mesh, mesh, i6);
    }

    public static Projection createEquirectangular(int i6) {
        return createEquirectangular(50.0f, 36, 72, 180.0f, 360.0f, i6);
    }

    public Projection(Mesh mesh, Mesh mesh2, int i6) {
        this.leftMesh = mesh;
        this.rightMesh = mesh2;
        this.stereoMode = i6;
        this.singleMesh = mesh == mesh2;
    }

    public static Projection createEquirectangular(float f6, int i6, int i7, float f7, float f8, int i8) {
        int i9 = i6;
        Assertions.checkArgument(f6 > 0.0f);
        Assertions.checkArgument(i9 >= 1);
        Assertions.checkArgument(i7 >= 1);
        Assertions.checkArgument(f7 > 0.0f && f7 <= 180.0f);
        Assertions.checkArgument(f8 > 0.0f && f8 <= 360.0f);
        float radians = (float) Math.toRadians(f7);
        float radians2 = (float) Math.toRadians(f8);
        float f9 = radians / i9;
        float f10 = radians2 / i7;
        int i10 = i7 + 1;
        int i11 = ((i10 * 2) + 2) * i9;
        float[] fArr = new float[i11 * 3];
        float[] fArr2 = new float[i11 * 2];
        int i12 = 0;
        int i13 = 0;
        int i14 = 0;
        while (i12 < i9) {
            float f11 = radians / 2.0f;
            float f12 = (i12 * f9) - f11;
            int i15 = i12 + 1;
            float f13 = (i15 * f9) - f11;
            int i16 = 0;
            while (i16 < i10) {
                float f14 = radians;
                float f15 = radians2;
                int i17 = 2;
                int i18 = 0;
                while (i18 < i17) {
                    float f16 = i18 == 0 ? f12 : f13;
                    float f17 = f9;
                    float f18 = i16 * f10;
                    float f19 = f10;
                    float f20 = f12;
                    double d6 = f6;
                    double d7 = (f18 + 3.1415927f) - (f15 / 2.0f);
                    double dSin = Math.sin(d7) * d6;
                    double d8 = f16;
                    fArr[i13] = -((float) (Math.cos(d8) * dSin));
                    fArr[i13 + 1] = (float) (Math.sin(d8) * d6);
                    int i19 = i13 + 3;
                    fArr[i13 + 2] = (float) (Math.cos(d7) * d6 * Math.cos(d8));
                    fArr2[i14] = f18 / f15;
                    int i20 = i14 + 2;
                    fArr2[i14 + 1] = ((i12 + i18) * f17) / f14;
                    if ((i16 == 0 && i18 == 0) || (i16 == i7 && i18 == 1)) {
                        System.arraycopy(fArr, i13, fArr, i19, 3);
                        i13 += 6;
                        i17 = 2;
                        System.arraycopy(fArr2, i14, fArr2, i20, 2);
                        i14 += 4;
                    } else {
                        i17 = 2;
                        i13 = i19;
                        i14 = i20;
                    }
                    i18++;
                    f9 = f17;
                    f10 = f19;
                    f12 = f20;
                }
                i16++;
                radians2 = f15;
                radians = f14;
            }
            i9 = i6;
            i12 = i15;
        }
        return new Projection(new Mesh(new SubMesh(0, fArr, fArr2, 1)), i8);
    }
}
