just ctrl s

This commit is contained in:
4sval 2022-08-25 20:27:35 +02:00
parent 0f120f26ea
commit 9b967341c2
5 changed files with 138 additions and 0 deletions

View File

@ -121,6 +121,9 @@
<PackageReference Include="RestSharp" Version="108.0.1" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Silk.NET.Input" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL" Version="2.16.0" />
<PackageReference Include="Silk.NET.Windowing" Version="2.16.0" />
<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.0" />
<PackageReference Include="SkiaSharp.Svg" Version="1.60.0" />
</ItemGroup>

View File

@ -100,4 +100,9 @@ public static class Helper
var d = (Math.Abs(d1) + Math.Abs(d2) + 10) * 1.0e-15;
return -d < n && d > n;
}
public static float DegreesToRadians(float degrees)
{
return MathF.PI / 180f * degrees;
}
}

View File

@ -11,6 +11,7 @@ using FModel.Settings;
using FModel.ViewModels;
using FModel.Views;
using FModel.Views.Resources.Controls;
using FModel.Views.Snooper;
using ICSharpCode.AvalonEdit.Editing;
namespace FModel;
@ -52,6 +53,10 @@ public partial class MainWindow
ApplicationService.ApiEndpointView.FModelApi.CheckForUpdates(UserSettings.Default.UpdateMode);
#endif
var v = new Viewer();
v.Run();
return;
switch (UserSettings.Default.AesReload)
{
case EAesReload.Always:

View File

@ -0,0 +1,58 @@
using System;
using System.Numerics;
namespace FModel.Views.Snooper;
public class Camera
{
public Vector3 Position { get; set; }
public Vector3 Front { get; set; }
public Vector3 Up { get; private set; }
public float AspectRatio { get; set; }
public float Yaw { get; set; } = -90f;
public float Pitch { get; set; }
private float Zoom = 45f;
public Camera(Vector3 position, Vector3 front, Vector3 up, float aspectRatio)
{
Position = position;
AspectRatio = aspectRatio;
Front = front;
Up = up;
}
public void ModifyZoom(float zoomAmount)
{
//We don't want to be able to zoom in too close or too far away so clamp to these values
Zoom = Math.Clamp(Zoom - zoomAmount, 1.0f, 45f);
}
public void ModifyDirection(float xOffset, float yOffset)
{
Yaw += xOffset;
Pitch -= yOffset;
//We don't want to be able to look behind us by going over our head or under our feet so make sure it stays within these bounds
Pitch = Math.Clamp(Pitch, -89f, 89f);
var cameraDirection = Vector3.Zero;
cameraDirection.X = MathF.Cos(Helper.DegreesToRadians(Yaw)) * MathF.Cos(Helper.DegreesToRadians(Pitch));
cameraDirection.Y = MathF.Sin(Helper.DegreesToRadians(Pitch));
cameraDirection.Z = MathF.Sin(Helper.DegreesToRadians(Yaw)) * MathF.Cos(Helper.DegreesToRadians(Pitch));
Front = Vector3.Normalize(cameraDirection);
}
public Matrix4x4 GetViewMatrix()
{
return Matrix4x4.CreateLookAt(Position, Position + Front, Up);
}
public Matrix4x4 GetProjectionMatrix()
{
return Matrix4x4.CreatePerspectiveFieldOfView(Helper.DegreesToRadians(Zoom), AspectRatio, 0.1f, 100.0f);
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Numerics;
using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
namespace FModel.Views.Snooper;
public class Viewer
{
private IWindow _window;
private GL _gl;
private Camera _camera;
private IKeyboard _keyboard;
public int Width { get; }
public int Height { get; }
private const double _ratio = .75;
public Viewer()
{
var x = System.Windows.SystemParameters.MaximizedPrimaryScreenWidth;
var y = System.Windows.SystemParameters.MaximizedPrimaryScreenHeight;
Width = Convert.ToInt32(x * _ratio);
Height = Convert.ToInt32(y * _ratio);
var options = WindowOptions.Default;
options.Size = new Vector2D<int>(Width, Height);
options.Title = "Snooper";
_window = Window.Create(options);
_window.Load += OnLoad;
_window.Closing += OnClose;
}
public void Run()
{
_window.Run();
}
private void OnLoad()
{
var input = _window.CreateInput();
_keyboard = input.Keyboards[0];
_keyboard.KeyDown += KeyDown;
_gl = GL.GetApi(_window);
//Start a camera at position 3 on the Z axis, looking at position -1 on the Z axis
_camera = new Camera(Vector3.UnitZ * 6, Vector3.UnitZ * -1, Vector3.UnitY, Width / Height);
}
private void OnClose()
{
}
private void KeyDown(IKeyboard keyboard, Key key, int arg3)
{
if (key == Key.Escape)
{
_window.Close();
}
}
}