From: Svjatoslav Agejenko Date: Wed, 14 Jun 2017 04:31:11 +0000 (+0300) Subject: Modernized galaxy generation code. X-Git-Tag: sixth-3d-1.2~53 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=dc58b3a2fdacb5a7d2405200c744bc51dfdf7c67;p=sixth-3d.git Modernized galaxy generation code. --- diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Galaxy.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Galaxy.java index 1f523fc..efffc59 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Galaxy.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/Galaxy.java @@ -12,26 +12,23 @@ package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite; import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.geometry.Transform; import eu.svjatoslav.sixth.e3d.renderer.raster.Color; -import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.ForwardOrientedTexture; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint; import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; -import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture; +import java.util.ArrayList; +import java.util.List; import java.util.Random; -import java.util.Vector; public class Galaxy extends AbstractCompositeShape { - private Vector textures; + private static List colors; public Galaxy(final int size, final int tailCount, final int starsCount, Transform transform) { super(transform); - Point3D location = new Point3D(); - - createReusableTextures(); + ensureColorsAreInitialized(); final double angle1 = Math.random() * 10; final double angle2 = Math.random() * 10; @@ -67,32 +64,28 @@ public class Galaxy extends AbstractCompositeShape { final double y1 = (y * angleCos2) + (z1 * angleSin2); final double z2 = (z1 * angleCos2) - (y * angleSin2); - final Point3D point3d = new Point3D(x1 + location.x, y1 - + location.y, z2 + location.z); - - addStar(point3d); + addStar(new Point3D(x1,y1,z2)); } } - public void addStar(final Point3D point3d) { - - final Texture texture = textures.get((int) (Math.random() * textures - .size())); - - addShape(new ForwardOrientedTexture(point3d, 10, texture)); + private void addStar(final Point3D starLocation) { + addShape( + new GlowingPoint(starLocation,10, + colors.get((int) (Math.random() * colors.size())))); } - public void createReusableTextures() { - textures = new Vector<>(); - - for (int i = 0; i < 30; i++) { - final GlowingPoint glowingPoint = new GlowingPoint(null, 1, - new Color(Math.random() + 0.5, Math.random() + 0.5, - Math.random() + 0.5, 255)); + private synchronized void ensureColorsAreInitialized() { + if (colors != null) return; - textures.add(glowingPoint.texture); + colors = new ArrayList<>(); - } + for (int i = 0; i < 30; i++) + colors.add( + new Color( + Math.random() + 0.5, + Math.random() + 0.5, + Math.random() + 0.5, + 255)); } }