forked from copygirl/gaemstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- GFX initialization moved to Game.OnLoad - Renderer processor doesn't update Camera anymore - Rename MainCamera => FullscreenCamera - Add Universe.Has method
- Loading branch information
Showing
7 changed files
with
76 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Numerics; | ||
using gaemstone.Client.Components; | ||
using gaemstone.Common.ECS; | ||
using gaemstone.Common.ECS.Processors; | ||
|
||
namespace gaemstone.Client.Graphics | ||
{ | ||
public class UpdateCameraOnResize | ||
: IProcessor | ||
{ | ||
private Game _game = null!; | ||
private bool _update; | ||
|
||
public void OnLoad(Universe universe) | ||
{ | ||
_game = (Game)universe; | ||
_game.Window.Resize += OnWindowResize; | ||
_update = true; | ||
} | ||
|
||
public void OnUnload() | ||
=> _game.Window.Resize -= OnWindowResize; | ||
|
||
public void OnWindowResize(Size size) | ||
=> _update = true; | ||
|
||
public void OnUpdate(double delta) | ||
{ | ||
var size = _game.Window.Size; | ||
foreach (var (entity, fsCamera) in _game.GetAll<FullscreenCamera>()) { | ||
// Only update cameras when _update is true, or | ||
// entity doesn't yet have a Camera component. | ||
if (!_update && _game.Has<Camera>(entity)) continue; | ||
|
||
_game.Set(entity, new Camera { | ||
Viewport = new Rectangle(Point.Empty, size), | ||
Matrix = fsCamera.IsOrthographic | ||
? Matrix4x4.CreateOrthographic(size.Width, size.Height, | ||
fsCamera.NearPlane, fsCamera.FarPlane) | ||
: Matrix4x4.CreatePerspectiveFieldOfView( | ||
fsCamera.FieldOfView * MathF.PI / 180, // Degrees => Radians | ||
(float)size.Width / size.Height, // Aspect Ratio | ||
fsCamera.NearPlane, fsCamera.FarPlane) | ||
}); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters