Ramaraunt1

Untitled

Dec 17th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 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. double 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.  
  71. private Color calculateColorFromTemp(float temp)
  72. {
  73. //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
  74.  
  75. float calc_temp = temp / 100;
  76. float Red;
  77. float Green;
  78. float Blue;
  79.  
  80. //R
  81. if (calc_temp <= 66)
  82. {
  83. Red = 255;
  84. }
  85. else
  86. {
  87. Red = calc_temp - 60;
  88. Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
  89. if (Red < 0) { Red = 0; }
  90. if (Red > 255) { Red = 255; }
  91. }
  92.  
  93. //G
  94. if (calc_temp <= 66)
  95. {
  96. Green = calc_temp;
  97. Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
  98. if (Green < 0) { Green = 0; }
  99. if (Green > 255) { Green = 255; }
  100. }
  101. else
  102. {
  103. Green = calc_temp - 60;
  104. Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
  105. if (Green < 0) { Green = 0; }
  106. if (Green > 255) { Green = 255; }
  107. }
  108.  
  109. //B
  110. if (calc_temp >= 66)
  111. {
  112. Blue = 255;
  113. }
  114. else if (calc_temp <= 19)
  115. {
  116. Blue = 0;
  117. }
  118. else
  119. {
  120. Blue = calc_temp - 10;
  121. Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
  122. if (Blue < 0) { Blue = 0; }
  123. if (Blue > 255) { Blue = 255; }
  124. }
  125.  
  126. color = new Color(Red, Green, Blue); //finally, create the color and assign it to the variable.
  127. return color;
  128.  
  129. }
  130.  
  131. private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
  132. {
  133.  
  134. float brightness;
  135. float percent_distance = distance / Galaxy.radius;
  136. float working_distance = percent_distance * 2;
  137. //this is an exponential decay curve, with brightness as y and working_distance as f.
  138. //at 0, brightness is 1, while at 2, brightness is a little over 0.
  139. brightness = Mathf.Pow(working_distance, -2);
  140. return brightness;
  141.  
  142. }
  143. }
  144.  
  145. public class GuidePoint
  146. {
  147. //attributes/properties
  148. private Vector3 m_pos = new Vector3();
  149. private int ID;
  150. private static int guide_point_count = -1;
  151.  
  152. //constructors
  153. //default constructor
  154. public GuidePoint()
  155. {
  156. x_coordinate = 0;
  157. y_coordinate = 0;
  158. z_coordinate = 0;
  159. ID = -4;
  160. }
  161. //designated constructor
  162. public GuidePoint(int x_coordinate, int y_coordinate, int z_coordinate)
  163. {
  164. this.x_coordinate = x_coordinate;
  165. this.y_coordinate = y_coordinate;
  166. this.z_coordinate = z_coordinate;
  167. ID = guide_point_count;
  168. guide_point_count++;
  169. }
  170. //getters
  171. public int getX()
  172. {
  173. return x_coordinate;
  174. }
  175. public int getY()
  176. {
  177. return y_coordinate;
  178. }
  179. public int getZ()
  180. {
  181. return z_coordinate;
  182. }
  183. public int getID()
  184. {
  185. return ID;
  186. }
  187. public void setX(int x_coordinate)
  188. {
  189. this.x_coordinate = x_coordinate;
  190. }
  191. public void setY(int x_coordinate)
  192. {
  193. this.x_coordinate = x_coordinate;
  194. }
  195. public void setZ(int x_coordinate)
  196. {
  197. this.x_coordinate = x_coordinate;
  198. }
  199. public void addID()
  200. {
  201. ID = guide_point_count;
  202. guide_point_count++;
  203. }
  204. }
  205.  
  206.  
  207. public class galaxygenerationstwo : MonoBehaviour {
  208.  
  209. // Use this for initialization
  210. void Start () {
  211.  
  212. }
  213.  
  214. // Update is called once per frame
  215. void Update () {
  216.  
  217. }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment