X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d-demos.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife_demo%2FStar.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife_demo%2FStar.java;h=6f5edaa947491d297f30cbc90248927705dffc08;hp=0000000000000000000000000000000000000000;hb=08719db537fae3645ca86f9ee6f8deba4dadf4f4;hpb=f0ebc20d0438fc46be1d98fb3643bd4196cb64c9 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java new file mode 100644 index 0000000..6f5edaa --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life_demo/Star.java @@ -0,0 +1,41 @@ +package eu.svjatoslav.sixth.e3d.examples.life_demo; + +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; + +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 + ); + } + +}