From cf5e8c6463410293bc82dfda0a8779d2f0bee7d4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 7 Jan 2020 20:09:21 -0500 Subject: [PATCH] Point planet renderer --- .../mindustry/graphics/PlanetRenderer.java | 61 +++++++++++++------ gradle.properties | 2 +- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/core/src/mindustry/graphics/PlanetRenderer.java b/core/src/mindustry/graphics/PlanetRenderer.java index 3d701b4f8f..ad8c6b2191 100644 --- a/core/src/mindustry/graphics/PlanetRenderer.java +++ b/core/src/mindustry/graphics/PlanetRenderer.java @@ -4,35 +4,62 @@ import arc.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.graphics.g3d.*; +import arc.math.*; import arc.util.*; public class PlanetRenderer{ - private ImmediateRenderer3D rend = new ImmediateRenderer3D(false, true, 0); + private ImmediateRenderer3D rend = new ImmediateRenderer3D(true, true, 0); private Camera3D cam = new Camera3D(); public void draw(){ Draw.flush(); - Gl.clear(Gl.depthBufferBit); + Gl.clearColor(0, 0, 0, 1); + //Gl.clear(Gl.depthBufferBit | Gl.colorBufferBit); + Gl.lineWidth(40f); - Tmp.v1.trns(Time.time() * 2f, 30f); - cam.position.set(Tmp.v1.x, Tmp.v1.y, 10); + Tmp.v1.trns(Time.time() / 4f, 20f); + cam.position.set(Tmp.v1.x, 0f, Tmp.v1.y); cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight()); + cam.update(); cam.lookAt(0, 0, 0); cam.update(); - rend.begin(cam.combined(), Gl.triangleStrip); - rend.color(Color.red); - rend.vertex(0f, 0f, 0f); - rend.color(Color.green); - rend.vertex(0f, 5f, 0f); - rend.color(Color.blue); - rend.vertex(0f, 5f, 5f); - rend.color(Color.red); - rend.vertex(0f, 0f, 0f); - rend.color(Color.green); - rend.vertex(0f, 0f, 5f); - rend.color(Color.blue); - rend.vertex(0f, 5f, 5f); + rend.begin(cam.combined(), Gl.points); + build(15, 15, 15, 60, 60); rend.end(); } + + void build(float width, float height, float depth, int divisionsU, int divisionsV) { + float angleUFrom = 0, angleUTo = 360f, angleVFrom = 0, angleVTo = 180f; + final float hw = width * 0.5f; + final float hh = height * 0.5f; + final float hd = depth * 0.5f; + final float auo = Mathf.degRad * angleUFrom; + final float stepU = (Mathf.degRad * (angleUTo - angleUFrom)) / divisionsU; + final float avo = Mathf.degRad * angleVFrom; + final float stepV = (Mathf.degRad * (angleVTo - angleVFrom)) / divisionsV; + final float us = 1f / divisionsU; + final float vs = 1f / divisionsV; + float u, v, angleU, angleV; + + final int s = divisionsU + 3; + int tempOffset = 0; + + for (int iv = 0; iv <= divisionsV; iv++) { + angleV = avo + stepV * iv; + v = vs * iv; + final float t = Mathf.sin(angleV); + final float h = Mathf.cos(angleV) * hh; + for (int iu = 0; iu <= divisionsU; iu++) { + angleU = auo + stepU * iu; + u = 1f - us * iu; + Tmp.v31.set(Mathf.cos(angleU) * hw * t, h, Mathf.sin(angleU) * hd * t); + + rend.color(Color.white); + rend.normal(Tmp.v32.set(Tmp.v31).nor()); + rend.texCoord(u, v); + rend.vertex(Tmp.v31); + } + } + } } diff --git a/gradle.properties b/gradle.properties index 052fc80569..ecc45979db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=9f70d5a39a910bd855430d74e41d0b8753b47442 +archash=dbdce4d5bfcf9d53dd21480c7d14e90a637eaa8e