Ramaraunt1

Untitled

Dec 17th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. //constants used for equations defined in this class.
  5. public static class Constant
  6. {
  7.  
  8. /** \brief Convert parsec to kilometre. */
  9. const double PC_TO_KM = 3.08567758129e13;
  10.  
  11. /** \brief Seconds per year. */
  12. const double SEC_PER_YEAR = 365.25 * 86400;
  13.  
  14. /** \brief Deg to radian conversion faktor. */
  15. const double DEG_TO_RAD = Mathf.PI / 180.0;
  16.  
  17. /** \brief Radian to deg conversion faktor. */
  18. const double RAD_TO_DEG = 180.0 / Mathf.PI;
  19. };
  20.  
  21. //galaxy basics defined in this equation.
  22. public class Galaxy
  23. {
  24. public static int starCount = 20000;
  25. int numberOfHIIDustClouds = 100;
  26. public static int armCount = 4;
  27. public static int guidePointsPerArm = 20;
  28. public static int angleIncrement = 360 / guidePointsPerArm;
  29. public static int startArmAngle = 0;
  30. public static int armAngleIncrement = 360 / armCount;
  31. public static int distanceIncreaseFromCore = 10;
  32. public static int verticalMaxChange = 10;
  33. public static int totalGuidePoints = guidePointsPerArm * armCount;
  34. public static int seventyFive = 50;
  35. public static int twentyFive = 70;
  36. public static GuidePoint[] guidePointsArray = new GuidePoint[totalGuidePoints];
  37. public bool starsMade = false;
  38.  
  39. public static Vector3 center = new Vector3(0, 0, 0);
  40. public static float radius = (float)(distanceIncreaseFromCore + (distanceIncreaseFromCore * guidePointsPerArm) + 20);
  41.  
  42. }
  43.  
  44. public class Star
  45. {
  46. float m_temp; // star temperature (in kelvin)
  47. float m_mag; // brigtness;
  48. Color color = new Color();
  49. Vector3 m_pos; // current position in kartesion koordinates
  50.  
  51. //default constructor
  52. public Star()
  53. {
  54. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  55. m_mag = 1; //brightness will be highest because star defaults to center of galaxy.
  56. m_pos = new Vector3(0, 0, 0); //star defaults to center of galaxy position.
  57. color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
  58.  
  59. }
  60. //now a constructor with the three vectors (x,y,z) defined
  61. public Star(float x, float y, float z)
  62. {
  63. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  64. color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
  65. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  66. float distance = Vector3.Distance(Galaxy.center, m_pos);
  67. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  68. }
  69.  
  70. //getters
  71. public float getM_temp()
  72. {
  73. return m_temp;
  74. }
  75. public Color getColor()
  76. {
  77. return color;
  78. }
  79. public Vector3 getM_pos()
  80. {
  81. return m_pos;
  82. }
  83. public float getM_mag()
  84. {
  85. return m_mag;
  86. }
  87.  
  88. //setters
  89. public void setM_temp(float m_temp)
  90. {
  91. this.m_temp = m_temp;
  92. color = calculateColorFromTemp(m_temp);
  93. }
  94. public void setM_pos(Vector3 m_pos)
  95. {
  96. this.m_pos = m_pos;
  97. float distance = Vector3.Distance(Galaxy.center, m_pos);
  98. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  99. }
  100. public void setM_pos(float x, float y, float z)
  101. {
  102. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  103. float distance = Vector3.Distance(Galaxy.center, m_pos);
  104. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  105. }
  106.  
  107.  
  108. //private functions
  109. private Color calculateColorFromTemp(float temp)
  110. {
  111. //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
  112.  
  113. float calc_temp = temp / 100;
  114. float Red;
  115. float Green;
  116. float Blue;
  117.  
  118. //R
  119. if (calc_temp <= 66)
  120. {
  121. Red = 255;
  122. }
  123. else
  124. {
  125. Red = calc_temp - 60;
  126. Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
  127. if (Red < 0) { Red = 0; }
  128. if (Red > 255) { Red = 255; }
  129. }
  130.  
  131. //G
  132. if (calc_temp <= 66)
  133. {
  134. Green = calc_temp;
  135. Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
  136. if (Green < 0) { Green = 0; }
  137. if (Green > 255) { Green = 255; }
  138. }
  139. else
  140. {
  141. Green = calc_temp - 60;
  142. Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
  143. if (Green < 0) { Green = 0; }
  144. if (Green > 255) { Green = 255; }
  145. }
  146.  
  147. //B
  148. if (calc_temp >= 66)
  149. {
  150. Blue = 255;
  151. }
  152. else if (calc_temp <= 19)
  153. {
  154. Blue = 0;
  155. }
  156. else
  157. {
  158. Blue = calc_temp - 10;
  159. Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
  160. if (Blue < 0) { Blue = 0; }
  161. if (Blue > 255) { Blue = 255; }
  162. }
  163.  
  164. color = new Color(Red, Green, Blue); //finally, create the color and assign it to the variable.
  165. return color;
  166.  
  167. }
  168.  
  169. private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
  170. {
  171.  
  172. float brightness;
  173. float percent_distance = distance / Galaxy.radius;
  174. float working_distance = percent_distance * 2;
  175. //this is an exponential decay curve, with brightness as y and working_distance as x.
  176. //at 0, brightness is 1, while at 2, brightness is a little over 0.
  177. brightness = (Mathf.Pow(working_distance, -2));
  178. return brightness;
  179.  
  180. }
  181. }
  182.  
  183. public class GuidePoint
  184. {
  185. //attributes/properties
  186. private Vector3 m_pos = new Vector3();
  187. private int ID;
  188. private static int guide_point_count = -1; //minus 1, cause first guide point is galactic center and has id of -1.
  189. private static Color color = Color.yellow;
  190.  
  191. //constructors
  192. //default constructor
  193. public GuidePoint()
  194. {
  195. m_pos = new Vector3(0, 0, 0);
  196. ID = -4;
  197. }
  198. //designated constructor
  199. public GuidePoint(float x_coordinate, float y_coordinate, float z_coordinate)
  200. {
  201. m_pos = new Vector3(x_coordinate, y_coordinate, z_coordinate);
  202. ID = guide_point_count;
  203. guide_point_count++;
  204. }
  205.  
  206. //getters
  207. public Vector3 getM_pos()
  208. {
  209. return m_pos;
  210. }
  211. public int getID()
  212. {
  213. return ID;
  214. }
  215. public int getGuidePointCount()
  216. {
  217. return guide_point_count;
  218. }
  219.  
  220. //setters
  221. public void setM_pos(Vector3 m_pos)
  222. {
  223. this.m_pos = m_pos;
  224. }
  225.  
  226. //adders
  227. public void addID()
  228. {
  229. ID = guide_point_count;
  230. guide_point_count++;
  231. }
  232. }
  233.  
  234.  
  235. public class galaxygenerationstwo : MonoBehaviour {
  236.  
  237. // Use this for initialization
  238. void Start () {
  239.  
  240. }
  241.  
  242. // Update is called once per frame
  243. void Update () {
  244.  
  245. }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment