Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //constants used for equations defined in this class.
- public static class Constant
- {
- /** \brief Convert parsec to kilometre. */
- const double PC_TO_KM = 3.08567758129e13;
- /** \brief Seconds per year. */
- const double SEC_PER_YEAR = 365.25 * 86400;
- /** \brief Deg to radian conversion faktor. */
- const double DEG_TO_RAD = Mathf.PI / 180.0;
- /** \brief Radian to deg conversion faktor. */
- const double RAD_TO_DEG = 180.0 / Mathf.PI;
- };
- //galaxy basics defined in this equation.
- public class Galaxy
- {
- public static int starCount = 20000;
- int numberOfHIIDustClouds = 100;
- public static int armCount = 4;
- public static int guidePointsPerArm = 20;
- public static int angleIncrement = 360 / guidePointsPerArm;
- public static int startArmAngle = 0;
- public static int armAngleIncrement = 360 / armCount;
- public static int distanceIncreaseFromCore = 10;
- public static int verticalMaxChange = 10;
- public static int totalGuidePoints = guidePointsPerArm * armCount;
- public static int seventyFive = 50;
- public static int twentyFive = 70;
- public static GuidePoint[] guidePointsArray = new GuidePoint[totalGuidePoints];
- public bool starsMade = false;
- public static Vector3 center = new Vector3(0, 0, 0);
- public static float radius = (float)(distanceIncreaseFromCore + (distanceIncreaseFromCore * guidePointsPerArm) + 20);
- }
- public class Star
- {
- float m_temp; // star temperature (in kelvin)
- double m_mag; // brigtness;
- Color color = new Color();
- Vector3 m_pos; // current position in kartesion koordinates
- //default constructor
- public Star()
- {
- m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
- m_mag = 1; //brightness will be highest because star defaults to center of galaxy.
- m_pos = new Vector3(0, 0, 0); //star defaults to center of galaxy position.
- color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
- }
- //now a constructor with the three vectors (x,y,z) defined
- public Star(float x, float y, float z)
- {
- m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
- color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
- m_pos = new Vector3(x, y, z); //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- private Color calculateColorFromTemp(float temp)
- {
- //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
- float calc_temp = temp / 100;
- float Red;
- float Green;
- float Blue;
- //R
- if (calc_temp <= 66)
- {
- Red = 255;
- }
- else
- {
- Red = calc_temp - 60;
- Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
- if (Red < 0) { Red = 0; }
- if (Red > 255) { Red = 255; }
- }
- //G
- if (calc_temp <= 66)
- {
- Green = calc_temp;
- Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
- if (Green < 0) { Green = 0; }
- if (Green > 255) { Green = 255; }
- }
- else
- {
- Green = calc_temp - 60;
- Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
- if (Green < 0) { Green = 0; }
- if (Green > 255) { Green = 255; }
- }
- //B
- if (calc_temp >= 66)
- {
- Blue = 255;
- }
- else if (calc_temp <= 19)
- {
- Blue = 0;
- }
- else
- {
- Blue = calc_temp - 10;
- Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
- if (Blue < 0) { Blue = 0; }
- if (Blue > 255) { Blue = 255; }
- }
- color = new Color(Red, Green, Blue); //finally, create the color and assign it to the variable.
- return color;
- }
- private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
- {
- float brightness;
- float percent_distance = distance / Galaxy.radius;
- float working_distance = percent_distance * 2;
- //this is an exponential decay curve, with brightness as y and working_distance as f.
- //at 0, brightness is 1, while at 2, brightness is a little over 0.
- brightness = Mathf.Pow(working_distance, -2);
- return brightness;
- }
- }
- public class GuidePoint
- {
- //attributes/properties
- private Vector3 m_pos = new Vector3();
- private int ID;
- private static int guide_point_count = -1;
- //constructors
- //default constructor
- public GuidePoint()
- {
- x_coordinate = 0;
- y_coordinate = 0;
- z_coordinate = 0;
- ID = -4;
- }
- //designated constructor
- public GuidePoint(int x_coordinate, int y_coordinate, int z_coordinate)
- {
- this.x_coordinate = x_coordinate;
- this.y_coordinate = y_coordinate;
- this.z_coordinate = z_coordinate;
- ID = guide_point_count;
- guide_point_count++;
- }
- //getters
- public int getX()
- {
- return x_coordinate;
- }
- public int getY()
- {
- return y_coordinate;
- }
- public int getZ()
- {
- return z_coordinate;
- }
- public int getID()
- {
- return ID;
- }
- public void setX(int x_coordinate)
- {
- this.x_coordinate = x_coordinate;
- }
- public void setY(int x_coordinate)
- {
- this.x_coordinate = x_coordinate;
- }
- public void setZ(int x_coordinate)
- {
- this.x_coordinate = x_coordinate;
- }
- public void addID()
- {
- ID = guide_point_count;
- guide_point_count++;
- }
- }
- public class galaxygenerationstwo : MonoBehaviour {
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment