Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vectors #57

Merged
merged 16 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class TextureManager : ITextureManager
{
[Dependency] private readonly IResourceLoader _resourceLoader = default!;

public ITexture CreateBlank(Vector2Int size, Color color)
public ITexture CreateBlank(Vector2i size, Color color)
{
var data = new byte[size.X * size.Y * 4];

Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/Viewports/Camera2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public sealed class Camera2D : ICamera
public Vector3 Position => _transform.Position;
public Vector3 Rotation => _transform.Rotation.ToEuler();
public Vector3 Scale => _transform.Scale;
public Vector2Int Size { get; private set; }
public Vector2i Size { get; private set; }

private readonly float _zFar;
private readonly float _zNear;

private Transform3 _transform = new();

public Camera2D(Vector2Int size, Vector2 position, float zNear, float zFar)
public Camera2D(Vector2i size, Vector2 position, float zNear, float zFar)
{
Size = size;
_zNear = zNear;
Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Client/Graphics/Viewports/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public void SetMainCamera(ICamera camera)
MainCamera = camera;
}

public ICamera CreateCamera2D(Vector2Int size)
public ICamera CreateCamera2D(Vector2i size)
{
return CreateCamera2D(size, Vector2.Zero);
}

public ICamera CreateCamera2D(Vector2Int size, Vector2 position, float zNear = 0.1f, float zFar = 100f)
public ICamera CreateCamera2D(Vector2i size, Vector2 position, float zNear = 0.1f, float zFar = 100f)
{
return new Camera2D(size, position, zNear, zFar);
}
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Viewports/ICamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ICamera
Vector3 Position { get; }
Vector3 Rotation { get; }
Vector3 Scale { get; }
Vector2Int Size { get; }
Vector2i Size { get; }

void SetPosition(Vector3 position);
void SetRotation(Vector3 rotation);
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Viewports/ICameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface ICameraManager


void SetMainCamera(ICamera camera);
ICamera CreateCamera2D(Vector2Int size);
ICamera CreateCamera2D(Vector2i size);
void UpdateInput(ICamera? camera, float delta);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public sealed class GlfwMonitorRegistration : MonitorHandle
public readonly Monitor* Pointer;


public GlfwMonitorRegistration(MonitorId id, string name, Vector2Int size, int refreshRate, VideoMode[] videoModes, Monitor* pointer) : base(id, name, size, refreshRate, videoModes)
public GlfwMonitorRegistration(MonitorId id, string name, Vector2i size, int refreshRate, VideoMode[] videoModes, Monitor* pointer) : base(id, name, size, refreshRate, videoModes)
{
Pointer = pointer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void WindowSetTitle(WindowHandle window, string title)

public void WindowSetMonitor(WindowHandle window, MonitorHandle registration)
{
WindowSetMonitor(window, registration, Vector2Int.Zero);
WindowSetMonitor(window, registration, Vector2i.Zero);
}

public void WindowRequestAttention(WindowHandle window)
Expand All @@ -217,7 +217,7 @@ public void WindowRequestAttention(WindowHandle window)
OpenTK.Windowing.GraphicsLibraryFramework.GLFW.RequestWindowAttention(glfwWindow);
}

public void WindowSetSize(WindowHandle window, Vector2Int size)
public void WindowSetSize(WindowHandle window, Vector2i size)
{
if (window is not GlfwWindowHandle glfwWindow)
return;
Expand Down Expand Up @@ -247,7 +247,7 @@ public void WindowSetOpacity(WindowHandle window, float opacity)
OpenTK.Windowing.GraphicsLibraryFramework.GLFW.SetWindowOpacity(glfwWindow, opacity);
}

public void WindowSetPosition(WindowHandle window, Vector2Int position)
public void WindowSetPosition(WindowHandle window, Vector2i position)
{
if (window is not GlfwWindowHandle glfwWindow)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public nint GetProcAddress(string procName)
return OpenTK.Windowing.GraphicsLibraryFramework.GLFW.GetProcAddress(procName);
}

public void WindowSetMonitor(WindowHandle window, MonitorHandle monitor, Vector2Int vector)
public void WindowSetMonitor(WindowHandle window, MonitorHandle monitor, Vector2i vector)
{
if (monitor is not GlfwMonitorRegistration glfwMonitor)
return;
Expand Down
1 change: 1 addition & 0 deletions Hypercube.Client/Hypercube.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<ProjectReference Include="..\Hypercube.Audio\Hypercube.Audio.csproj" />
<ProjectReference Include="..\Hypercube.ImGui\Hypercube.ImGui.csproj" />
<ProjectReference Include="..\Hypercube.Logging\Hypercube.Logging.csproj" />
<ProjectReference Include="..\Hypercube.Mathematics\Hypercube.Mathematics.csproj" />
<ProjectReference Include="..\Hypercube.OpenAL\Hypercube.OpenAL.csproj" />
<ProjectReference Include="..\Hypercube.OpenGL\Hypercube.OpenGL.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions Hypercube.Graphics/Monitors/MonitorHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public class MonitorHandle
{
public MonitorId Id { get; }
public string Name { get; }
public Vector2Int Size { get; }
public Vector2i Size { get; }
public int RefreshRate { get; }
public VideoMode[] VideoModes { get; }

public MonitorHandle(MonitorId id, string name, Vector2Int size, int refreshRate, VideoMode[] videoModes)
public MonitorHandle(MonitorId id, string name, Vector2i size, int refreshRate, VideoMode[] videoModes)
{
Id = id;
Name = name;
Expand All @@ -25,7 +25,7 @@ public MonitorHandle(MonitorId id, string name, int width, int height, int refre
{
Id = id;
Name = name;
Size = new Vector2Int(width, height);
Size = new Vector2i(width, height);
RefreshRate = refreshRate;
VideoModes = videoModes;
}
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Graphics/Shaders/IShaderProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IShaderProgram : IDisposable
void SetUniform(string name, double value);

void SetUniform(string name, Vector2 value);
void SetUniform(string name, Vector2Int value);
void SetUniform(string name, Vector2i value);
void SetUniform(string name, Vector3 value);

void SetUniform(string name, Matrix3X3 value, bool transpose = false);
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Graphics/Texturing/ITextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Hypercube.Graphics.Texturing;
[PublicAPI]
public interface ITextureManager
{
ITexture CreateBlank(Vector2Int size, Color color);
ITexture CreateBlank(Vector2i size, Color color);
ITexture CreateTexture(ResourcePath path);

ITextureHandle CreateTextureHandle(ITexture texture);
Expand Down
4 changes: 2 additions & 2 deletions Hypercube.Graphics/Texturing/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Hypercube.Graphics.Texturing;
public const int PixelPerUnit = 32;

public ResourcePath Path { get; }
public Vector2Int Size { get; }
public Vector2i Size { get; }

public byte[] Data { get; }

Expand All @@ -27,7 +27,7 @@ public Box2 Quad
}
}

public Texture(ResourcePath path, Vector2Int size, byte[] data)
public Texture(ResourcePath path, Vector2i size, byte[] data)
{
Path = path;
Size = size;
Expand Down
6 changes: 3 additions & 3 deletions Hypercube.Graphics/Windowing/IWindowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public interface IWindowing : IDisposable
void WindowDestroy(WindowHandle window);
void WindowSetTitle(WindowHandle window, string title);
void WindowSetMonitor(WindowHandle window, MonitorHandle monitor);
void WindowSetMonitor(WindowHandle window, MonitorHandle monitor, Vector2Int vector2Int);
void WindowSetMonitor(WindowHandle window, MonitorHandle monitor, Vector2i vector2I);
void WindowRequestAttention(WindowHandle window);
void WindowSetOpacity(WindowHandle window, float opacity);
void WindowSetVisible(WindowHandle window, bool visible);
void WindowSetSize(WindowHandle window, Vector2Int size);
void WindowSetPosition(WindowHandle window, Vector2Int position);
void WindowSetSize(WindowHandle window, Vector2i size);
void WindowSetPosition(WindowHandle window, Vector2i position);
void WindowSwapBuffers(WindowHandle window);
void WindowSetIcons(WindowHandle window, List<ITexture> images);

Expand Down
2 changes: 1 addition & 1 deletion Hypercube.Graphics/Windowing/WindowCreateSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class WindowCreateSettings
public int Height => Size.Y;

public string Title { get; init; } = "Hypercube Window";
public Vector2Int Size { get; init; } = new(1280, 720);
public Vector2i Size { get; init; } = new(1280, 720);

public ITexture[]? WindowImages { get; init; }
public MonitorHandle? Monitor { get; init; }
Expand Down
8 changes: 4 additions & 4 deletions Hypercube.Graphics/Windowing/WindowHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ public abstract class WindowHandle
public bool DisposeOnClose { get; }
public bool IsDisposed { get; }
public float Ratio { get; init; }
public Vector2Int Size { get; set; }
public Vector2Int FramebufferSize { get; init; }
public Vector2i Size { get; set; }
public Vector2i FramebufferSize { get; init; }

protected WindowHandle(WindowId id, nint pointer)
{
Id = id;
Pointer = pointer;
}

public void SetSize(Vector2Int size)
public void SetSize(Vector2i size)
{
Size = size;
}

public void SetSize(int width, int height)
{
Size = new Vector2Int(width, height);
Size = new Vector2i(width, height);
}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Hypercube.ImGui/IImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface IImGuiController : IImGui
void Render();

void InputFrame();
void UpdateMousePosition(Vector2Int position);
void UpdateMousePosition(Vector2i position);
void UpdateKey(Key key, KeyState state, KeyModifiers modifiers);
void UpdateMouseButtons(MouseButton button, KeyState state, KeyModifiers modifiers);
void UpdateMouseScroll(Vector2 offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void InputFrame()
{
}

public void UpdateMousePosition(Vector2Int position)
public void UpdateMousePosition(Vector2i position)
{
_io.MousePos = position;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void Render(ImDrawDataPtr data)
if (data.CmdListsCount == 0)
return;

var frameBufferSize = new Vector2Int(
var frameBufferSize = new Vector2i(
data.DisplaySize.X * data.FramebufferScale.X,
data.DisplaySize.Y * data.FramebufferScale.Y);

Expand Down Expand Up @@ -128,7 +128,7 @@ private void Render(ImDrawDataPtr data)
GL.Disable(EnableCap.ScissorTest);
}

private void SetupRender(ImDrawDataPtr data, Vector2Int frameBufferSize)
private void SetupRender(ImDrawDataPtr data, Vector2i frameBufferSize)
{
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.ScissorTest);
Expand Down
10 changes: 6 additions & 4 deletions Hypercube.Mathematics/Angle.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Hypercube.Mathematics.Extensions;
using Hypercube.Mathematics.Vectors;
using JetBrains.Annotations;

namespace Hypercube.Mathematics;

[PublicAPI, Serializable, StructLayout(LayoutKind.Sequential)]
public readonly struct Angle : IEquatable<Angle>, IEquatable<double>
{
public static readonly Angle Zero = new(0);
Expand All @@ -19,18 +22,17 @@ public double Degrees
public Vector2 Vector
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new((float)System.Math.Cos(Theta), (float)System.Math.Sin(Theta));
get => new(MathF.Cos((float) Theta), MathF.Sin((float) Theta));
}

public Angle(double theta)
{
Theta = theta;
}

public Angle(Vector2 vector2)
public Angle(Vector2 value)
{
vector2 = vector2.Normalized;
Theta = System.Math.Atan2(vector2.X, vector2.Y);
Theta = value.Angle;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
9 changes: 8 additions & 1 deletion Hypercube.Mathematics/HyperMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class HyperMath
{
public const double PI = System.Math.PI;
public const double PI = Math.PI;

public const double PIOver2 = PI / 2;
public const double PIOver4 = PI / 4;
Expand All @@ -13,4 +13,11 @@ public static class HyperMath

public const double RadiansToDegrees = 180 / PI;
public const double DegreesToRadians = PI / 180;

public static int MoveTowards(int current, int target, int distance)
{
return current < target ?
Math.Min(current + distance, target) :
Math.Max(current - distance, target);
}
}
7 changes: 7 additions & 0 deletions Hypercube.Mathematics/HyperMathF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public static class HyperMathF

public const float RadiansToDegrees = 180 / PI;
public const float DegreesToRadians = PI / 180;

public static float MoveTowards(float current, float target, float distance)
{
return current < target ?
MathF.Min(current + distance, target) :
MathF.Max(current - distance, target);
}
}
49 changes: 22 additions & 27 deletions Hypercube.Mathematics/Matrices/Matrix4X4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,38 +320,33 @@ public override string ToString()

public static Matrix4X4 operator *(Matrix4X4 a, Matrix4X4 b)
{
var result = Zero;

result.M00 = (a.Row0 * b.Column0).Sum();
result.M01 = (a.Row0 * b.Column1).Sum();
result.M02 = (a.Row0 * b.Column2).Sum();
result.M03 = (a.Row0 * b.Column3).Sum();

result.M10 = (a.Row1 * b.Column0).Sum();
result.M11 = (a.Row1 * b.Column1).Sum();
result.M12 = (a.Row1 * b.Column2).Sum();
result.M13 = (a.Row1 * b.Column3).Sum();

result.M20 = (a.Row2 * b.Column0).Sum();
result.M21 = (a.Row2 * b.Column1).Sum();
result.M22 = (a.Row2 * b.Column2).Sum();
result.M23 = (a.Row2 * b.Column3).Sum();

result.M30 = (a.Row3 * b.Column0).Sum();
result.M31 = (a.Row3 * b.Column1).Sum();
result.M32 = (a.Row3 * b.Column2).Sum();
result.M33 = (a.Row3 * b.Column3).Sum();

return result;
return new Matrix4X4(
(a.Row0 * b.Column0).Summation,
(a.Row0 * b.Column1).Summation,
(a.Row0 * b.Column2).Summation,
(a.Row0 * b.Column3).Summation,
(a.Row1 * b.Column0).Summation,
(a.Row1 * b.Column1).Summation,
(a.Row1 * b.Column2).Summation,
(a.Row1 * b.Column3).Summation,
(a.Row2 * b.Column0).Summation,
(a.Row2 * b.Column1).Summation,
(a.Row2 * b.Column2).Summation,
(a.Row2 * b.Column3).Summation,
(a.Row3 * b.Column0).Summation,
(a.Row3 * b.Column1).Summation,
(a.Row3 * b.Column2).Summation,
(a.Row3 * b.Column3).Summation
);
}

public static Vector4 operator *(Matrix4X4 a, Vector4 b)
{
return new Vector4(
(a.Row0 * b).Sum(),
(a.Row1 * b).Sum(),
(a.Row2 * b).Sum(),
(a.Row3 * b).Sum());
(a.Row0 * b).Summation,
(a.Row1 * b).Summation,
(a.Row2 * b).Summation,
(a.Row3 * b).Summation);
}

public static bool operator ==(Matrix4X4 a, Matrix4X4 b)
Expand Down
Loading
Loading