cleaning up code

This commit is contained in:
Halbear
2026-06-02 02:56:57 +01:00
parent 9f624c3b80
commit 810e74ab73
2 changed files with 31 additions and 52 deletions
@@ -25,9 +25,10 @@ import net.minecraft.util.math.vector.*;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
import javax.annotation.Nonnull;
import java.util.*; import java.util.*;
import static net.halbear.hvf.Util.Math.CommonFunctions.RotateIn3dSpaceFromOrigin; import static net.halbear.hvf.Util.Math.CommonFunctions.getRotationMatrix4f;
public class VehicleBaseEntity extends Entity { public class VehicleBaseEntity extends Entity {
@@ -400,31 +401,7 @@ public class VehicleBaseEntity extends Entity {
float pitchRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_PITCH")); float pitchRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_PITCH"));
float rollRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_ROLL")); float rollRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_ROLL"));
float CosYaw = (float)Math.cos(yawRad); Matrix4f TransformationMatrix = getRotationMatrix4f(yawRad, pitchRad, rollRad);
float SinYaw = (float)Math.sin(yawRad);
float CosPitch = (float)Math.cos(pitchRad);
float SinPitch = (float)Math.sin(pitchRad);
float CosRoll = (float)Math.cos(rollRad);
float SinRoll = (float)Math.sin(rollRad);
float m00 = CosYaw * CosRoll + SinYaw * SinPitch * SinRoll;
float m01 = -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll;
float m02 = SinYaw * CosPitch;
float m10 = SinRoll * CosPitch;
float m11 = CosRoll * CosPitch;
float m12 = -SinPitch;
float m20 = -SinYaw * CosRoll + CosYaw * SinPitch * SinRoll;
float m21 = SinYaw * SinRoll + CosYaw * SinPitch * CosRoll;
float m22 = CosYaw * CosPitch;
Matrix4f TransformationMatrix = new Matrix4f(new float[]{
m00,m01,m02,0f,
m10,m11,m12,0f,
m20,m21,m22,0f,
0f,0f,0f,1f
});
Vector4f SeatPosition = new Vector4f( Vector4f SeatPosition = new Vector4f(
(float) (localOffset.x + OriginPosition.x), (float) (localOffset.x + OriginPosition.x),
@@ -444,4 +421,5 @@ public class VehicleBaseEntity extends Entity {
} }
} }
} }
} }
@@ -1,37 +1,38 @@
package net.halbear.hvf.Util.Math; package net.halbear.hvf.Util.Math;
import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d; import javax.annotation.Nonnull;
import net.minecraft.util.math.vector.Vector3f;
public class CommonFunctions { public class CommonFunctions {
public static Vector3d RotateIn3dSpaceFromOrigin(Vector3d Point, Vector3d Origin, double YawRad, double PitchRad, double RollRad){ @Nonnull
Vector3d relativeOffset = Point.subtract(Origin); public static Matrix4f getRotationMatrix4f(float yawRad, float pitchRad, float rollRad) {
float CosYaw = (float)Math.cos(yawRad);
float SinYaw = (float)Math.sin(yawRad);
float CosPitch = (float)Math.cos(pitchRad);
float SinPitch = (float)Math.sin(pitchRad);
float CosRoll = (float)Math.cos(rollRad);
float SinRoll = (float)Math.sin(rollRad);
double CosYaw = Math.cos(YawRad); float m00 = CosYaw * CosRoll + SinYaw * SinPitch * SinRoll;
double SinYaw = Math.sin(YawRad); float m01 = -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll;
double CosPitch = Math.cos(PitchRad); float m02 = SinYaw * CosPitch;
double SinPitch = Math.sin(PitchRad);
double CosRoll = Math.cos(RollRad);
double SinRoll = Math.sin(RollRad);
Vector3d Forward = new Vector3d(SinYaw * CosPitch, -SinPitch, CosYaw * CosPitch); float m10 = SinRoll * CosPitch;
float m11 = CosRoll * CosPitch;
float m12 = -SinPitch;
Vector3d Up = new Vector3d( float m20 = -SinYaw * CosRoll + CosYaw * SinPitch * SinRoll;
-CosYaw * SinRoll + SinYaw * SinPitch * CosRoll, float m21 = SinYaw * SinRoll + CosYaw * SinPitch * CosRoll;
CosPitch * CosRoll, float m22 = CosYaw * CosPitch;
SinYaw * SinRoll + CosYaw * SinPitch * CosRoll
);
Vector3d Right = new Vector3d(Forward.x,Forward.y,Forward.z); Matrix4f TransformationMatrix = new Matrix4f(new float[]{
Right.crossProduct(Up); m00,m01,m02,0f,
m10,m11,m12,0f,
Vector3d Rotated = new Vector3d( m20,m21,m22,0f,
(Right.getX() * relativeOffset.x) + (Up.getX() * relativeOffset.y) + (Forward.getX() * relativeOffset.z), 0f,0f,0f,1f
(Right.getY() * relativeOffset.x) + (Up.getY() * relativeOffset.y) + (Forward.getY() * relativeOffset.z), });
(Right.getZ() * relativeOffset.x) + (Up.getZ() * relativeOffset.y) + (Forward.getZ() * relativeOffset.z)); return TransformationMatrix;
return Rotated.add(Origin);
} }
} }