Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Constants
- public static float EARTHMASS = Mathf.Pow(5.97237f, 24); //One Earth-Mass. Used to calculate the gravity of other bodies relative to Earth's.
- //CelestialBody Variables -- Objects are assumed to be perfect spheres.
- protected double mass = 1; //measured in kilograms
- protected float surfaceArea = 1f; //Measured in square kilometers.
- protected float volume = 1f; //measured in cubic kilometers
- protected float radius = 1f; //measured in kilometers
- protected float density = 1f; //measured in grams per cubic centimeter
- protected float surfaceGravity = 1f; //measured in Gs.
- protected float surfaceTemp = 2.7f; //Measured in Kelvins. Average value for entire body. Initialized to value of cosmic microwave background.
- //Property Methods
- #region
- public double Mass
- {
- get
- {
- return mass;
- }
- set
- {
- if(value > 0)
- {
- mass = value;
- }
- }
- }
- public float SurfaceArea
- {
- get
- {
- return surfaceArea;
- }
- set
- {
- if(value > 0)
- {
- surfaceArea = value;
- }
- }
- }
- public float Volume
- {
- get
- {
- return volume;
- }
- set
- {
- if (value > 0)
- {
- volume = value;
- }
- }
- }
- public float Radius
- {
- get
- {
- return radius;
- }
- set
- {
- if (value > 0)
- {
- radius = value;
- }
- }
- }
- public float Density
- {
- get
- {
- return density;
- }
- set
- {
- if (value > 0)
- {
- density = value;
- }
- }
- }
- public float SurfaceGravity
- {
- get
- {
- return surfaceGravity;
- }
- set
- {
- if (value > 0)
- {
- surfaceGravity = value;
- }
- }
- }
- public float SurfaceTemp
- {
- get
- {
- return surfaceTemp;
- }
- set
- {
- if (value > 0)
- {
- surfaceTemp = value;
- }
- }
- }
- #endregion
- //Physical Property Methods
- #region
- /* CalcDensity()
- *
- * Purpose: finds the body's density from its mass and volume
- *
- * Parameter list: double / mass, float / volume
- *
- * Return List: float / density
- * */
- public float CalcDensity(double mass, float volume)
- {
- density = (float) mass / volume;
- return density;
- }
- /* CalcVolume()
- *
- * Purpose: finds the body's volume, given its mass and density
- *
- * Parameter list: double / mass, float / density
- *
- * Return list: float / volume
- * */
- public float CalcVolume(double mass, float density)
- {
- volume = (float)mass / density;
- return volume;
- }
- /* CalcMass()
- *
- * Purpose: finds the body's mass, given its volume and density
- *
- * Parameter list: float / volume, float / density
- *
- * Return list: double / mass
- * */
- public double CalcMass(float volume, float density)
- {
- mass = (double)volume * density;
- return mass;
- }
- /* CalcSurfaceArea()
- *
- * Purpose: finds the body's surface area given its volume. Bodies are assumed to be perfect spheres.
- *
- * Parameter list: float / volume
- *
- * Return list: float / surface area
- * */
- public float CalcSurfaceArea(float volume)
- {
- surfaceArea = 4 * Mathf.PI * Mathf.Pow(radius, 2);
- return surfaceArea;
- }
- /* CalcRadius()
- *
- * Purpose: finds the body's radius given its volume. As ever, bodies are assumed to be perfect spheres.
- *
- * Parameter list: float / volume
- *
- * Return list: float / radius
- * */
- public float CalcRadius(float volume)
- {
- float tmp = volume / Mathf.PI;
- Debug.Log(tmp.ToString());
- tmp *= 0.75f;
- Debug.Log(tmp.ToString());
- float tmp2 = 0.33f;
- Debug.Log(tmp2.ToString());
- float radius = Mathf.Pow(tmp, tmp2);
- return radius;
- }
- /* CalcGravity()
- *
- * Purpose: finds the body's surface gravity, measured in Earth Gs, given its mass.
- *
- * Parameter list: double / mass
- *
- * Return list: float / surfaceGravity
- * */
- public float CalcGravity(double mass)
- {
- double temp = mass / EARTHMASS;
- surfaceGravity = (float)temp;
- return surfaceGravity;
- }
- public virtual void SetSprite()
- {
- GetComponent<SpriteRenderer>().sprite = image;
- }
- #endregion
- // Use this for initialization
- void Start ()
- {
- CalcDensity(mass, volume);
- radius = CalcRadius(volume);
- CalcSurfaceArea(volume);
- CalcGravity(mass);
- }
- // Update is called once per frame
- void Update ()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement