update for CSM implementation

pull/1/head
cosmonaut 2020-09-19 01:06:50 -07:00
parent a92a8de50a
commit cf2e6d7ce6
7 changed files with 42 additions and 64 deletions

2
Kav

@ -1 +1 @@
Subproject commit 3540e098d55e3b8edc4e78504487576e07537ec8 Subproject commit 8cb760171745a7bc75ff56d88f0773dc55e2f2e3

View File

@ -1,15 +1,20 @@
using Encompass; using Encompass;
using Microsoft.Xna.Framework;
namespace KavTest.Components namespace KavTest.Components
{ {
public struct CameraComponent : IComponent public struct PerspectiveCameraComponent : IComponent
{ {
public Matrix Projection { get; } public float FieldOfView { get; }
public float AspectRatio { get; }
public float NearPlane { get; }
public float FarPlane { get; }
public CameraComponent(Matrix projection) public PerspectiveCameraComponent(float fieldOfView, float aspectRatio, float nearPlane, float farPlane)
{ {
Projection = projection; FieldOfView = fieldOfView;
AspectRatio = aspectRatio;
NearPlane = nearPlane;
FarPlane = farPlane;
} }
} }
} }

View File

@ -4,16 +4,16 @@ using KavTest.Messages;
namespace KavTest.Engines namespace KavTest.Engines
{ {
[Reads(typeof(CameraComponent), typeof(ArcballTransformComponent))] [Reads(typeof(PerspectiveCameraComponent), typeof(ArcballTransformComponent))]
[Receives(typeof(MoveCameraMessage), typeof(RotateCameraMessage))] [Receives(typeof(MoveCameraMessage), typeof(RotateCameraMessage))]
[Writes(typeof(ArcballTransformComponent))] [Writes(typeof(ArcballTransformComponent))]
public class CameraEngine : Engine public class CameraEngine : Engine
{ {
public override void Update(double dt) public override void Update(double dt)
{ {
if (SomeComponent<CameraComponent>()) if (SomeComponent<PerspectiveCameraComponent>())
{ {
var cameraEntity = ReadEntity<CameraComponent>(); var cameraEntity = ReadEntity<PerspectiveCameraComponent>();
var arcballTransformComponent = GetComponent<ArcballTransformComponent>(cameraEntity); var arcballTransformComponent = GetComponent<ArcballTransformComponent>(cameraEntity);
var transform = arcballTransformComponent.ArcballTransform; var transform = arcballTransformComponent.ArcballTransform;

View File

@ -6,7 +6,7 @@ using Microsoft.Xna.Framework.Input;
namespace KavTest.Engines namespace KavTest.Engines
{ {
[Reads(typeof(CameraComponent))] [Reads(typeof(PerspectiveCameraComponent))]
[Sends( [Sends(
typeof(MoveCameraMessage), typeof(MoveCameraMessage),
typeof(RotateCameraMessage) typeof(RotateCameraMessage)
@ -47,9 +47,9 @@ namespace KavTest.Engines
if (Game.IsActive) if (Game.IsActive)
{ {
if (SomeComponent<CameraComponent>()) if (SomeComponent<PerspectiveCameraComponent>())
{ {
var cameraEntity = ReadEntity<CameraComponent>(); var cameraEntity = ReadEntity<PerspectiveCameraComponent>();
SendMessage(new RotateCameraMessage(cameraEntity, -mouseState.X, -mouseState.Y)); SendMessage(new RotateCameraMessage(cameraEntity, -mouseState.X, -mouseState.Y));
} }
} }

View File

@ -107,7 +107,7 @@ namespace KavTest
} }
WorldBuilder.SendMessage(new DirectionalLightSpawnMessage( WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2 + 0.1f), Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver4),
Color.GhostWhite, Color.GhostWhite,
0.1f 0.1f
)); ));
@ -132,13 +132,11 @@ namespace KavTest
0 0
) )
)); ));
WorldBuilder.SetComponent(cameraEntity, new CameraComponent( WorldBuilder.SetComponent(cameraEntity, new PerspectiveCameraComponent(
Matrix.CreatePerspectiveFieldOfView(
Microsoft.Xna.Framework.MathHelper.PiOver4, Microsoft.Xna.Framework.MathHelper.PiOver4,
16f / 9f, 16f / 9f,
0.1f, 0.01f,
100f 100f
)
)); ));
World = WorldBuilder.Build(); World = WorldBuilder.Build();

View File

@ -75,20 +75,30 @@ namespace KavTest.Renderers
public SceneRenderer(GraphicsDevice graphicsDevice) public SceneRenderer(GraphicsDevice graphicsDevice)
{ {
Renderer = new Kav.Renderer(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight); Renderer = new Kav.Renderer(
graphicsDevice,
graphicsDevice.PresentationParameters.BackBufferWidth,
graphicsDevice.PresentationParameters.BackBufferHeight,
3
);
} }
public override void Render() public override void Render()
{ {
if (SomeComponent<CameraComponent>()) if (SomeComponent<PerspectiveCameraComponent>())
{ {
var cameraEntity = ReadEntity<CameraComponent>(); var cameraEntity = ReadEntity<PerspectiveCameraComponent>();
var transformComponent = GetComponent<ArcballTransformComponent>(cameraEntity); var transformComponent = GetComponent<ArcballTransformComponent>(cameraEntity);
var cameraComponent = GetComponent<CameraComponent>(cameraEntity); var cameraComponent = GetComponent<PerspectiveCameraComponent>(cameraEntity);
var camera = new Kav.Camera( var camera = new Kav.PerspectiveCamera(
transformComponent.ArcballTransform.TransformMatrix, transformComponent.ArcballTransform.Position,
cameraComponent.Projection transformComponent.ArcballTransform.Forward,
transformComponent.ArcballTransform.Up,
cameraComponent.FieldOfView,
cameraComponent.AspectRatio,
cameraComponent.NearPlane,
cameraComponent.FarPlane
); );
// if (SomeComponent<DirectionalLightComponent>()) // if (SomeComponent<DirectionalLightComponent>())

View File

@ -1,38 +1,3 @@
# Encompass-FNA-Template # KavTest
Template (and VSCode build tasks) for developing a cross-platform multi-target .NET Framework and .NET Core game using Encompass and FNA. Test project to develop Kav.
## Features
- Includes project boilerplate code
- Build tasks for both .NET Framework and .NET Core side by side
- Press F5 to build and debug in-editor with Core Debugger
## Requirements
- [Git](https://git-scm.com/)
- [Git for Windows](https://gitforwindows.org/) if on Windows
- [Visual Studio Code](https://code.visualstudio.com/)
- [VSCode C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
- [.NET Core SDK](https://dotnet.microsoft.com/download/dotnet-core)
- [.NET Framework SDK](https://dotnet.microsoft.com/download/visual-studio-sdks) or [Mono](https://www.mono-project.com/)
## Installation
- Make sure you have Git Bash from Git for Windows if you are on Windows
- Download this repository
- Run `install.sh`
- Move the newly created project directory wherever you want
## Usage
- Open the project directory in VSCode
- Press Ctrl-Shift-B to open the build tasks menu
- `Framework` tasks use .NET Framework or Mono to build and run
- `Core` tasks use .NET Core to build and run
- Press F5 to build and debug with Core Debugger
## Acknowledgments
Thanks to Andrew Russell and Caleb Cornett's FNA templates for a starting point for this template.