public SolarBody(string _name, List <int> _solarIndex, SolarType _solarType, SolarSubType _solarSubType, double mass, double radius, Orbit orbit, Color _color, SolarBody star) { this.orbit = orbit; this.mass = mass; this.bodyRadius = radius; name = _name; this.solarType = _solarType; this.solarSubType = _solarSubType; solarIndex = _solarIndex; color = _color; surfaceGravity = GameDataModel.G * mass / (radius * radius) / 9.81; surfacePressure = 0; // In atm bondAlebo = Random.value; var dist = orbit.sma; if (solarIndex.Count == 3) { dist = star.satelites[solarIndex[1]].orbit.sma; } if (solarType == SolarType.Moon || solarType == SolarType.DwarfPlanet) { surfacePressure = Random.Range(.01f, 1); greenhouse = .0137328 * Mathd.Pow(surfacePressure, 2) + .0986267 * surfacePressure; if (greenhouse < 0) { greenhouse = 0; } surfaceTemp = Mathd.Pow(((1 - bondAlebo) * star.luminosity) / ((16 * Mathd.PI * 5.6705e-8) * Mathd.Pow(orbit.sma, 2)), .25) * Mathd.Pow((1 + .438 * greenhouse * .9), .25); var rand = Random.value; if (surfaceTemp - 273.15 < -50) { if (rand < .15) { solarSubType = SolarSubType.Ice; } else if (rand < .2) { solarSubType = SolarSubType.Volcanic; } } else if (surfaceTemp - 273.15 > 120) { if (surfacePressure > .1) { if (rand < .75) { solarSubType = SolarSubType.Volcanic; } } else { if (rand < .25) { solarSubType = SolarSubType.Desert; } } } else { if (surfacePressure > .5) { if (rand < .55) { solarSubType = SolarSubType.Ocean; } else if (rand < .85) { solarSubType = SolarSubType.EarthLike; } else if (rand < .95) { solarSubType = SolarSubType.Volcanic; } } else if (surfacePressure > .25) { if (rand < .75) { solarSubType = SolarSubType.EarthLike; } else if (rand < .85) { solarSubType = SolarSubType.Ocean; } } } } else if (solarSubType == SolarSubType.GasGiant) { surfacePressure = Random.Range(10, 100); greenhouse = .0137328 * Mathd.Pow(surfacePressure, 2) + .0986267 * surfacePressure; if (greenhouse < 0) { greenhouse = 0; } surfaceTemp = Mathd.Pow(((1 - bondAlebo) * star.luminosity) / ((16 * Mathd.PI * 5.6705e-8) * Mathd.Pow(orbit.sma, 2)), .25) * Mathd.Pow((1 + .438 * greenhouse * .9), .25); } else if (solarType == SolarType.Planet && solarSubType == SolarSubType.Rocky) { var rand = Random.value; if (rand < .75) { surfacePressure = Random.Range(.01f, 2); } else { surfacePressure = Random.Range(.01f, 100); } greenhouse = .0137328 * Mathd.Pow(surfacePressure, 2) + .0986267 * surfacePressure; if (greenhouse < 0) { greenhouse = 0; } surfaceTemp = Mathd.Pow(((1 - bondAlebo) * star.luminosity) / ((16 * Mathd.PI * 5.6705e-8) * Mathd.Pow(orbit.sma, 2)), .25) * Mathd.Pow((1 + .438 * greenhouse * .9), .25); rand = Random.value; if (surfaceTemp - 273.15 < -50) { if (rand < .25) { solarSubType = SolarSubType.Ice; } } else if (surfaceTemp - 273.15 > 120) { if (surfacePressure > 20) { if (rand < .75) { solarSubType = SolarSubType.Volcanic; } } else { if (rand < .25) { solarSubType = SolarSubType.Desert; } } } else { if (surfacePressure > 40) { if (rand < .55) { solarSubType = SolarSubType.Volcanic; } else if (rand < .85) { solarSubType = SolarSubType.Ocean; } } else if (surfacePressure > 20) { if (rand < .55) { solarSubType = SolarSubType.Ocean; } else if (rand < .85) { solarSubType = SolarSubType.EarthLike; } else if (rand < .95) { solarSubType = SolarSubType.Volcanic; } } else if (surfacePressure > .25) { if (rand < .75) { solarSubType = SolarSubType.EarthLike; } else if (rand < .85) { solarSubType = SolarSubType.Ocean; } } } } //------------Assigning Colors----------------// if (solarSubType == SolarSubType.Rocky) { color = Color.gray; } else if (solarSubType == SolarSubType.EarthLike) { color = Color.green; } else if (solarSubType == SolarSubType.Ice) { color = Color.white; } else if (solarSubType == SolarSubType.Desert) { color = Color.yellow; } else if (solarSubType == SolarSubType.Ocean) { color = Color.blue; } else if (solarSubType == SolarSubType.Volcanic) { color = Color.red; } if (solarType != SolarType.Star && solarSubType != SolarSubType.GasGiant) { GeneratePlanetTiles(); } }
public static double Lerp(double from, double to, double t) { return(from + (to - from) * Mathd.Clamp01(t)); }
public double temp(double time) { if (GameManager.instance.data.stars[solarIndex[0]].solar == this) { return(surfaceTemp); } Vector3d position = Position(time); var solar = GameManager.instance.data.stars[solarIndex[0]].solar; if (solarIndex.Count == 3) { position += solar.satelites[solarIndex[1]].Position(time); } var distance = position.magnitude; //(Mathd.Pow(solar.bodyRadius, 2) / Mathd.Pow(position.magnitude, 2)) * solar.surfaceTemp * 2314; surfaceTemp = Mathd.Pow(((1 - bondAlebo) * solar.luminosity) / ((16 * Mathd.PI * 5.6705e-8) * Mathd.Pow(distance, 2)), .25) * Mathd.Pow((1 + .438 * greenhouse * .9), .25); return(surfaceTemp); }
public double MM(double parentMass) // Mean motion of orbit in radians per second. { return(Mathd.Sqrt((GameDataModel.G * parentMass) / (Mathd.Pow((double)orbit.sma, 3)))); }
public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { target = current + Mathd.DeltaAngle(current, target); return(Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime)); }
public static float AngleBetweenInPlane(Vector3 fromAngle, Vector3 toAngle, Vector3 vector) { Mathd.ProjectVectorOnPlane(fromAngle, vector); Mathd.ProjectVectorOnPlane(toAngle, vector); return(Vector3.Angle(fromAngle, toAngle)); }
public override void OnInspectorGUI() { EditorGUILayout.PropertyField(serializedObject.FindProperty("threadCount")); EditorGUILayout.PropertyField(serializedObject.FindProperty("maxPixelError")); serializedObject.ApplyModifiedProperties(); if (Application.isPlaying) { QuadNodeGenerator qng = target as QuadNodeGenerator; EditorGUILayout.LabelField(qng.queueCount + " queued nodes"); double avgsfc, minsfc, maxsfc; double avgtree, mintree, maxtree; double avggrass, mingrass, maxgrass; avgsfc = minsfc = maxsfc = avgtree = mintree = maxtree = avggrass = mingrass = maxgrass = -1; lock (QuadNode.sfctimes) { if (QuadNode.sfctimes.Count > 0) { avgsfc = 0; minsfc = QuadNode.sfctimes[0]; maxsfc = QuadNode.sfctimes[0]; QuadNode.sfctimes.ForEach(l => { avgsfc += l; minsfc = Mathd.Min(l, minsfc); maxsfc = Mathd.Max(l, maxsfc); }); avgsfc /= QuadNode.sfctimes.Count; } } lock (QuadNode.treetimes) { if (QuadNode.treetimes.Count > 0) { avgtree = 0; mintree = QuadNode.treetimes[0]; maxtree = QuadNode.treetimes[0]; QuadNode.treetimes.ForEach(l => { avgtree += l; mintree = Mathd.Min(l, mintree); maxtree = Mathd.Max(l, maxtree); }); avgtree /= QuadNode.treetimes.Count; } } lock (QuadNode.grasstimes) { if (QuadNode.grasstimes.Count > 0) { avggrass = 0; mingrass = QuadNode.grasstimes[0]; maxgrass = QuadNode.grasstimes[0]; QuadNode.grasstimes.ForEach(l => { avggrass += l; mingrass = Mathd.Min(l, mingrass); maxgrass = Mathd.Max(l, maxgrass); }); avggrass /= QuadNode.grasstimes.Count; } } float w = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 60f; EditorGUILayout.LabelField("Surface avg/min/max", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(avgsfc.ToString("f3")); EditorGUILayout.LabelField(minsfc.ToString("f3")); EditorGUILayout.LabelField(maxsfc.ToString("f3")); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Trees avg/min/max", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(avgtree.ToString("f3")); EditorGUILayout.LabelField(mintree.ToString("f3")); EditorGUILayout.LabelField(maxtree.ToString("f3")); EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField("Grass avg/min/max", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(avggrass.ToString("f3")); EditorGUILayout.LabelField(mingrass.ToString("f3")); EditorGUILayout.LabelField(maxgrass.ToString("f3")); EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = w; } }
public static bool Approximately(double a, double b) { return(Mathd.Abs(b - a) < Mathd.Max(1E-06d * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44d)); }
void fGrav(GravationalObjectV2 a, GravationalObjectV2 b) { double distance = Mathd.Sqrt(Mathd.Pow(b.x - a.x, 2) + Mathd.Pow(b.y - a.y, 2) + Mathd.Pow(b.z - a.z, 2)); float F = (float)(6.67408 * Mathd.Pow(10, -11)) * (float)((a.mass * b.mass) / Mathd.Pow(distance, 2)); //meters, kg, seconds //Debug.Log(F); //Calculate new vector for a Vector3d veca = (new Vector3d(b.x, b.y, b.z)) - (new Vector3d(a.x, a.y, a.z)); //direction vector veca = veca.normalized * (F * dt / a.mass); //force vector //veca = veca*(dt/a.mass); a.VVec = a.VVec + veca; //Calculate new vector for b Vector3d vecb = (new Vector3d(a.x, a.y, a.z)) - (new Vector3d(b.x, b.y, b.z)); //direction vector vecb = vecb.normalized * (F * dt / b.mass); //force vector //vecb = (vecb*dt)/b.mass; b.VVec = b.VVec + vecb; }
private double Sine(double t) { return(amplitude * Math.Sin(2d * Math.PI * frequency * t + Mathd.DegToRad(phase)) + valueOffset); }
Double dist(Vector3d p, Vector3d mO) { return(Mathd.Sqrt(Mathd.Pow(p.x - mO.x, 2) + Mathd.Pow(p.y - mO.y, 2) + Mathd.Pow(p.z - mO.z, 2))); }
private void CreateBaseMesh(UnityTile tile) { //TODO use arrays instead of lists _newVertexList.Clear(); _newNormalList.Clear(); _newUvList.Clear(); _newTriangleList.Clear(); var cap = (_sampleCount - 1); for (float y = 0; y < cap; y++) { for (float x = 0; x < cap; x++) { var x1 = (float)(Mathd.Lerp(tile.Rect.Min.x, tile.Rect.Max.x, x / cap) - tile.Rect.Center.x); var y1 = (float)(Mathd.Lerp(tile.Rect.Min.y, tile.Rect.Max.y, y / cap) - tile.Rect.Center.y); var x2 = (float)(Mathd.Lerp(tile.Rect.Min.x, tile.Rect.Max.x, (x + 1) / cap) - tile.Rect.Center.x); var y2 = (float)(Mathd.Lerp(tile.Rect.Min.y, tile.Rect.Max.y, (y + 1) / cap) - tile.Rect.Center.y); var triStart = _newVertexList.Count; _newVertexList.Add(new Vector3(x1, 0, y1)); _newVertexList.Add(new Vector3(x2, 0, y1)); _newVertexList.Add(new Vector3(x1, 0, y2)); //-- _newVertexList.Add(new Vector3(x2, 0, y1)); _newVertexList.Add(new Vector3(x2, 0, y2)); _newVertexList.Add(new Vector3(x1, 0, y2)); _newNormalList.Add(Unity.Constants.Math.Vector3Up); _newNormalList.Add(Unity.Constants.Math.Vector3Up); _newNormalList.Add(Unity.Constants.Math.Vector3Up); //-- _newNormalList.Add(Unity.Constants.Math.Vector3Up); _newNormalList.Add(Unity.Constants.Math.Vector3Up); _newNormalList.Add(Unity.Constants.Math.Vector3Up); _newUvList.Add(new Vector2(x / cap, 1 - y / cap)); _newUvList.Add(new Vector2((x + 1) / cap, 1 - y / cap)); _newUvList.Add(new Vector2(x / cap, 1 - (y + 1) / cap)); //-- _newUvList.Add(new Vector2((x + 1) / cap, 1 - y / cap)); _newUvList.Add(new Vector2((x + 1) / cap, 1 - (y + 1) / cap)); _newUvList.Add(new Vector2(x / cap, 1 - (y + 1) / cap)); _newTriangleList.Add(triStart); _newTriangleList.Add(triStart + 1); _newTriangleList.Add(triStart + 2); //-- _newTriangleList.Add(triStart + 3); _newTriangleList.Add(triStart + 4); _newTriangleList.Add(triStart + 5); } } var mesh = tile.MeshFilter.mesh; mesh.SetVertices(_newVertexList); mesh.SetNormals(_newNormalList); mesh.SetUVs(0, _newUvList); mesh.SetTriangles(_newTriangleList, 0); mesh.RecalculateBounds(); }
public static float MoveTowardAngle(float fromAngle, float toAngle, float maxSpeed, float amountPerCycle) { float single = Mathf.Clamp(Mathd.AngleBetween(fromAngle, toAngle) * amountPerCycle, -maxSpeed * Time.deltaTime, maxSpeed * Time.deltaTime); return(fromAngle + single); }
public static double MoveTowardsAngle(double current, double target, double maxDelta) { target = current + Mathd.DeltaAngle(current, target); return(Mathd.MoveTowards(current, target, maxDelta)); }
void takeStep(float dt) { hillRadius [0] = 0.0f; for (int j = 1; j < nb; j++) { if (m [j] > massThreshold) { double a = x [j].magnitude; hillRadius [j] = (float)(a * Mathd.Pow((double)m [j] / (3.0 * (double)m [0]), 0.33333)); } else { hillRadius [j] = 0.0f; } } float captureMultiplier = 3.0f; if (!paused) { if (useDLL) { for (int j = 0; j < nb; j++) { dx [j] = x [j].x; dy [j] = x [j].y; dz [j] = x [j].z; dvx [j] = v [j].x; dvy [j] = v [j].y; dvz [j] = v [j].z; dm [j] = m [j]; dhr [j] = captureMultiplier * hillRadius [j]; } Wrappers.Wrapper_TakeStepDLL(itd, dx, dy, dz, dvx, dvy, dvz, dax, day, daz, dm, dhr, nb, (double)dt, (double)G, (double)shieldRadius, (double)massThreshold); for (int j = 0; j < nb; j++) { x [j].x = (float)dx [j]; x [j].y = (float)dy [j]; x [j].z = (float)dz [j]; v [j].x = (float)dvx [j]; v [j].y = (float)dvy [j]; v [j].z = (float)dvz [j]; if (itd [j] > 0) { toBeRemoved [j] = true; } } } else { for (int j = 0; j < nb; j++) { a[j] = Vector3d.zero; } for (int j = 0; j < nb; j++) { for (int k = j + 1; k < nb; k++) { if (m[k] > massThreshold || m[j] > massThreshold) { Vector3d dx = (x[k] - x[j]); double dxm = dx.magnitude; //float dx2 = dxm * dxm; double dx3 = dxm * dxm * dxm; if (m[j] <= massThreshold) { if (dxm < captureMultiplier * hillRadius[k]) { toBeRemoved[j] = true; } } if (m[k] <= massThreshold) { if (dxm < captureMultiplier * hillRadius[j]) { toBeRemoved[k] = true; } } if (dxm > shieldRadius) { if (m[k] > massThreshold) { a[j] += G * m[k] / dx3 * dx; } if (m[j] > massThreshold) { a[k] -= G * m[j] / dx3 * dx; } } } } } for (int j = 0; j < nb; j++) { v[j] += a[j] * dt; x[j] += v[j] * dt; } } /* * for (int j = 0; j < nb; j++) * { * bodyGos[j].GetComponent<PlanetBehaviour>().Push(x[j]); * } */ t += dt; } }
public static double SmoothStep(double from, double to, double t) { t = Mathd.Clamp01(t); t = (-2.0 * t * t * t + 3.0 * t * t); return(to * t + from * (1.0 - t)); }
public double SemiMinorAxis() { return(Mathd.Sqrt(apoapsis * periapsis)); }
public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed) { double deltaTime = (double)Time.deltaTime; return(Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime)); }
private Vector3d Position(double time) { if (orbit.sma == 0) { return(Vector3d.zero); } double parentMass; if (solarIndex.Count == 2) { parentMass = GameManager.instance.data.stars[solarIndex[0]].solar.mass; } else if (solarIndex.Count == 3) { parentMass = GameManager.instance.data.stars[solarIndex[0]].solar.satelites[solarIndex[1]].mass; } else { throw new System.Exception("parentMass not found."); } var ena = ENA(time, parentMass); var pos = new Vector3d(orbit.sma * (Mathd.Cos(ena) - orbit.ecc), orbit.sma * Mathd.Sqrt(1 - (orbit.ecc * orbit.ecc)) * Mathd.Sin(ena)); var pol = new Polar2d(pos); pol.angle += orbit.lpe; var pos2 = pol.cartesian; return(pos2); }
public static double Repeat(double t, double length) { return(t - Mathd.Floor(t / length) * length); }
private static float AbsAngleBetween(float fromAngle, float toAngle) { return(Mathf.Abs(Mathd.AngleBetween(fromAngle, toAngle))); }