2 * Sixth - System for data storage, computation, exploration and interaction.
3 * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
12 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
13 import eu.svjatoslav.sixth.e3d.geometry.Transform;
14 import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
15 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.ForwardOrientedTexture;
16 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
17 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
18 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
20 import java.util.Random;
21 import java.util.Vector;
23 public class Galaxy extends AbstractCompositeShape {
25 private Vector<Texture> textures;
27 public Galaxy(final int size, final int tailCount, final int starsCount,
28 Transform transform) {
32 Point3D location = new Point3D();
34 createReusableTextures();
36 final double angle1 = Math.random() * 10;
37 final double angle2 = Math.random() * 10;
39 final double angleSin1 = Math.sin(angle1);
40 final double angleCos1 = Math.cos(angle1);
41 final double angleSin2 = Math.sin(angle2);
42 final double angleCos2 = Math.cos(angle2);
44 Random random = new Random();
46 for (int i = 1; i < starsCount; i++) {
47 final double b = Math.random() * 10;
49 final double s = (b * b) / 30;
51 final double v1 = (Math.random() * (11.5 - b)) / 3;
52 final double v1p = v1 / 2;
54 final double ane = ((Math.random() * (s / 2)) / tailCount) * 2;
55 final double sba = ((2 * Math.PI) / tailCount)
56 * random.nextInt(tailCount);
58 final double x = (((Math.sin((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
60 final double z = (((Math.cos((b - sba) + ane) * s) + (Math.random() * v1)) - v1p)
62 final double y = ((Math.random() * v1) - v1p) * size;
64 final double x1 = (x * angleCos1) + (z * angleSin1);
65 final double z1 = (z * angleCos1) - (x * angleSin1);
67 final double y1 = (y * angleCos2) + (z1 * angleSin2);
68 final double z2 = (z1 * angleCos2) - (y * angleSin2);
70 final Point3D point3d = new Point3D(x1 + location.x, y1
71 + location.y, z2 + location.z);
77 public void addStar(final Point3D point3d) {
79 final Texture texture = textures.get((int) (Math.random() * textures
82 addShape(new ForwardOrientedTexture(point3d, 10, texture));
85 public void createReusableTextures() {
86 textures = new Vector<>();
88 for (int i = 0; i < 30; i++) {
89 final GlowingPoint glowingPoint = new GlowingPoint(null, 1,
90 new Color(Math.random() + 0.5, Math.random() + 0.5,
91 Math.random() + 0.5, 255));
93 textures.add(glowingPoint.texture);