mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
39 lines
946 B
Java
39 lines
946 B
Java
package com.hbm.util;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
public class BobMathUtil {
|
|
|
|
public static double getAngleFrom2DVecs(double x1, double z1, double x2, double z2) {
|
|
|
|
double upper = x1 * x2 + z1 * z2;
|
|
double lower = Math.sqrt(x1 * x1 + z1 * z1) * Math.sqrt(x2 * x2 + z2 * z2);
|
|
|
|
double result = Math.toDegrees(Math.cos(upper / lower));
|
|
|
|
if(result >= 180)
|
|
result -= 180;
|
|
|
|
return result;
|
|
}
|
|
|
|
public static double getCrossAngle(Vec3 vel, Vec3 rel) {
|
|
|
|
vel.normalize();
|
|
rel.normalize();
|
|
|
|
double vecProd = rel.xCoord * vel.xCoord + rel.yCoord * vel.yCoord + rel.zCoord * vel.zCoord;
|
|
double bot = rel.lengthVector() * vel.lengthVector();
|
|
double angle = Math.acos(vecProd / bot) * 180 / Math.PI;
|
|
|
|
if(angle >= 180)
|
|
angle -= 180;
|
|
|
|
return angle;
|
|
}
|
|
|
|
public static float remap(float num, float min1, float max1, float min2, float max2){
|
|
return ((num - min1) / (max1 - min1)) * (max2 - min2) + min2;
|
|
}
|
|
}
|