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

com.parzivail.util.client.CameraUtil Maven / Gradle / Ivy

There is a newer version: 0.0.114+1.20.2
Show newest version
package com.parzivail.util.client;

import net.minecraft.class_243;
import net.minecraft.class_310;
import net.minecraft.class_3532;
import net.minecraft.class_4184;
import net.minecraft.class_4587;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.joml.Vector4f;

public class CameraUtil
{
	public static PositionNormal3f unproject(class_4587 matrices, Vector3f normal)
	{
		var worldPos = new Vector4f(0, 0, 0, 1);

		matrices.method_23760().method_23761().transform(worldPos);
		var worldNormal = matrices.method_23760().method_23762().transform(normal);
		worldPos.mul(1, -1, 1, 1);
		worldNormal.mul(1, -1, 1);

		// TODO: incorporate projection matrix to fix first-person FOV issues
		// TODO: why doesn't RenderSystem.getInverseViewRotationMatrix() work instead of manually removing rotation?

		var cam = class_310.method_1551().field_1773.method_19418();

		var camPos = cam.method_19326();
		var pitch = new Quaternionf().rotateX(cam.method_19329() * class_3532.field_29847);
		var yaw = new Quaternionf().rotateY(-cam.method_19330() * class_3532.field_29847);

		pitch.transform(worldPos);
		yaw.transform(worldPos);

		pitch.transform(worldNormal);
		yaw.transform(worldNormal);

		return new PositionNormal3f(new Vector3f(camPos.method_46409()).sub(worldPos.x, worldPos.y, worldPos.z), worldNormal);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy