]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Tidy up overcrowding with spheres
authorIrtimaled <irtimaled@gmail.com>
Thu, 25 Jun 2020 07:46:01 +0000 (00:46 -0700)
committerIrtimaled <irtimaled@gmail.com>
Tue, 18 Aug 2020 04:15:53 +0000 (21:15 -0700)
src/main/java/com/irtimaled/bbor/client/renderers/AbstractRenderer.java

index 64f8fc7e2949436241d6a436ddf8469d5bc6161b..de227735639eedd7bc8e4366a23f1113fdea0fb3 100644 (file)
@@ -2,6 +2,7 @@ package com.irtimaled.bbor.client.renderers;
 
 import com.irtimaled.bbor.client.config.ConfigManager;
 import com.irtimaled.bbor.client.models.Point;
+import com.irtimaled.bbor.common.MathHelper;
 import com.irtimaled.bbor.common.models.AbstractBoundingBox;
 import net.minecraft.client.Minecraft;
 import net.minecraft.client.gui.FontRenderer;
@@ -11,7 +12,9 @@ import java.util.function.Supplier;
 
 public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
     private static final double TAU = 6.283185307179586D;
+    public static final double PHI_SEGMENT = TAU / 90D;
     private static final double PI = TAU / 2D;
+    public static final double THETA_SEGMENT = PHI_SEGMENT / 2D;
 
     public abstract void render(T boundingBox);
 
@@ -138,7 +141,8 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
         RenderHelper.lineWidth2();
 
         double offset = ((radius - (int) radius) == 0) ? center.getY() - (int) center.getY() : 0;
-        for (double dy = offset - radius; dy <= radius + 1; dy++) {
+        int dyStep = radius < 64 ? 1 : MathHelper.floor(radius / 32);
+        for (double dy = offset - radius; dy <= radius + 1; dy += dyStep) {
             double circleRadius = Math.sqrt((radius * radius) - (dy * dy));
             if (circleRadius == 0) circleRadius = Math.sqrt(2) / 2;
             renderCircle(center, circleRadius, color, dy + 0.001F);
@@ -149,9 +153,8 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
         Renderer renderer = Renderer.startLineLoop()
                 .setColor(color);
 
-        for (int a = 0; a < 360; a += 5) {
-            double heading = a * PI / 180;
-            renderer.addPoint(new OffsetPoint(center.offset(Math.cos(heading) * radius, dy, Math.sin(heading) * radius)));
+        for (double phi = 0.0D; phi < TAU; phi += PHI_SEGMENT) {
+            renderer.addPoint(new OffsetPoint(center.offset(Math.cos(phi) * radius, dy, Math.sin(phi) * radius)));
         }
 
         renderer.render();
@@ -163,15 +166,12 @@ public abstract class AbstractRenderer<T extends AbstractBoundingBox> {
         Renderer renderer = Renderer.startPoints()
                 .setColor(color);
 
-        int segments = 64;
-        double thetaSegment = PI / (double) segments;
-        double phiSegment = TAU / (double) segments;
-
-        for (double phi = 0.0D; phi < TAU; phi += phiSegment) {
-            for (double theta = 0.0D; theta < PI; theta += thetaSegment) {
-                double dx = radius * Math.sin(phi) * Math.cos(theta);
-                double dz = radius * Math.sin(phi) * Math.sin(theta);
-                double dy = radius * Math.cos(phi);
+        for (double phi = 0.0D; phi < TAU; phi += PHI_SEGMENT) {
+            double dy = radius * Math.cos(phi);
+            double radiusBySinPhi = radius * Math.sin(phi);
+            for (double theta = 0.0D; theta < PI; theta += THETA_SEGMENT) {
+                double dx = radiusBySinPhi * Math.cos(theta);
+                double dz = radiusBySinPhi * Math.sin(theta);
 
                 renderer.addPoint(new OffsetPoint(center.offset(dx, dy, dz)));
             }