Improved code readability. Components now aware of what mouse button was clicked.
[sixth-3d-demos.git] / src / main / java / eu / svjatoslav / sixth / e3d / examples / life_demo / Star.java
1 package eu.svjatoslav.sixth.e3d.examples.life_demo;
2
3 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
4 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
5 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 class Star extends GlowingPoint {
11     public static final int STAR_SIZE = 10;
12
13     public static final int UNIQUE_STARS_COUNT = 30;
14
15     private static final List<Color> uniqueStarColors = new ArrayList<>();
16
17     /*
18      * A little hack to save RAM. We are going to have potentially lot of stars.
19      * Instead of creating new individual texture for each star, Sixth 3D engine
20      * uses internal optimization and reuses existing star textures, if star with
21      * identical color already exists. To take advantage ot such optimization
22      * we create here limited set of precomputed star colors and later reuse them.
23      */
24     static {
25         for (int i = 0; i < UNIQUE_STARS_COUNT; i++)
26             uniqueStarColors.add(
27                     new Color(
28                             Math.random() + 0.5,
29                             Math.random() + 0.5,
30                             Math.random() + 0.5,
31                             255));
32     }
33
34     public Star(Point3D location) {
35         super(location,
36                 STAR_SIZE,
37                 uniqueStarColors.get((int) (Math.random() * uniqueStarColors.size())) // pick random pre-generated color
38         );
39     }
40
41 }