Skip to content

Commit

Permalink
Fixed Radial Menu rendering and angle issues. Thanks for @lclc98 for …
Browse files Browse the repository at this point in the history
…the help
  • Loading branch information
GirafiStudios committed Jul 27, 2021
1 parent 9f93136 commit 5e0d6a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
55 changes: 28 additions & 27 deletions src/main/java/dmillerw/menu/handler/ClientTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,16 @@ private static void renderButtonBackgrounds() {
Minecraft mc = Minecraft.getInstance();
PoseStack poseStack = RenderSystem.getModelViewStack();
poseStack.pushPose();

RenderSystem.disableTexture();

RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

RenderSystem.applyModelViewMatrix();
poseStack.pushPose();
poseStack.setIdentity();

poseStack.translate(mc.getWindow().getGuiScaledWidth() * 0.5D, mc.getWindow().getGuiScaledHeight() * 0.5D, 0);
RenderSystem.applyModelViewMatrix();
poseStack.pushPose();
poseStack.setIdentity();

RenderSystem.setShader(GameRenderer::getPositionColorShader);
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuilder();
RenderSystem.enableBlend();
RenderSystem.disableTexture();
RenderSystem.defaultBlendFunc();
RenderSystem.disableCull();

double mouseAngle = AngleHelper.getMouseAngle();
mouseAngle -= (ANGLE_PER_ITEM / 2);
Expand All @@ -111,8 +105,8 @@ private static void renderButtonBackgrounds() {
currAngle = Math.toRadians(currAngle);
nextAngle = Math.toRadians(nextAngle);

double innerRadius = ((INNER_RADIUS - RadialMenu.animationTimer - (mouseIn ? 2 : 0)) / 100F) * (257F / (float) mc.getWindow().getGuiScaledHeight());
double outerRadius = ((OUTER_RADIUS - RadialMenu.animationTimer + (mouseIn ? 2 : 0)) / 100F) * (257F / (float) mc.getWindow().getGuiScaledHeight());
double innerRadius = ((INNER_RADIUS - RadialMenu.animationTimer - (mouseIn ? 2 : 0)) / 100F) * (130F);
double outerRadius = ((OUTER_RADIUS - RadialMenu.animationTimer + (mouseIn ? 2 : 0)) / 100F) * (130F);

bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);

Expand All @@ -130,22 +124,29 @@ private static void renderButtonBackgrounds() {
alpha = (float) ConfigHandler.VISUAL.menuAlpha.get() / (float) 255;
}

bufferBuilder.vertex(Math.cos(currAngle) * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getGuiScaledWidth() * innerRadius, Math.sin(currAngle) * innerRadius, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(Math.cos(currAngle) * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getGuiScaledWidth() * outerRadius, Math.sin(currAngle) * outerRadius, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(Math.cos(nextAngle) * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getGuiScaledWidth() * outerRadius, Math.sin(nextAngle) * outerRadius, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(Math.cos(nextAngle) * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getGuiScaledWidth() * innerRadius, Math.sin(nextAngle) * innerRadius, 0).color(r, g, b, alpha).endVertex();
double x1 = Math.cos(currAngle) * innerRadius;
double x2 = Math.cos(currAngle) * outerRadius;
double x3 = Math.cos(nextAngle) * outerRadius;
double x4 = Math.cos(nextAngle) * innerRadius;

tessellator.end();
}
double y1 = Math.sin(currAngle) * innerRadius;
double y2 = Math.sin(currAngle) * outerRadius;
double y3 = Math.sin(nextAngle) * outerRadius;
double y4 = Math.sin(nextAngle) * innerRadius;

poseStack.popPose();
RenderSystem.applyModelViewMatrix();
poseStack.popPose();
bufferBuilder.vertex(x1, y1, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(x2, y2, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(x3, y3, 0).color(r, g, b, alpha).endVertex();
bufferBuilder.vertex(x4, y4, 0).color(r, g, b, alpha).endVertex();

tessellator.end();
}
RenderSystem.enableCull();
RenderSystem.disableBlend();
RenderSystem.enableTexture();

poseStack.popPose();
RenderSystem.applyModelViewMatrix();
}

private static void renderItems() {
Expand All @@ -159,17 +160,17 @@ private static void renderItems() {
Item menuButton = ForgeRegistries.ITEMS.getValue(new ResourceLocation(ConfigHandler.GENERAL.menuButtonIcon.get().toString()));
ItemStack stack = (item != null && !item.icon.isEmpty()) ? item.icon : (menuButton == null ? ItemStack.EMPTY : new ItemStack(menuButton));

double angle = (ANGLE_PER_ITEM * i) - (90);
double angle = (ANGLE_PER_ITEM * i);
double drawOffset = 1.5;
double drawX = INNER_RADIUS - RadialMenu.animationTimer + drawOffset;
double drawY = INNER_RADIUS - RadialMenu.animationTimer + drawOffset;

double length = Math.sqrt(drawX * drawX + drawY * drawY);

drawX = (length * Math.cos(StrictMath.toRadians(angle)));
drawY = (length * Math.sin(StrictMath.toRadians(angle)));
drawX = (length * Math.cos(Math.toRadians(angle)));
drawY = (length * Math.sin(Math.toRadians(angle)));

ItemRenderHelper.renderItem((int) drawX, (int) drawY, stack);
ItemRenderHelper.renderItem((int) drawY, (int) drawX, stack);
}

poseStack.popPose();
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/dmillerw/menu/helper/AngleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public static double getMouseAngle() {
}

private static double getRelativeAngle(double originX, double originY, double x, double y) {
double angle = Math.toDegrees(Math.atan2(x - originX, y - originY));

// Remove 90 from the angle to make 0 and 180 at the top and bottom of the screen
angle -= 180;
double angle = -Math.toDegrees(Math.atan2(x - originX, y - originY));

return correctAngle(angle);
}
Expand Down

0 comments on commit 5e0d6a4

Please sign in to comment.