Split CameraModule into Components and Controller

wip/source-generators
copygirl 2 years ago
parent 594433a0ad
commit 8c5c5260c2
  1. 7
      src/Immersion/Program.cs
  2. 34
      src/gaemstone.Client/Modules/CameraComponents.cs
  3. 38
      src/gaemstone.Client/Modules/CameraController.cs
  4. 2
      src/gaemstone.Client/Modules/Renderer.cs

@ -8,7 +8,8 @@ using Silk.NET.Maths;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using static flecs_hub.flecs;
using static gaemstone.Client.CameraModule;
using static gaemstone.Client.CameraComponents;
using static gaemstone.Client.FreeCameraController;
using static gaemstone.Client.Input;
using static gaemstone.Client.Windowing;
@ -36,8 +37,10 @@ universe.RegisterComponent<Mesh>();
universe.RegisterComponent<gaemstone.Client.Texture>();
universe.RegisterComponent<TextureCoords4>();
universe.RegisterModule<CameraComponents>();
universe.RegisterModule<FreeCameraController>();
universe.RegisterModule<Input>();
universe.RegisterModule<CameraModule>();
universe.RegisterModule<Renderer>();
game.Set(new RawInput());

@ -0,0 +1,34 @@
using gaemstone.ECS;
using Silk.NET.Maths;
namespace gaemstone.Client;
[Module]
[DependsOn(typeof(Input))]
public class CameraComponents
{
[Component]
public struct Camera
{
public static readonly Camera Default2D = Create2D();
public static readonly Camera Default3D = Create3D(80.0F);
public static Camera Create2D(float nearPlane = -100.0F, float farPlane = 100.0F)
=> new() { NearPlane = nearPlane, FarPlane = farPlane };
public static Camera Create3D(float fieldOfView, float nearPlane = 0.1F, float farPlane = 200.0F)
=> new() { FieldOfView = fieldOfView, NearPlane = nearPlane, FarPlane = farPlane };
public float FieldOfView { get; set; }
public float NearPlane { get; set; }
public float FarPlane { get; set; }
public bool IsOrthographic => (FieldOfView == 0.0F);
}
[Component]
public struct CameraViewport
{
public Vector4D<byte> ClearColor { get; set; }
public Rectangle<int> Viewport { get; set; }
}
}

@ -2,39 +2,16 @@ using System;
using gaemstone.ECS;
using Silk.NET.Input;
using Silk.NET.Maths;
using static gaemstone.Client.CameraComponents;
using static gaemstone.Client.Input;
namespace gaemstone.Client;
[Module]
[DependsOn(typeof(CameraComponents))]
[DependsOn(typeof(Input))]
public class CameraModule
public class FreeCameraController
{
[Component]
public struct Camera
{
public static readonly Camera Default2D = Create2D();
public static readonly Camera Default3D = Create3D(80.0F);
public static Camera Create2D(float nearPlane = -100.0F, float farPlane = 100.0F)
=> new() { NearPlane = nearPlane, FarPlane = farPlane };
public static Camera Create3D(float fieldOfView, float nearPlane = 0.1F, float farPlane = 200.0F)
=> new() { FieldOfView = fieldOfView, NearPlane = nearPlane, FarPlane = farPlane };
public float FieldOfView { get; set; }
public float NearPlane { get; set; }
public float FarPlane { get; set; }
public bool IsOrthographic => (FieldOfView == 0.0F);
}
[Component]
public struct CameraViewport
{
public Vector4D<byte> ClearColor { get; set; }
public Rectangle<int> Viewport { get; set; }
}
[Component]
public struct CameraController
{
@ -54,10 +31,11 @@ public class CameraModule
else controller.MouseGrabbedAt = null;
}
if (controller.MouseGrabbedAt is not Vector2D<float> pos) return;
var mouseMoved = input.MousePosition - pos;
input.Context!.Mice[0].Position = pos.ToSystem();
var mouseMoved = Vector2D<float>.Zero;
if (controller.MouseGrabbedAt is Vector2D<float> pos) {
mouseMoved = input.MousePosition - pos;
input.Context!.Mice[0].Position = pos.ToSystem();
}
var dt = (float)delta.TotalSeconds;
var xMovement = mouseMoved.X * dt * controller.MouseSensitivity;

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
using gaemstone.ECS;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
using static gaemstone.Client.CameraModule;
using static gaemstone.Client.CameraComponents;
using static gaemstone.Client.Windowing;
namespace gaemstone.Client;

Loading…
Cancel
Save