X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fcomposite%2FGalaxy.java;h=3aed0cbea9a91ab60c959d773be19f42bb5e9406;hb=ed4236f4d37f20f56347e47af41f8bcc4fafb8a1;hp=1f523fcfe5f0876357036670c23db8b06acd4865;hpb=b1e8d7bd8c9d0905e9fe3c46fc84a11779b95982;p=sixth-3d.git 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..3aed0cb 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 @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License @@ -10,56 +10,55 @@ 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.math.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; + +import static java.lang.Math.*; public class Galaxy extends AbstractCompositeShape { - private Vector textures; + private static List colors; - public Galaxy(final int size, final int tailCount, final int starsCount, + public Galaxy(final int galaxySize, 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; + final double angle1 = random() * 10; + final double angle2 = random() * 10; - final double angleSin1 = Math.sin(angle1); - final double angleCos1 = Math.cos(angle1); - final double angleSin2 = Math.sin(angle2); - final double angleCos2 = Math.cos(angle2); + final double angleSin1 = sin(angle1); + final double angleCos1 = cos(angle1); + final double angleSin2 = sin(angle2); + final double angleCos2 = cos(angle2); Random random = new Random(); + double starSize = galaxySize / 70d; + for (int i = 1; i < starsCount; i++) { - final double b = Math.random() * 10; + final double b = random() * 10; final double s = (b * b) / 30; - final double v1 = (Math.random() * (11.5 - b)) / 3; + final double v1 = (random() * (11.5 - b)) / 3; final double v1p = v1 / 2; - final double ane = ((Math.random() * (s / 2)) / tailCount) * 2; - final double sba = ((2 * Math.PI) / tailCount) + final double ane = ((random() * (s / 2)) / tailCount) * 2; + final double sba = ((2 * PI) / tailCount) * random.nextInt(tailCount); - final double x = (((Math.sin((b - sba) + ane) * s) + (Math.random() * v1)) - v1p) - * size; - final double z = (((Math.cos((b - sba) + ane) * s) + (Math.random() * v1)) - v1p) - * size; - final double y = ((Math.random() * v1) - v1p) * size; + final double x = (((sin((b - sba) + ane) * s) + (random() * v1)) - v1p) * galaxySize; + final double z = (((cos((b - sba) + ane) * s) + (random() * v1)) - v1p) * galaxySize; + final double y = ((random() * v1) - v1p) * galaxySize; final double x1 = (x * angleCos1) + (z * angleSin1); final double z1 = (z * angleCos1) - (x * angleSin1); @@ -67,32 +66,26 @@ 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), starSize); } } - 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, double size) { + addShape(new GlowingPoint(starLocation, size, colors.get((int) (random() * colors.size())))); } - public void createReusableTextures() { - textures = new Vector<>(); + private synchronized void ensureColorsAreInitialized() { + if (colors != null) return; - 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)); + colors = new ArrayList<>(); - textures.add(glowingPoint.texture); - - } + for (int i = 0; i < 30; i++) + colors.add( + new Color( + random() + 0.5, + random() + 0.5, + random() + 0.5, + 255)); } }