Point planet renderer
This commit is contained in:
@@ -4,35 +4,62 @@ import arc.*;
|
|||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.graphics.g3d.*;
|
import arc.graphics.g3d.*;
|
||||||
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
|
||||||
public class PlanetRenderer{
|
public class PlanetRenderer{
|
||||||
private ImmediateRenderer3D rend = new ImmediateRenderer3D(false, true, 0);
|
private ImmediateRenderer3D rend = new ImmediateRenderer3D(true, true, 0);
|
||||||
private Camera3D cam = new Camera3D();
|
private Camera3D cam = new Camera3D();
|
||||||
|
|
||||||
public void draw(){
|
public void draw(){
|
||||||
Draw.flush();
|
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);
|
Tmp.v1.trns(Time.time() / 4f, 20f);
|
||||||
cam.position.set(Tmp.v1.x, Tmp.v1.y, 10);
|
cam.position.set(Tmp.v1.x, 0f, Tmp.v1.y);
|
||||||
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
cam.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||||
|
cam.update();
|
||||||
cam.lookAt(0, 0, 0);
|
cam.lookAt(0, 0, 0);
|
||||||
cam.update();
|
cam.update();
|
||||||
|
|
||||||
rend.begin(cam.combined(), Gl.triangleStrip);
|
rend.begin(cam.combined(), Gl.points);
|
||||||
rend.color(Color.red);
|
build(15, 15, 15, 60, 60);
|
||||||
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.end();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=9f70d5a39a910bd855430d74e41d0b8753b47442
|
archash=dbdce4d5bfcf9d53dd21480c7d14e90a637eaa8e
|
||||||
|
|||||||
Reference in New Issue
Block a user