Browse Source

update for CSM implementation

pull/1/head
cosmonaut 8 months ago
parent
commit
cf2e6d7ce6
7 changed files with 42 additions and 64 deletions
  1. +1
    -1
      Kav
  2. +10
    -5
      KavTest/Components/CameraComponent.cs
  3. +3
    -3
      KavTest/Engines/CameraEngine.cs
  4. +3
    -3
      KavTest/Engines/InputEngine.cs
  5. +6
    -8
      KavTest/KavTestGame.cs
  6. +17
    -7
      KavTest/Renderers/SceneRenderer.cs
  7. +2
    -37
      README.md

+ 1
- 1
Kav

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

+ 10
- 5
KavTest/Components/CameraComponent.cs View File

@ -1,15 +1,20 @@
using Encompass;
using Microsoft.Xna.Framework;
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;
}
}
}

+ 3
- 3
KavTest/Engines/CameraEngine.cs View File

@ -4,16 +4,16 @@ using KavTest.Messages;
namespace KavTest.Engines
{
[Reads(typeof(CameraComponent), typeof(ArcballTransformComponent))]
[Reads(typeof(PerspectiveCameraComponent), typeof(ArcballTransformComponent))]
[Receives(typeof(MoveCameraMessage), typeof(RotateCameraMessage))]
[Writes(typeof(ArcballTransformComponent))]
public class CameraEngine : Engine
{
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 transform = arcballTransformComponent.ArcballTransform;


+ 3
- 3
KavTest/Engines/InputEngine.cs View File

@ -6,7 +6,7 @@ using Microsoft.Xna.Framework.Input;
namespace KavTest.Engines
{
[Reads(typeof(CameraComponent))]
[Reads(typeof(PerspectiveCameraComponent))]
[Sends(
typeof(MoveCameraMessage),
typeof(RotateCameraMessage)
@ -47,9 +47,9 @@ namespace KavTest.Engines
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));
}
}


+ 6
- 8
KavTest/KavTestGame.cs View File

@ -107,7 +107,7 @@ namespace KavTest
}
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,
0.1f
));
@ -132,13 +132,11 @@ namespace KavTest
0
)
));
WorldBuilder.SetComponent(cameraEntity, new CameraComponent(
Matrix.CreatePerspectiveFieldOfView(
Microsoft.Xna.Framework.MathHelper.PiOver4,
16f / 9f,
0.1f,
100f
)
WorldBuilder.SetComponent(cameraEntity, new PerspectiveCameraComponent(
Microsoft.Xna.Framework.MathHelper.PiOver4,
16f / 9f,
0.01f,
100f
));
World = WorldBuilder.Build();


+ 17
- 7
KavTest/Renderers/SceneRenderer.cs View File

@ -75,20 +75,30 @@ namespace KavTest.Renderers
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()
{
if (SomeComponent<CameraComponent>())
if (SomeComponent<PerspectiveCameraComponent>())
{
var cameraEntity = ReadEntity<CameraComponent>();
var cameraEntity = ReadEntity<PerspectiveCameraComponent>();
var transformComponent = GetComponent<ArcballTransformComponent>(cameraEntity);
var cameraComponent = GetComponent<CameraComponent>(cameraEntity);
var cameraComponent = GetComponent<PerspectiveCameraComponent>(cameraEntity);
var camera = new Kav.Camera(
transformComponent.ArcballTransform.TransformMatrix,
cameraComponent.Projection
var camera = new Kav.PerspectiveCamera(
transformComponent.ArcballTransform.Position,
transformComponent.ArcballTransform.Forward,
transformComponent.ArcballTransform.Up,
cameraComponent.FieldOfView,
cameraComponent.AspectRatio,
cameraComponent.NearPlane,
cameraComponent.FarPlane
);
// if (SomeComponent<DirectionalLightComponent>())


+ 2
- 37
README.md 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.
## 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.
Test project to develop Kav.

Loading…
Cancel
Save