Skip to content

Commit

Permalink
Fix quaternion
Browse files Browse the repository at this point in the history
  • Loading branch information
maximumpower55 committed Nov 8, 2023
1 parent 799e4c5 commit 469d8b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.core.Direction;
import net.minecraft.core.FrontAndTop;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.Shapes;
Expand Down Expand Up @@ -54,29 +55,27 @@ public Portal(int netId, Vec3 origin, FrontAndTop orientation, PortalShape shape
this.linked = null;
this.linkedOptional = Optional.empty();

this.rotation = orientation.top().getRotation();
// Direction front = orientation.front();
// if (front == Direction.DOWN) {
// rotation.rotateZ(Mth.DEG_TO_RAD * 180);
// } else if (front.getAxis().isHorizontal()) {
// rotation.rotateX(Mth.DEG_TO_RAD * 90);
// float yRot = switch (front) {
// case NORTH -> 180;
// case EAST -> 90;
// case WEST -> 270;
// default -> 0;
// };
// rotation.rotateY(Mth.DEG_TO_RAD * yRot);
// }
// if (front.getAxis().isVertical()) {
// float yRot = switch (orientation.top()) {
// case NORTH -> 180;
// case EAST -> 90;
// case WEST -> 270;
// default -> 0;
// };
// rotation.rotateY(Mth.DEG_TO_RAD * yRot);
// }
var topDirection = orientation.top();
var frontDirection = orientation.front();
float topAngle = 0;
if (frontDirection.getAxis().isVertical()) {
topDirection = (frontDirection == Direction.DOWN && topDirection.getAxis() == Direction.Axis.Z) ? topDirection.getOpposite() : topDirection;
topAngle = switch (topDirection) {
case NORTH -> Mth.DEG_TO_RAD * 180;
case WEST -> Mth.DEG_TO_RAD * 90;
case EAST -> Mth.DEG_TO_RAD * -90;
default -> 0;
};
}
var rotation = switch (frontDirection) {
case DOWN -> new Quaternionf().rotationXYZ(Mth.DEG_TO_RAD * 270, 0, topAngle);
case UP -> new Quaternionf().rotationXYZ(Mth.DEG_TO_RAD * -270, 0, topAngle);
case SOUTH -> new Quaternionf().rotationY(Mth.DEG_TO_RAD * 180);
case WEST -> new Quaternionf().rotationY(Mth.DEG_TO_RAD * 90);
case EAST -> new Quaternionf().rotationY(Mth.DEG_TO_RAD * -90);
default -> new Quaternionf();
};
this.rotation = rotation;

Direction.Axis frontAxis = orientation.front().getAxis();
Direction.Axis verticalAxis = orientation.top().getAxis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,7 @@ private static void renderPortal(Portal portal, PoseStack matrices, MultiBufferS
matrices.translate(portal.origin.x, portal.origin.y, portal.origin.z);
// apply rotations
matrices.mulPose(portal.rotation); // rotate towards facing direction
// if (front.getAxis().isVertical()) {
// // for floor / ceiling portals, rotate towards top
// float rotation = portal.orientation.top().toYRot();
// if (front == Direction.UP) {
// // I don't know! This is needed because of some weirdness that I've debugged for too long across too many projects.
// rotation = -rotation + 180;
// }
// matrices.mulPose(Axis.YP.rotationDegrees(rotation));
// }
matrices.mulPose(Axis.ZP.rotationDegrees(180));
// slight offset so origin is center of portal
matrices.translate(-0.5f, -1, 0);
// scale quad - 32x32 texture, half is used. scale the 1x1 to a 2x2.
Expand Down

0 comments on commit 469d8b9

Please sign in to comment.