X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife%2FStar.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife%2FStar.java;h=81e7198a8b2abc603472400c1a779d7f9ad820ac;hb=151ac55eaaa0f3a2d7a589a0a3ff877b6db09a6f;hp=0000000000000000000000000000000000000000;hpb=3faa9ebcc7e643181ec70a26a69ba1dbd40e6ab6;p=sixth-3d-demos.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java new file mode 100644 index 0000000..81e7198 --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Star.java @@ -0,0 +1,41 @@ +package eu.svjatoslav.sixth.e3d.examples.life; + +import eu.svjatoslav.sixth.e3d.geometry.Point3D; +import eu.svjatoslav.sixth.e3d.renderer.raster.Color; +import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint; + +import java.util.ArrayList; +import java.util.List; + +public class Star extends GlowingPoint{ + public static final int STAR_SIZE = 10; + + public static final int UNIQUE_STARS_COUNT = 30; + + private static final List uniqueStarColors = new ArrayList<>(); + + /** + * A little hack to save RAM. We are going to have potentially lot of stars. + * Instead of creating new individual texture for each star, Sixth 3D engine + * uses internal optimization and reuses existing star textures, if star with + * identical color already exists. To take advantage ot such optimization + * we create here limited set of precomputed star colors and later reuse them. + */ + static { + for (int i = 0; i < UNIQUE_STARS_COUNT; i++) + uniqueStarColors.add( + new Color( + Math.random() + 0.5, + Math.random() + 0.5, + Math.random() + 0.5, + 255)); + } + + public Star(Point3D location) { + super(location, + STAR_SIZE, + uniqueStarColors.get((int) (Math.random() * uniqueStarColors.size())) // pick random pre-generated color + ); + } + +}