diff --git a/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java b/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java index e690754..43e9bd3 100644 --- a/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java +++ b/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java @@ -25,9 +25,10 @@ import net.minecraft.util.math.vector.*; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; +import javax.annotation.Nonnull; 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 { @@ -400,31 +401,7 @@ public class VehicleBaseEntity extends Entity { float pitchRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_PITCH")); float rollRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_ROLL")); - 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); - - 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 - }); + Matrix4f TransformationMatrix = getRotationMatrix4f(yawRad, pitchRad, rollRad); Vector4f SeatPosition = new Vector4f( (float) (localOffset.x + OriginPosition.x), @@ -444,4 +421,5 @@ public class VehicleBaseEntity extends Entity { } } } + } diff --git a/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java b/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java index c29eabe..e804528 100644 --- a/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java +++ b/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java @@ -1,37 +1,38 @@ package net.halbear.hvf.Util.Math; -import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.util.math.vector.Matrix4f; + +import javax.annotation.Nonnull; public class CommonFunctions { - public static Vector3d RotateIn3dSpaceFromOrigin(Vector3d Point, Vector3d Origin, double YawRad, double PitchRad, double RollRad){ - Vector3d relativeOffset = Point.subtract(Origin); + @Nonnull + 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); - double SinYaw = Math.sin(YawRad); - double CosPitch = Math.cos(PitchRad); - double SinPitch = Math.sin(PitchRad); - double CosRoll = Math.cos(RollRad); - double SinRoll = Math.sin(RollRad); + float m00 = CosYaw * CosRoll + SinYaw * SinPitch * SinRoll; + float m01 = -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll; + float m02 = SinYaw * CosPitch; - Vector3d Forward = new Vector3d(SinYaw * CosPitch, -SinPitch, CosYaw * CosPitch); + float m10 = SinRoll * CosPitch; + float m11 = CosRoll * CosPitch; + float m12 = -SinPitch; - Vector3d Up = new Vector3d( - -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll, - CosPitch * CosRoll, - SinYaw * SinRoll + CosYaw * SinPitch * CosRoll - ); + float m20 = -SinYaw * CosRoll + CosYaw * SinPitch * SinRoll; + float m21 = SinYaw * SinRoll + CosYaw * SinPitch * CosRoll; + float m22 = CosYaw * CosPitch; - Vector3d Right = new Vector3d(Forward.x,Forward.y,Forward.z); - Right.crossProduct(Up); - - Vector3d Rotated = new Vector3d( - (Right.getX() * relativeOffset.x) + (Up.getX() * relativeOffset.y) + (Forward.getX() * relativeOffset.z), - (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 Rotated.add(Origin); + Matrix4f TransformationMatrix = new Matrix4f(new float[]{ + m00,m01,m02,0f, + m10,m11,m12,0f, + m20,m21,m22,0f, + 0f,0f,0f,1f + }); + return TransformationMatrix; } }