Advertisement
Guest User

fuk

a guest
Aug 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. //Constants
  2. public static float EARTHMASS = Mathf.Pow(5.97237f, 24); //One Earth-Mass. Used to calculate the gravity of other bodies relative to Earth's.
  3.  
  4. //CelestialBody Variables -- Objects are assumed to be perfect spheres.
  5. protected double mass = 1; //measured in kilograms
  6. protected float surfaceArea = 1f; //Measured in square kilometers.
  7. protected float volume = 1f; //measured in cubic kilometers
  8. protected float radius = 1f; //measured in kilometers
  9. protected float density = 1f; //measured in grams per cubic centimeter
  10. protected float surfaceGravity = 1f; //measured in Gs.
  11. protected float surfaceTemp = 2.7f; //Measured in Kelvins. Average value for entire body. Initialized to value of cosmic microwave background.
  12.  
  13. //Property Methods
  14. #region
  15. public double Mass
  16. {
  17. get
  18. {
  19. return mass;
  20. }
  21. set
  22. {
  23. if(value > 0)
  24. {
  25. mass = value;
  26. }
  27. }
  28. }
  29.  
  30. public float SurfaceArea
  31. {
  32. get
  33. {
  34. return surfaceArea;
  35. }
  36. set
  37. {
  38. if(value > 0)
  39. {
  40. surfaceArea = value;
  41. }
  42. }
  43. }
  44.  
  45. public float Volume
  46. {
  47. get
  48. {
  49. return volume;
  50. }
  51. set
  52. {
  53. if (value > 0)
  54. {
  55. volume = value;
  56. }
  57. }
  58. }
  59.  
  60. public float Radius
  61. {
  62. get
  63. {
  64. return radius;
  65. }
  66. set
  67. {
  68. if (value > 0)
  69. {
  70. radius = value;
  71. }
  72. }
  73. }
  74.  
  75. public float Density
  76. {
  77. get
  78. {
  79. return density;
  80. }
  81. set
  82. {
  83. if (value > 0)
  84. {
  85. density = value;
  86. }
  87. }
  88. }
  89.  
  90. public float SurfaceGravity
  91. {
  92. get
  93. {
  94. return surfaceGravity;
  95. }
  96. set
  97. {
  98. if (value > 0)
  99. {
  100. surfaceGravity = value;
  101. }
  102. }
  103. }
  104.  
  105. public float SurfaceTemp
  106. {
  107. get
  108. {
  109. return surfaceTemp;
  110. }
  111. set
  112. {
  113. if (value > 0)
  114. {
  115. surfaceTemp = value;
  116. }
  117. }
  118. }
  119. #endregion
  120.  
  121.  
  122. //Physical Property Methods
  123. #region
  124. /* CalcDensity()
  125. *
  126. * Purpose: finds the body's density from its mass and volume
  127. *
  128. * Parameter list: double / mass, float / volume
  129. *
  130. * Return List: float / density
  131. * */
  132.  
  133. public float CalcDensity(double mass, float volume)
  134. {
  135. density = (float) mass / volume;
  136. return density;
  137. }
  138.  
  139. /* CalcVolume()
  140. *
  141. * Purpose: finds the body's volume, given its mass and density
  142. *
  143. * Parameter list: double / mass, float / density
  144. *
  145. * Return list: float / volume
  146. * */
  147.  
  148. public float CalcVolume(double mass, float density)
  149. {
  150. volume = (float)mass / density;
  151. return volume;
  152. }
  153.  
  154. /* CalcMass()
  155. *
  156. * Purpose: finds the body's mass, given its volume and density
  157. *
  158. * Parameter list: float / volume, float / density
  159. *
  160. * Return list: double / mass
  161. * */
  162.  
  163. public double CalcMass(float volume, float density)
  164. {
  165. mass = (double)volume * density;
  166. return mass;
  167. }
  168.  
  169. /* CalcSurfaceArea()
  170. *
  171. * Purpose: finds the body's surface area given its volume. Bodies are assumed to be perfect spheres.
  172. *
  173. * Parameter list: float / volume
  174. *
  175. * Return list: float / surface area
  176. * */
  177.  
  178. public float CalcSurfaceArea(float volume)
  179. {
  180. surfaceArea = 4 * Mathf.PI * Mathf.Pow(radius, 2);
  181. return surfaceArea;
  182. }
  183.  
  184. /* CalcRadius()
  185. *
  186. * Purpose: finds the body's radius given its volume. As ever, bodies are assumed to be perfect spheres.
  187. *
  188. * Parameter list: float / volume
  189. *
  190. * Return list: float / radius
  191. * */
  192.  
  193. public float CalcRadius(float volume)
  194. {
  195. float tmp = volume / Mathf.PI;
  196. Debug.Log(tmp.ToString());
  197. tmp *= 0.75f;
  198. Debug.Log(tmp.ToString());
  199. float tmp2 = 0.33f;
  200. Debug.Log(tmp2.ToString());
  201. float radius = Mathf.Pow(tmp, tmp2);
  202. return radius;
  203. }
  204.  
  205. /* CalcGravity()
  206. *
  207. * Purpose: finds the body's surface gravity, measured in Earth Gs, given its mass.
  208. *
  209. * Parameter list: double / mass
  210. *
  211. * Return list: float / surfaceGravity
  212. * */
  213.  
  214. public float CalcGravity(double mass)
  215. {
  216. double temp = mass / EARTHMASS;
  217. surfaceGravity = (float)temp;
  218. return surfaceGravity;
  219. }
  220.  
  221. public virtual void SetSprite()
  222. {
  223. GetComponent<SpriteRenderer>().sprite = image;
  224. }
  225. #endregion
  226.  
  227. // Use this for initialization
  228. void Start ()
  229. {
  230. CalcDensity(mass, volume);
  231. radius = CalcRadius(volume);
  232. CalcSurfaceArea(volume);
  233. CalcGravity(mass);
  234. }
  235.  
  236. // Update is called once per frame
  237. void Update ()
  238. {
  239.  
  240. }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement