diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 53a228625..c253c91ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -702,6 +702,89 @@ object RenderUtils { GlStateManager.popMatrix() } + fun LorenzRenderWorldEvent.drawSphereInWorld( + color: Color, + location: LorenzVec, + radius: Float, + ) { + drawSphereInWorld(color, location.x, location.y, location.z, radius) + } + + fun LorenzRenderWorldEvent.drawSphereInWorld( + color: Color, + x: Double, + y: Double, + z: Double, + radius: Float, + ) { + GlStateManager.pushMatrix() + GL11.glNormal3f(0.0f, 1.0f, 0.0f) + + GlStateManager.enableDepth() + GlStateManager.enableBlend() + GlStateManager.depthFunc(GL11.GL_LEQUAL) + GlStateManager.disableCull() + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) + GlStateManager.enableAlpha() + GlStateManager.disableTexture2D() + color.bindColor() + + var x1 = x + var y1 = y + var z1 = z + val renderViewEntity = Minecraft.getMinecraft().renderViewEntity + val viewX = + renderViewEntity.prevPosX + (renderViewEntity.posX - renderViewEntity.prevPosX) * partialTicks.toDouble() + val viewY = + renderViewEntity.prevPosY + (renderViewEntity.posY - renderViewEntity.prevPosY) * partialTicks.toDouble() + val viewZ = + renderViewEntity.prevPosZ + (renderViewEntity.posZ - renderViewEntity.prevPosZ) * partialTicks.toDouble() + x1 -= viewX + y1 -= viewY + z1 -= viewZ + + val tessellator = Tessellator.getInstance() + val worldrenderer = tessellator.worldRenderer + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION) + + val segments = 32 + + for (phi in 0 until segments) { + for (theta in 0 until segments * 2) { + val x2 = x1 + radius * sin(Math.PI * phi / segments) * cos(2.0 * Math.PI * theta / (segments * 2)) + val y2 = y1 + radius * cos(Math.PI * phi / segments) + val z2 = z1 + radius * sin(Math.PI * phi / segments) * sin(2.0 * Math.PI * theta / (segments * 2)) + + val x3 = x1 + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * theta / (segments * 2)) + val y3 = y1 + radius * cos(Math.PI * (phi + 1) / segments) + val z3 = z1 + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * theta / (segments * 2)) + + worldrenderer.pos(x2, y2, z2).endVertex() + worldrenderer.pos(x3, y3, z3).endVertex() + + val x4 = x1 + radius * sin(Math.PI * (phi + 1) / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2)) + val y4 = y1 + radius * cos(Math.PI * (phi + 1) / segments) + val z4 = z1 + radius * sin(Math.PI * (phi + 1) / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2)) + + val x5 = x1 + radius * sin(Math.PI * phi / segments) * cos(2.0 * Math.PI * (theta + 1) / (segments * 2)) + val y5 = y1 + radius * cos(Math.PI * phi / segments) + val z5 = z1 + radius * sin(Math.PI * phi / segments) * sin(2.0 * Math.PI * (theta + 1) / (segments * 2)) + + worldrenderer.pos(x4, y4, z4).endVertex() + worldrenderer.pos(x5, y5, z5).endVertex() + } + } + + tessellator.draw() + + GlStateManager.enableCull() + GlStateManager.enableTexture2D() + GlStateManager.enableDepth() + GlStateManager.disableBlend() + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f) + GlStateManager.popMatrix() + } + private fun Color.bindColor() = GlStateManager.color(this.red / 255f, this.green / 255f, this.blue / 255f, this.alpha / 255f) |