All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.impl.compat.mojang.math.QuaternionCompatImpl Maven / Gradle / Ivy

There is a newer version: 0.6.59
Show newest version
package top.hendrixshen.magiclib.impl.compat.mojang.math;

import org.joml.Quaternionf;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.api.compat.AbstractCompat;
import top.hendrixshen.magiclib.api.compat.mojang.math.QuaternionCompat;

//#if MC < 11500
//$$ import net.minecraft.util.Mth;
//$$ import top.hendrixshen.magiclib.mixin.minecraft.accessor.QuaternionAccessor;
//$$ import top.hendrixshen.magiclib.util.MiscUtil;
//#endif

@Environment(EnvType.CLIENT)
public class QuaternionCompatImpl extends AbstractCompat implements QuaternionCompat {
    public QuaternionCompatImpl(@NotNull Quaternionf type) {
        super(type);
    }

    @Override
    public void mul(float f) {
        //#if MC > 11404
        this.get().mul(f);
        //#else
        //$$ float[] v = ((QuaternionAccessor) MiscUtil.cast(this.get())).magiclib$getValues();
        //$$ v[0] *= f;
        //$$ v[1] *= f;
        //$$ v[2] *= f;
        //$$ v[3] *= f;
        //#endif
    }

    public void normalize() {
        //#if MC > 11404
        this.get().normalize();
        //#else
        //$$ Quaternion quaternion = this.get();
        //$$ float k = quaternion.i() * quaternion.i() + quaternion.j() * quaternion.j() +
        //$$         quaternion.k() * quaternion.k() + quaternion.r() * quaternion.r();
        //$$
        //$$ if (k > 1.0E-6F) {
        //$$     this.mul((float) Mth.fastInvSqrt(k));
        //$$ } else {
        //$$     this.mul(0.0F);
        //$$ }
        //#endif
    }

    public QuaternionCompat copy() {
        return QuaternionCompat.of(
                //#if MC > 11902
                new Quaternionf(this.get())
                //#elseif MC > 11404
                //$$ this.get().copy()
                //#else
                //$$ new Quaternion(this.get())
                //#endif
        );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy