/// <summary> /// Creates a new editor presenter /// </summary> /// <param name="engine">The engine to use for rendering</param> /// <param name="universe">The universe to display</param> /// <param name="lighting">Shall lighting be used for rendering?</param> public EditorPresenter(Engine engine, Universe universe, bool lighting) : base(engine, universe) { #region Sanity checks if (engine == null) { throw new ArgumentNullException(nameof(engine)); } if (universe == null) { throw new ArgumentNullException(nameof(universe)); } #endregion Lighting = lighting; // Restore previous camera position (or default to center of terrain) var mainCamera = CreateCamera(universe.CurrentCamera); View = new View(Scene, mainCamera) { Name = "Editor", BackgroundColor = universe.FogColor }; // Floating axis-arrows for easier orientation var axisArrows = new FloatingModel(XMesh.Get(engine, "Engine/AxisArrows.x")) { Name = "AxisArrows", Alpha = 160, Position = new DoubleVector3(-16, -12, 40), Rotation = Quaternion.RotationYawPitchRoll(0, 0, 0) }; axisArrows.SetScale(0.03f); View.FloatingModels.Add(axisArrows); }
/// <inheritdoc/> public override void Click(MouseEventArgs e, bool accumulate) { #region Sanity checks if (e == null) { throw new ArgumentNullException(nameof(e)); } #endregion if (TerrainBrush != null) { if (TerrainPaint != null && e.Button == MouseButtons.Left) { // Determine the point the user click on and "paint" on it DoubleVector3 paintPoint; if (Terrain.Intersects(View.PickingRay(e.Location), out paintPoint)) { TerrainPaint(paintPoint.Flatten(), true); } } } else { base.Click(e, accumulate); } }
/// <summary> /// Creates a new presenter for the actual running game /// </summary> /// <param name="engine">The engine to use for rendering</param> /// <param name="universe">The universe to display</param> public InGamePresenter(Engine engine, Universe universe) : base(engine, universe) { #region Sanity checks if (engine == null) { throw new ArgumentNullException(nameof(engine)); } if (universe == null) { throw new ArgumentNullException(nameof(universe)); } #endregion // Restore previous camera position (or default to center of terrain) var mainCamera = CreateCamera(universe.CurrentCamera); View = new View(Scene, mainCamera) { Name = "InGame", BackgroundColor = universe.FogColor }; }
/// <inheritdoc/> public override void AreaSelection(Rectangle area, bool accumulate, bool done) { if (TerrainBrush != null) { if (TerrainPaint != null) { DoubleVector3 paintPoint; if (Terrain.Intersects(View.PickingRay(new Point(area.Right, area.Bottom)), out paintPoint)) { // Determine the terrain point at the location the user is currently "selecting" and "paint" on it TerrainPaint(paintPoint.Flatten(), done); } else if (done) { // If there is no terrain where the user is currently "selecting" finish running "paint" operations with a null operation (indicated by negative value) TerrainPaint(new Vector2(-1), true); } } } else { base.AreaSelection(area, accumulate, done); } }
/// <inheritdoc/> public override void Hover(Point target) { if (!TerrainBrush.HasValue) { return; } DoubleVector3 hoverPoint; if (Terrain.Intersects(View.PickingRay(target), out hoverPoint)) { // ToDo: Make steps discrete _terrainPaintingBrushCircle.Position = _terrainPaintingBrushSquare.Position = hoverPoint; _terrainPaintingBrushCircle.Visible = TerrainBrush.Value.Circle; _terrainPaintingBrushSquare.Visible = !TerrainBrush.Value.Circle; } else { _terrainPaintingBrushCircle.Visible = _terrainPaintingBrushSquare.Visible = false; } }
/// <summary> /// Switches from the current camera view to a new view using a cinematic effect. /// </summary> /// <param name="name">The <see cref="Positionable{TCoordinates}.Name"/> of a <see cref="CameraState{TCoordinates}"/> stored in the <see cref="PresenterBase{TUniverse,TCoordinates}.Universe"/>.</param> public void SwingCameraTo(string name) { View.SwingCameraTo(CreateCamera(Universe.GetCamera(name)), duration: 4); }