public CelestialBodies searchMinimumDistance(List <CelestialBodies> cel, Vector3 playerPosition) { CelestialBodies plant = new CelestialBodies(); float minDistance = 0; bool flag = false; foreach (CelestialBodies c in cel) { if (c.getType().ToLower().Equals("planet") && !flag) //to make sure that the first minDisance is of the first plant in the array { Vector3 plantPosition = c.getPosition(); Vector3 cal = new Vector3(playerPosition.x - plantPosition.x, playerPosition.y - plantPosition.y, playerPosition.z - plantPosition.z); minDistance = Mathf.Sqrt(cal.x * cal.x + cal.y * cal.y + cal.z * cal.z); plant = c; flag = true; } else if (c.getType().ToLower().Equals("planet")) { Vector3 plantPosition = c.getPosition(); Vector3 cal = new Vector3(playerPosition.x - plantPosition.x, playerPosition.y - plantPosition.y, playerPosition.z - plantPosition.z); float distance = Mathf.Sqrt(cal.x * cal.x + cal.y * cal.y + cal.z * cal.z); if (distance < minDistance) { minDistance = distance; plant = c; } } } return(plant); }
private void LoadCelestialBodies() { CelestialBodies.Add(new Sun(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Merkur(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Venus(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Erde(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Mars(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Jupiter(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Saturn(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Uranus(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Neptun(this, GraphicsDevice, Observer.Camera)); CelestialBodies.Add(new Pluto(this, GraphicsDevice, Observer.Camera)); //CelestialBodies.Add(new Halleyscher_Komet(this, GraphicsDevice, Observer.Camera)); CelestialBody.SetInfluencingBoedies(new CelestialBody[] { CelestialBodies[0], CelestialBodies[1], CelestialBodies[2], CelestialBodies[3], CelestialBodies[4], CelestialBodies[5], CelestialBodies[6], CelestialBodies[7], CelestialBodies[8], CelestialBodies[9] }); for (int i = 0; i < CelestialBodies.Count; i++) { CelestialBodies[i].Begin(); } }
public void AddGPSPosition(string name, Vector3 position) { var celestialBody = CelestialBodies.Find(obj => obj.Name == name); if (celestialBody == null) { celestialBody = new DetectedEntity(); CelestialBodies.Add(celestialBody); } celestialBody.Name = name; celestialBody.Position = position; celestialBody.Type = CelestialType.GPS; }
internal static void Init(QStage qStage) { CelestialBodies.SetSelectedBody(qStage.Body.bodyName); SimManager.Gravity = QTools.Gravity(qStage.Body); BuildAdvanced.Altitude = qStage.Altitude; SimManager.Atmosphere = (qStage.Atmosphere ? CelestialBodies.SelectedBody.GetAtmospheres(BuildAdvanced.Altitude) : 0d); SimManager.Mach = qStage.Mach; SimManager.OnReady += GetSimManagerResults; Log("Simulation inited: \t" + qStage.Body.bodyName, "QVessel"); Log("\tGravity: \t\t" + SimManager.Gravity, "QVessel"); Log("\tAtmosphere: \t" + qStage.Atmosphere, "QVessel"); Log("\t\tCalculation: " + SimManager.Atmosphere, "QVessel"); Log("\tMach: \t\t" + SimManager.Mach, "QVessel"); Log("\tAltitude: \t\t" + BuildAdvanced.Altitude, "QVessel"); }
/// <summary> /// Loads the settings when this object is created. /// </summary> private void Load() { try { SettingHandler handler = SettingHandler.Load("BuildAdvanced.xml"); handler.Get("visible", ref visible); position.x = handler.Get("windowPositionX", position.x); position.y = handler.Get("windowPositionY", position.y); handler.Get("compactMode", ref compactMode); handler.Get("compactCollapseRight", ref compactCollapseRight); handler.Get("showAllStages", ref showAllStages); handler.Get("showAtmosphericDetails", ref showAtmosphericDetails); handler.Get("showSettings", ref showSettings); CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name)); } catch (Exception ex) { MyLogger.Exception(ex, "BuildAdvanced.Load()"); } }
private void DrawBody(CelestialBodies.BodyInfo bodyInfo, int depth = 0) { GUILayout.BeginHorizontal(); GUILayout.Space(20.0f * depth); if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? bodiesButtonActiveStyle : bodiesButtonStyle)) { CelestialBodies.SetSelectedBody(bodyInfo.Name); Altitude = 0.0f; bodiesList.Resize = true; } GUILayout.EndHorizontal(); if (bodyInfo.Selected) { for (int i = 0; i < bodyInfo.Children.Count; ++i) { DrawBody(bodyInfo.Children[i], depth + 1); } } }
public void informationAboutPlant() { Vector3 playerPosition = player.getPlayerPosition(); print(playerPosition); List <CelestialBodies> celestialBodies = spaceController.getCelestialBodies(); CelestialBodies planet = spaceController.searchMinimumDistance(celestialBodies, playerPosition); string info = planet.getName() + "\n" + "Volume " + planet.getInfo().getVolume() + "\nCircumference " + planet.getInfo().getCircumference() + "\n" + "Mass" + planet.getInfo().getMass() + "Radius " + planet.getInfo().getRadius() + "\n" + "Surgace " + planet.getInfo().getSurface() + "\n" + "Average Temperature " + planet.getInfo().getAverageTemperature() + "\n" + "Position from sun " + planet.getInfo().getPositionFromSun() + "\n" + "Orbital Period " + planet.getInfo().getOrbitalPeroid() + "\n" + "NumberOfHoursInOneDay " + planet.getInfo().getDayHours() + "\n" + "number Of Moons " + planet.getInfo().getNumberOfMoons() + "\n" + "Gravity Amount " + planet.getGravity() + "\n" + "Distance from Sun " + planet.getInfo().getDistanceFromSun(); TextMesh textObject = GameObject.Find("PlanetInfo").GetComponent <TextMesh>(); textObject.text = info; // return plant; }
public static void GetState(State state) { if (state == null) { throw new ArgumentNullException(); } state.CheckValidity(); Body body = state.Body.Value; DateTime epoch = state.Epoch; DefaultState bodyDefaultState = CelestialBodies.GetDefaultState(body, epoch); defaultStates.Add(body, bodyDefaultState); foreach (Coordinates mainCoordinates in state.CoordinatesSet) { if (mainCoordinates.CoordinatesNeeded == null || mainCoordinates.Body == null) { throw new ArgumentNullException(); } Body origin = mainCoordinates.Body.Value; if (origin == body) { throw new InvalidOperationException(); } DefaultState originDefaultState = new DefaultState(); if (bodyDefaultState.Coordinates.Body != origin) { originDefaultState = CelestialBodies.GetDefaultState(origin); defaultStates.Add(origin, originDefaultState); } CoordinatesNeeded coordinatesNeeded = mainCoordinates.CoordinatesNeeded; if (coordinatesNeeded.Keplerian) { //Earth-Sun, Sun-Earth if (bodyDefaultState.Coordinates.Body == origin) { if (bodyDefaultState.CoordinateType == CoordinateType.Keplerian) { CoordinateTransformations.ConvertKeplerianFrame(bodyDefaultState.Coordinates.KeplerianCoordinates, mainCoordinates.KeplerianCoordinates); } else if (bodyDefaultState.CoordinateType == CoordinateType.Cartesian) { CoordinateTransformations.ConvertCartesianToKeplerian(bodyDefaultState.Coordinates.CartesianCoordinates.First(), mainCoordinates.KeplerianCoordinates); } else { throw new NotImplementedException(); } } // Sun-Mars , Sun default earth, Mars default sun else if (originDefaultState.Coordinates.Body == body) { CartesianCoordinates dummyCartesianCoordinates = new CartesianCoordinates { CoordinateFrame = mainCoordinates.KeplerianCoordinates.CoordinateFrame, Depth = CartesianDepth.Velocity, }; if (originDefaultState.CoordinateType == CoordinateType.Keplerian) { CartesianCoordinates cartesianCoordinates1 = new CartesianCoordinates { Depth = CartesianDepth.Velocity, }; CoordinateTransformations.ConvertKeplerianToCartesian(originDefaultState.Coordinates.KeplerianCoordinates, cartesianCoordinates1); CoordinateTransformations.ConvertCartesianFrame(cartesianCoordinates1, dummyCartesianCoordinates); } else if (originDefaultState.CoordinateType == CoordinateType.Cartesian) { CoordinateTransformations.ConvertCartesianFrame(originDefaultState.Coordinates.CartesianCoordinates.First(), dummyCartesianCoordinates); } dummyCartesianCoordinates.Negative(); CoordinateTransformations.ConvertCartesianToKeplerian(dummyCartesianCoordinates, mainCoordinates.KeplerianCoordinates); } //Moon-Sun //Sun-Moon } if (coordinatesNeeded.Cartesian) { foreach (CartesianCoordinates cartesianCoordinates in mainCoordinates.CartesianCoordinates) { if (cartesianCoordinates == null || cartesianCoordinates.CoordinateFrame == null) { throw new ArgumentNullException(); } cartesianCoordinates.Origin = origin; if (origin != body) { CartesianCoordinates dummyCartesianCoordinates = new CartesianCoordinates { Depth = cartesianCoordinates.Depth, CoordinateFrame = cartesianCoordinates.CoordinateFrame, }; Coordinates dummyCoordinates = new Coordinates { Body = origin, CoordinatesNeeded = new CoordinatesNeeded { Cartesian = true, }, KeplerianCoordinates = mainCoordinates.KeplerianCoordinates, CartesianCoordinates = new List <CartesianCoordinates> { dummyCartesianCoordinates, } }; GetHelioCentricState(state.Epoch, dummyCoordinates); dummyCartesianCoordinates.Negative(); //BETTERME cartesianCoordinates.Position = dummyCartesianCoordinates.Position; if (cartesianCoordinates.Depth >= CartesianDepth.Velocity) { cartesianCoordinates.Velocity = dummyCartesianCoordinates.Velocity; } } else { cartesianCoordinates.Position = Vector <double> .Build.Dense(3); if (cartesianCoordinates.Depth >= CartesianDepth.Velocity) { cartesianCoordinates.Velocity = Vector <double> .Build.Dense(3); } } } } } }
private void DrawBody(CelestialBodies.BodyInfo bodyInfo, int depth = 0) { GUILayout.BeginHorizontal(); GUILayout.Space(20.0f * depth); if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? bodiesButtonActiveStyle : bodiesButtonStyle)) { CelestialBodies.SetSelectedBody(bodyInfo.Name); Altitude = 0.0f; bodiesList.Resize = true; } GUILayout.EndHorizontal(); if (bodyInfo.Selected) { for (int i = 0; i < bodyInfo.Children.Count; ++i) { DrawBody(bodyInfo.Children[i], depth + 1); } } }
public void changeGravity(string planetName, float amount) { CelestialBodies planet = search(planetName); planet.setGravity(amount); }
// GameObject[] _objects; void Start() { string[] lines = System.IO.File.ReadAllLines(@"planetsInfo.txt"); celestialBodies = new List <CelestialBodies>(); for (int i = 0; i < lines.Length; i++) { CelestialBodies c = GameObject.Find(lines[i]).GetComponent <CelestialBodies>(); //find all planet objects by their names PlanetInfo info = new PlanetInfo(); c.setName(lines[i]); c.setType("Planet"); i++; string[] words = lines[i].Split(' '); float volume = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setVolume(volume); //-------------------------------------------------------------- i++; words = lines[i].Split(' '); float radius = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setRadius(radius); //---------------------------------------------------------------- i++; words = lines[i].Split(' '); float circumference = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setCircumference(circumference); //------------------------------------------------------------- i++; words = lines[i].Split(' '); float mass = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setMass(mass); //---------------------------------------------------------------- i++; words = lines[i].Split('*'); info.setSurface(words[1]); //--------------------------------------------------------------------- i++; words = lines[i].Split(' '); float avergTemperature = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setAverageTemperature(avergTemperature); //-------------------------------------------------------------------- i++; words = lines[i].Split('*'); info.setPositionFromSun(words[1]); //-------------------------------------------------------------------------- i++; words = lines[i].Split(' '); int orbitalPeriod = Convert.ToInt32(words[1]); info.setOrbitalPeriod(orbitalPeriod); // print(words[1]); //------------------------------------------------------------------------------ i++; words = lines[i].Split('*'); info.setDayHours(words[1]); //--------------------------------------------------------------------------- i++; words = lines[i].Split(' '); int numberOfMoons = Convert.ToInt32(words[1]); info.setNumberOfMoons(numberOfMoons); //print(words[1]); //-------------------------------------------------------------------------- i++; //lightspeed //--------------------------------------------------------------------------- i++; words = lines[i].Split(' '); float gravity = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); c.setGravity(gravity); //------------------------------------------------------------------------------ i++; words = lines[i].Split(' '); float distanceFromSun = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat); info.setDistanceFromSun(distanceFromSun); //--------------------------------------------------------------------- i++; c.setInfo(info); celestialBodies.Add(c); } // foreach (CelestialBodies c in celestialBodies) print(c.ToString()); }
void changeGravity(float amount, CelestialBodies planet) { space.changeGravity(planet.name, amount); }
protected override void Draw(GameTime gameTime) { //FIX POSTPROCESSING spriteBatch.Begin(); spriteBatch.End(); BloomComponent.BeginDraw(); GraphicsDevice.Clear(Color.Black); for (int i = 0; i < CelestialBodies.Count; i++) { if (CelestialBodies[i].RenderWithBloom) { CelestialBodies[i].Render(); } } base.Draw(gameTime); Grid.Render(Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Matrix.CreateTranslation(new Vector3(CelestialBody.GLOBALX - 3500000, CelestialBody.GLOBALY, CelestialBody.GLOBALZ - 3500000))); GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.RasterizerState = RasterizerState.CullNone; GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; for (int i = 0; i < CelestialBodies.Count; i++) { CelestialBodies[i].DrawEllipsoid(); if (!CelestialBodies[i].RenderWithBloom) { spriteBatch.Begin(); spriteBatch.End(); var v1 = Vector3.Zero; var v2 = new Vector3((float)CelestialBodies[i].XCoord + CelestialBody.GLOBALX, (float)CelestialBodies[i].ZCoord + CelestialBody.GLOBALY, (float)CelestialBodies[i].YCoord + CelestialBody.GLOBALZ); var direction = v2 - v1; direction.Normalize(); Ray Ray = new Ray(Vector3.Zero, direction); CelestialBodies[i].IsAllowedToRender = !(Ray.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox) > 1) || (v2 - v1).Length() < (new Vector3(CelestialBody.GLOBALX, CelestialBody.GLOBALY, CelestialBody.GLOBALZ) - v1).Length(); CelestialBodies[i].Render(); } spriteBatch.Begin(); CelestialBodies[i].DrawInformation(spriteBatch); spriteBatch.End(); if (ShowDebug) { BoundingBoxRenderer.Render(CelestialBodies[i].BoundingBox, GraphicsDevice, Observer.Camera.ViewMatrix, Observer.Camera.ProjectionsMatrix, Color.Red); } } _total_frames++; if (ShowDebug) { spriteBatch.Begin(); Observer.Camera.RenderDebug(spriteBatch, DebugFont); CelestialBody.DrawDebug(spriteBatch, DebugFont); spriteBatch.DrawString(DebugFont, fps + " frames per second", new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth - UI.Width - 150, 15), Color.White); spriteBatch.End(); } }
protected override void Update(GameTime gameTime) { _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds; ClickTimer += gameTime.ElapsedGameTime.TotalMilliseconds; if (_elapsed_time > 1000.0f) { fps = _total_frames; _total_frames = 0; _elapsed_time = 0.0f; SunCollisionActive = true; } InputManager.Update(); MouseInteraction.Update(); if (Mouse.GetState().LeftButton == ButtonState.Released) { LeftButtonPressed = false; } if (Mouse.GetState().RightButton == ButtonState.Pressed) { if (!RightButtonPressed) { Observer.Camera.MouseSensity = .00025f; MousePositionSpace = MouseInteraction.GetXZAtY(MouseInteraction.GetRay(GraphicsDevice, Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1f, 1000.0f), Observer.Camera.ViewMatrix), Observer.Camera.CameraPosition.Y); MousePositionSpace = new Vector3(MousePositionSpace.X - CelestialBody.GLOBALX, MousePositionSpace.Y - CelestialBody.GLOBALY, MousePositionSpace.Z - CelestialBody.GLOBALZ); RightButtonPressed = true; } Observer.Camera.SetLookAt(MousePositionSpace, Zoom); } if (Mouse.GetState().RightButton == ButtonState.Released) { Observer.Camera.MouseSensity = .0008f; RightButtonPressed = false; } if (MouseInteraction.IsScrollingUp) { Zoom -= 5.5f; Observer.Camera.Move(new Vector3(0, 0, -5.5f)); } if (MouseInteraction.IsScrollingDown) { Zoom += 5.5f; Observer.Camera.Move(new Vector3(0, 0, 5.5f)); } Observer.Camera.Update(); CelestialBody.GLOBALX = Observer.Camera.CameraPosition.X; CelestialBody.GLOBALY = Observer.Camera.CameraPosition.Y; CelestialBody.GLOBALZ = Observer.Camera.CameraPosition.Z; for (int i = 0; i < CelestialBodies.Count; i++) { CelestialBodies[i].Update(gameTime); if (SunCollisionActive) { if (CelestialBodies[i].Name != "Sun") { if (CelestialBodies[i].BoundingBox.Intersects(CelestialBodies.Find(p => p.Name == "Sun").BoundingBox)) { CelestialBodies.RemoveAt(i); } } } } if (Mouse.GetState().LeftButton == ButtonState.Pressed) { if (!LeftButtonPressed) { LeftButtonPressed = true; Ray r = ToolKit.CalculateRay(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Observer.Camera.ViewMatrix, Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.01f, 150000.0f), GraphicsDevice.Viewport); if (ClickTimer < TimerDelay) { for (int i = 0; i < CelestialBodies.Count; i++) { if (r.Intersects(CelestialBodies[i].BoundingBox) > 1) { Observer.Camera.Flush(); UI.SetPlanet(CelestialBodies[i]); CelestialBodies[i].Follow(); break; } } } else { for (int i = 0; i < CelestialBodies.Count; i++) { if (r.Intersects(CelestialBodies[i].BoundingBox) > 1) { UI.SetPlanet(CelestialBodies[i]); CelestialBodies[i].SetFocus(); break; } } } ClickTimer = 0; } } UI.UpdateQR(gameTime); CelestialBodies = CelestialBodies.OrderByDescending(p => p.DistanceToObserver).ToList(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (CelestialBodies != null) { //draw lines var bodies = CelestialBodies.Where(b => !string.IsNullOrWhiteSpace(b.Name)).ToDictionary(b => b.Name); foreach (var body in bodies.Select(b => b.Value)) { foreach (string neighbour in body.Neighbours) { Pen pen = new Pen(Color.Cyan); if (body.IsMarked && bodies[neighbour].IsMarked) { pen = new Pen(Color.Red); } e.Graphics.DrawLine( pen, (float)body.X, (float)body.Y, (float)bodies[neighbour].X, (float)bodies[neighbour].Y ); } } foreach (CelestialBody body in CelestialBodies) { //draw planets & astroids Color penColour = Color.FromName(body.Colour); if (body.IsMarked) { penColour = Color.Red; } if (!penColour.IsKnownColor) { penColour = Color.DarkGray; } e.Graphics.FillEllipse( new SolidBrush(penColour), new RectangleF( (float)(body.X - body.Radius), (float)(body.Y - body.Radius), (float)body.Radius * 2, (float)body.Radius * 2 ) ); } if (Rectangles?.Count > 0) { //draw rectangles for collision bounds foreach (Rectangle rectangle in Rectangles) { e.Graphics.DrawRectangle( new Pen(Color.Red), rectangle ); } } } }