package com.seewo.factoryaging.opengl3d.h;

import android.opengl.Matrix;
import android.util.Log;

/* JADX INFO: compiled from: Camera.java */
/* JADX INFO: loaded from: classes.dex */
public class e {
    public float a;
    public float b;
    public float c;
    public float d;
    public float e;
    public float f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float f335g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public float f336h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public float f337i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final d f338j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private final d f339k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private float[] f340l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private long f341m;
    private Object[] n;
    private boolean o;

    public e() {
        this(0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    }

    private void a(float f) {
        if (Float.isNaN(f)) {
            Log.w("Rot", "NaN");
            return;
        }
        float f2 = this.d - this.a;
        float f3 = this.e - this.b;
        float f4 = this.f - this.c;
        float length = Matrix.length(f2, f3, f4);
        c(this.f340l, 24, f, f2 / length, f3 / length, f4 / length);
        float[] fArr = {this.a, this.b, this.c, 1.0f, this.d, this.e, this.f, 1.0f, this.f335g, this.f336h, this.f337i, 1.0f};
        float[] fArr2 = this.f340l;
        f(fArr2, 0, fArr2, 24, fArr, 0);
        float[] fArr3 = this.f340l;
        this.a = fArr3[0];
        this.b = fArr3[1];
        this.c = fArr3[2];
        this.d = fArr3[4];
        this.e = fArr3[5];
        this.f = fArr3[6];
        this.f335g = fArr3[8];
        this.f336h = fArr3[9];
        this.f337i = fArr3[10];
        g(true);
    }

    private static void c(float[] fArr, int i2, float f, float f2, float f3, float f4) {
        double d = f;
        float fCos = (float) Math.cos(d);
        float fSin = (float) Math.sin(d);
        float f5 = 1.0f - fCos;
        float f6 = f5 * f2;
        fArr[i2] = (f6 * f2) + fCos;
        float f7 = f6 * f3;
        float f8 = f4 * fSin;
        fArr[i2 + 1] = f7 - f8;
        float f9 = f5 * f4;
        float f10 = f9 * f2;
        float f11 = f3 * fSin;
        fArr[i2 + 2] = f10 + f11;
        fArr[i2 + 3] = 0.0f;
        fArr[i2 + 4] = f7 + f8;
        float f12 = f5 * f3;
        fArr[i2 + 5] = (f3 * f12) + fCos;
        float f13 = f12 * f4;
        float f14 = f2 * fSin;
        fArr[i2 + 6] = f13 - f14;
        fArr[i2 + 7] = 0.0f;
        fArr[i2 + 8] = f10 - f11;
        fArr[i2 + 9] = f13 + f14;
        fArr[i2 + 10] = (f9 * f4) + fCos;
        fArr[i2 + 11] = 0.0f;
        fArr[i2 + 12] = 0.0f;
        fArr[i2 + 13] = 0.0f;
        fArr[i2 + 14] = 0.0f;
        fArr[i2 + 15] = 1.0f;
    }

    private boolean e(float f, float f2, float f3) {
        if (this.f339k.g(f, f2, f3)) {
            Log.i("Camera", "Out of room walls");
            return true;
        }
        if (this.f338j.g(f, f2, f3)) {
            return false;
        }
        Log.i("Camera", "Inside absolute center");
        return true;
    }

    private static void f(float[] fArr, int i2, float[] fArr2, int i3, float[] fArr3, int i4) {
        for (int i5 = 0; i5 < fArr3.length / 4; i5++) {
            int i6 = i5 * 4;
            Matrix.multiplyMV(fArr, i2 + i6, fArr2, i3, fArr3, i4 + i6);
        }
    }

    private void j(float f, float f2) {
        float f3 = this.d - this.a;
        float f4 = this.e - this.b;
        float f5 = this.f - this.c;
        float length = Matrix.length(f3, f4, f5);
        float f6 = f3 / length;
        float f7 = f4 / length;
        float f8 = f5 / length;
        float f9 = this.f335g - this.a;
        float f10 = this.f336h - this.b;
        float f11 = this.f337i - this.c;
        float length2 = Matrix.length(f9, f10, f11);
        float f12 = f9 / length2;
        float f13 = f10 / length2;
        float f14 = f11 / length2;
        float f15 = (f7 * f14) - (f8 * f13);
        float f16 = (f8 * f12) - (f14 * f6);
        float f17 = (f13 * f6) - (f12 * f7);
        float length3 = Matrix.length(f15, f16, f17);
        float f18 = f15 / length3;
        float f19 = f16 / length3;
        float f20 = f17 / length3;
        float f21 = (f19 * f8) - (f20 * f7);
        float f22 = (f20 * f6) - (f8 * f18);
        float f23 = (f7 * f18) - (f6 * f19);
        float length4 = Matrix.length(f21, f22, f23);
        float f24 = f21 / length4;
        float f25 = f22 / length4;
        float f26 = f23 / length4;
        float[] fArr = {this.a, this.b, this.c, 1.0f, this.d, this.e, this.f, 1.0f, this.f335g, this.f336h, this.f337i, 1.0f};
        if (f != 0.0f && f2 != 0.0f) {
            float f27 = (f18 * f2) + (f24 * f);
            float f28 = (f19 * f2) + (f25 * f);
            float f29 = (f20 * f2) + (f26 * f);
            float length5 = Matrix.length(f27, f28, f29);
            c(this.f340l, 24, length5, f27 / length5, f28 / length5, f29 / length5);
        } else if (f != 0.0f) {
            c(this.f340l, 24, f, f24, f25, f26);
        } else {
            c(this.f340l, 24, f2, f18, f19, f20);
        }
        float[] fArr2 = this.f340l;
        f(fArr2, 0, fArr2, 24, fArr, 0);
        float[] fArr3 = this.f340l;
        if (e(fArr3[0], fArr3[1], fArr3[2])) {
            return;
        }
        float[] fArr4 = this.f340l;
        this.a = fArr4[0] / fArr4[3];
        this.b = fArr4[1] / fArr4[3];
        this.c = fArr4[2] / fArr4[3];
        this.d = fArr4[4] / fArr4[7];
        this.e = fArr4[5] / fArr4[7];
        this.f = fArr4[6] / fArr4[7];
        this.f335g = fArr4[8] / fArr4[11];
        this.f336h = fArr4[9] / fArr4[11];
        this.f337i = fArr4[10] / fArr4[11];
        g(true);
    }

    public synchronized void b() {
        if (this.n != null && this.f341m != 0) {
            String str = (String) this.n[0];
            if (str.equals("translate")) {
                j((((Float) this.n[1]).floatValue() * this.f341m) / 100.0f, (((Float) this.n[2]).floatValue() * this.f341m) / 100.0f);
            } else if (str.equals("rotate")) {
                a((((Float) this.n[1]).floatValue() / 100.0f) * this.f341m);
            }
            this.f341m--;
            return;
        }
        this.n = null;
        this.f341m = 100L;
    }

    public boolean d() {
        return this.o;
    }

    public void g(boolean z) {
        this.o = z;
    }

    public e[] h(float f) {
        float[] fArrD = com.seewo.factoryaging.opengl3d.k.d.d(this.d - this.a, this.e - this.b, this.f - this.c, this.f335g, this.f336h, this.f337i);
        com.seewo.factoryaging.opengl3d.k.d.e(fArrD);
        float f2 = this.a;
        float f3 = f2 - ((fArrD[0] * f) / 2.0f);
        float f4 = this.b;
        float f5 = f4 - ((fArrD[1] * f) / 2.0f);
        float f6 = this.c;
        float f7 = f6 - ((fArrD[2] * f) / 2.0f);
        float f8 = this.d;
        float f9 = fArrD[0];
        float f10 = this.e;
        float f11 = fArrD[1];
        float f12 = this.f;
        float f13 = fArrD[2];
        float f14 = f2 + ((fArrD[0] * f) / 2.0f);
        float f15 = f4 + ((fArrD[1] * f) / 2.0f);
        float f16 = f6 + ((fArrD[2] * f) / 2.0f);
        float f17 = fArrD[0];
        float f18 = fArrD[1];
        float f19 = fArrD[2];
        return new e[]{new e(f3, f5, f7, f8, f10, f12, this.f335g, this.f336h, this.f337i), new e(f14, f15, f16, f8, f10, f12, this.f335g, this.f336h, this.f337i)};
    }

    public synchronized void i(float f, float f2) {
        if (f == 0.0f && f2 == 0.0f) {
            return;
        }
        j(f, f2);
        this.n = new Object[]{"translate", Float.valueOf(f), Float.valueOf(f2)};
    }

    public String toString() {
        return "Camera [xPos=" + this.a + ", yPos=" + this.b + ", zPos=" + this.c + ", xView=" + this.d + ", yView=" + this.e + ", zView=" + this.f + ", xUp=" + this.f335g + ", yUp=" + this.f336h + ", zUp=" + this.f337i + "]";
    }

    public e(float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9) {
        this.f338j = new d("scene", -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f);
        this.f339k = new d("scene", -30.0f, 30.0f, -30.0f, 30.0f, -30.0f, 30.0f);
        this.f340l = new float[56];
        this.o = false;
        this.a = f;
        this.b = f2;
        this.c = f3;
        this.d = f4;
        this.e = f5;
        this.f = f6;
        this.f335g = f7;
        this.f336h = f8;
        this.f337i = f9;
    }
}
