|
1 | 1 | package com.zigythebird.bendable_cuboids.impl; |
2 | 2 |
|
3 | 3 | import com.mojang.blaze3d.vertex.PoseStack; |
| 4 | +import com.mojang.math.Axis; |
4 | 5 | import com.zigythebird.bendable_cuboids.impl.compatibility.PlayerBendHelper; |
5 | 6 | import net.minecraft.client.model.HumanoidModel; |
6 | 7 | import net.minecraft.client.model.PlayerModel; |
|
10 | 11 | import java.lang.Math; |
11 | 12 |
|
12 | 13 | public class BendUtil { |
13 | | - public static BendApplier getBend(BendableCuboid cuboid, float bendAxis, float bendValue) { |
14 | | - return getBend(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(), |
15 | | - cuboid.basePlane, cuboid.otherPlane, false, cuboid.bendHeight(), bendAxis, bendValue); |
| 14 | + private static final Vector3f Z_AXIS = new Vector3f(0, 0, 1); |
| 15 | + |
| 16 | + public static BendApplier getBend(BendableCuboid cuboid, float bendValue) { |
| 17 | + return getBend(cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(), |
| 18 | + cuboid.basePlane, cuboid.otherPlane, false, cuboid.bendHeight(), bendValue); |
16 | 19 | } |
17 | 20 |
|
18 | 21 | /** |
19 | 22 | * Applies the transformation to every position in posSupplier |
20 | | - * @param bendAxis axis for the bend |
21 | 23 | * @param bendValue bend value |
22 | 24 | */ |
23 | | - public static BendApplier getBend(Direction bendDirection, float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane, |
24 | | - boolean mirrorBend, float bendHeight, float bendAxis, float bendValue) { |
25 | | - Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis)); |
26 | | - Matrix3f matrix3f = new Matrix3f().set(bendDirection.getRotation()); |
27 | | - axis.mul(matrix3f); |
| 25 | + public static BendApplier getBend(float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane, |
| 26 | + boolean mirrorBend, float bendHeight, float bendValue) { |
28 | 27 | if (mirrorBend) bendValue *= -1; |
29 | 28 | final float finalBend = bendValue; |
30 | | - Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendAxis, bendValue); |
| 29 | + Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendValue); |
31 | 30 |
|
32 | 31 | float halfSize = bendHeight/2; |
33 | 32 |
|
@@ -55,29 +54,25 @@ else if (distFromBase + distFromOther <= bendHeight && distFromOther > v) { |
55 | 54 | }); |
56 | 55 | } |
57 | 56 |
|
58 | | - public static BendApplier getBendLegacy(BendableCuboid cuboid, float bendAxis, float bendValue) { |
| 57 | + public static BendApplier getBendLegacy(BendableCuboid cuboid, float bendValue) { |
59 | 58 | return getBendLegacy(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(), |
60 | | - cuboid.basePlane, cuboid.otherPlane, cuboid.isBendInverted(), false, cuboid.bendHeight(), bendAxis, bendValue); |
| 59 | + cuboid.basePlane, cuboid.otherPlane, cuboid.isBendInverted(), false, cuboid.bendHeight(), bendValue); |
61 | 60 | } |
62 | 61 |
|
63 | 62 | /** |
64 | 63 | * Bends in the old pre-1.21.6 way which is more stretchy, but works in more situations, like for GeckoLib armor. |
65 | | - * @param bendAxis axis for the bend |
66 | 64 | * @param bendValue bend value |
67 | 65 | */ |
68 | 66 | public static BendApplier getBendLegacy(Direction bendDirection, float bendX, float bendY, float bendZ, Plane basePlane, Plane otherPlane, |
69 | | - boolean isBendInverted, boolean mirrorBend, float bendHeight, float bendAxis, float bendValue) { |
70 | | - Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis)); |
71 | | - Matrix3f matrix3f = new Matrix3f().set(bendDirection.getRotation()); |
72 | | - axis.mul(matrix3f); |
| 67 | + boolean isBendInverted, boolean mirrorBend, float bendHeight, float bendValue) { |
73 | 68 | if (mirrorBend) bendValue *= -1; |
74 | 69 | final float finalBend = bendValue; |
75 | | - Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendAxis, bendValue); |
| 70 | + Matrix4f transformMatrix = applyBendToMatrix(new Matrix4f(), bendX, bendY, bendZ, bendValue); |
76 | 71 |
|
77 | 72 | Vector3f directionUnit; |
78 | 73 |
|
79 | 74 | directionUnit = bendDirection.step(); |
80 | | - directionUnit.cross(axis); |
| 75 | + directionUnit.cross(Z_AXIS); |
81 | 76 | //parallel to the bend's axis and to the cube's bend direction |
82 | 77 | Plane bendPlane = new Plane(directionUnit, new Vector3f(bendX, bendY, bendZ)); |
83 | 78 | float halfSize = bendHeight/2; |
@@ -112,21 +107,17 @@ else if (isInBendArea) { |
112 | 107 | }); |
113 | 108 | } |
114 | 109 |
|
115 | | - public static Matrix4f applyBendToMatrix(Matrix4f transformMatrix, float bendX, float bendY, float bendZ, float bendAxis, float bendValue) { |
116 | | - Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis)); |
117 | | - |
| 110 | + public static Matrix4f applyBendToMatrix(Matrix4f transformMatrix, float bendX, float bendY, float bendZ, float bendValue) { |
118 | 111 | transformMatrix.translate(bendX, bendY, bendZ); |
119 | | - transformMatrix.rotate(bendValue, axis); |
| 112 | + transformMatrix.rotateX(bendValue); |
120 | 113 | transformMatrix.translate(-bendX, -bendY, -bendZ); |
121 | 114 |
|
122 | 115 | return transformMatrix; |
123 | 116 | } |
124 | 117 |
|
125 | | - public static PoseStack applyBendToMatrix(PoseStack transformMatrix, float bendX, float bendY, float bendZ, float bendAxis, float bendValue) { |
126 | | - Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis)); |
127 | | - |
| 118 | + public static PoseStack applyBendToMatrix(PoseStack transformMatrix, float bendX, float bendY, float bendZ, float bendValue) { |
128 | 119 | transformMatrix.translate(bendX, bendY, bendZ); |
129 | | - transformMatrix.mulPose(new Quaternionf().rotateAxis(bendValue, axis)); |
| 120 | + transformMatrix.mulPose(Axis.XP.rotation(bendValue)); |
130 | 121 | transformMatrix.translate(-bendX, -bendY, -bendZ); |
131 | 122 |
|
132 | 123 | return transformMatrix; |
|
0 commit comments