summaryrefslogtreecommitdiff
path: root/Plugin.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Plugin.cs')
-rwxr-xr-xPlugin.cs147
1 files changed, 94 insertions, 53 deletions
diff --git a/Plugin.cs b/Plugin.cs
index 458b659..8553cea 100755
--- a/Plugin.cs
+++ b/Plugin.cs
@@ -15,12 +15,15 @@ using SharpPluginLoader.Core.Configuration;
using System.Diagnostics;
#endif
+// @TODO:
+// FEATURE: Figure out how to disable gravity.
+
namespace MHWNewCamera
{
public unsafe class Plugin : IPlugin
{
public string Name => "MHW New Camera";
- public string Author => "pizza";
+ public string Author => "Akon City Software";
private const float DEFAULT_FOV = 60.0f;
@@ -246,7 +249,13 @@ namespace MHWNewCamera
{
camera.AspectRatio = vp.Region.Height / (float)vp.Region.Width;
// Increase FOV for culling then set it back in CalculateViewHook.
- camera.FieldOfView *= 2.0f;
+ // * 2.0f breaks at higher FOV's and if the FOV goes over 180.0f I think it wraps
+ // around causing more culling.
+ camera.FieldOfView *= 1.5f;
+ if (camera.FieldOfView >= 180.0f)
+ {
+ camera.FieldOfView = 179.9f;
+ }
resetFovInView = true;
}
@@ -310,7 +319,7 @@ namespace MHWNewCamera
if (updateView)
{
Camera? camera;
- if ((camera = freeCamera ? vp.Camera : targetCamera) != null)
+ if ((camera = (freeCamera ? vp.Camera : targetCamera)) != null)
{
camera.FieldOfView = cameraFov;
}
@@ -356,9 +365,9 @@ namespace MHWNewCamera
ImGui.PushID("Perspective");
ImGui.DragFloat("Field of View", ref cameraFov, 0.4f, 1.0f, 180.0f);
- ImGui.DragFloat("Forward", ref cameraForward, 0.4f, -360.0f, 360.0f);
- ImGui.DragFloat("Left", ref cameraLeft, 0.4f, -360.0f, 360.0f);
- ImGui.DragFloat("Up", ref cameraYOffset, 0.4f, -360.0f, 360.0f);
+ ImGui.DragFloat("Forward", ref cameraForward, 0.4f);
+ ImGui.DragFloat("Left", ref cameraLeft, 0.4f);
+ ImGui.DragFloat("Up", ref cameraYOffset, 0.4f);
if (ImGui.Button("Default"))
{
cameraFov = DEFAULT_FOV;
@@ -500,53 +509,88 @@ namespace MHWNewCamera
ImGui.PushID("Camera");
ImGui.Text("Camera/Viewport:");
Viewport vp;
- for (int i = 0; i < 1; i++)
+ for (int i = 0; i < 8; i++)
{
- vp = CameraSystem.GetViewport(i);
- ImGui.Text($"Pointer: {vp.Instance:x}");
- ImGui.Text($"Visible: {vp.Visible}");
- ImGui.Text($"Region: {vp.Region.X} {vp.Region.Y} {vp.Region.Width} {vp.Region.Height}");
- if (vp.Camera != null)
+ if (ImGui.CollapsingHeader($"Camera #{i}"))
{
- ImGui.InputFloat("X Offset", ref cameraXOffset);
- ImGui.InputFloat("Y Offset", ref cameraYOffset);
- ImGui.InputFloat("Z Offset", ref cameraZOffset);
- ImGui.Text($"Camera Pointer: {vp.Camera.Instance:x}");
- ImGui.InputFloat("FOV", ref vp.Camera.FieldOfView);
- ImGui.Text($"Internal FOV: {previousFov}");
- if (ImGui.BeginItemTooltip())
- {
- ImGui.Text("What the FOV would be if not set by us.");
- ImGui.EndTooltip();
- }
- ImGui.InputFloat("Aspect Ratio", ref vp.Camera.AspectRatio);
- ImGui.InputFloat("Far Clip", ref vp.Camera.FarClip);
- ImGui.InputFloat("Near Clip", ref vp.Camera.NearClip);
- ImGui.DragFloat3("Position", ref vp.Camera.Position, 0.45f);
- ImGui.DragFloat3("Target", ref vp.Camera.Target, 0.45f);
- ImGui.DragFloat3("Up", ref vp.Camera.Up, 0.45f);
- ImGui.Text("Rotation:");
- float pitch = cameraPitch;
- if (ImGui.InputFloat("Pitch", ref pitch, 0.25f))
- {
- cameraPitch = pitch;
- }
- float yaw = cameraYaw;
- if (ImGui.InputFloat("Yaw", ref yaw, 0.25f))
- {
- cameraYaw = yaw;
- }
- float roll = cameraRoll;
- if (ImGui.DragFloat("Roll", ref roll, 0.25f))
- {
- cameraRoll = roll;
- }
- float pitchLimit = cameraPitchLimit;
- if (ImGui.InputFloat("Pitch Limit", ref pitchLimit, 0.0f, 0.0f, null, ImGuiInputTextFlags.EnterReturnsTrue))
+ ImGui.PushID($"Camera{i}");
+ vp = CameraSystem.GetViewport(i);
+ ImGui.Text($"Pointer: {vp.Instance:x}");
+ ImGui.Text($"Visible: {vp.Visible}");
+ ImGui.Text($"Region: {vp.Region.X} {vp.Region.Y} {vp.Region.Width} {vp.Region.Height}");
+ if (vp.Camera != null)
{
- cameraPitchLimit = pitchLimit;
+ ImGui.InputFloat("X Offset", ref cameraXOffset);
+ ImGui.InputFloat("Y Offset", ref cameraYOffset);
+ ImGui.InputFloat("Z Offset", ref cameraZOffset);
+ var camera = vp.Camera;
+ ImGui.Text($"Camera Pointer: {camera.Instance:x}");
+ ImGui.DragFloat("FOV", ref camera.FieldOfView, 0.45f);
+ ImGui.Text($"Internal FOV: {previousFov}");
+ if (ImGui.BeginItemTooltip())
+ {
+ ImGui.Text("What the FOV would be if not set by us.");
+ ImGui.EndTooltip();
+ }
+ ImGui.InputFloat("Aspect Ratio", ref camera.AspectRatio);
+ ImGui.InputFloat("Far Clip", ref camera.FarClip);
+ ImGui.InputFloat("Near Clip", ref camera.NearClip);
+ ImGui.DragFloat3("Position", ref camera.Position, 0.45f);
+ ImGui.DragFloat3("Target", ref camera.Target, 0.45f);
+ ImGui.DragFloat3("Up", ref camera.Up, 0.45f);
+ ImGui.Text("Offset:");
+ float offsetForward = 0.0f;
+ if (ImGui.DragFloat("Forward", ref offsetForward, 0.45f))
+ {
+ Quaternion forward = getForward(camera.Position, camera.Target);
+ forward = Quaternion.Normalize(forward);
+ camera.Position.X += forward.X * offsetForward;
+ camera.Position.Y += forward.Y * offsetForward;
+ camera.Position.Z += forward.Z * offsetForward;
+ }
+ float offsetLeft = 0.0f;
+ if (ImGui.DragFloat("Left", ref offsetLeft, 0.45f))
+ {
+ Quaternion forward = getForward(camera.Position, camera.Target);
+ forward = Quaternion.Normalize(forward);
+ Quaternion left = forward * Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(Single.DegreesToRadians(180.0f)));
+ camera.Position.X += left.X * offsetLeft;
+ camera.Position.Z += left.Z * offsetLeft;
+ }
+ ImGui.Text("Rotation:");
+ float pitch = cameraPitch;
+ if (ImGui.InputFloat("Pitch", ref pitch, 0.25f))
+ {
+ cameraPitch = pitch;
+ }
+ float yaw = cameraYaw;
+ if (ImGui.InputFloat("Yaw", ref yaw, 0.25f))
+ {
+ cameraYaw = yaw;
+ }
+ float roll = cameraRoll;
+ if (ImGui.DragFloat("Roll", ref roll, 0.25f))
+ {
+ cameraRoll = roll;
+ }
+ float pitchLimit = cameraPitchLimit;
+ if (ImGui.InputFloat("Pitch Limit", ref pitchLimit, 0.0f, 0.0f, null, ImGuiInputTextFlags.EnterReturnsTrue))
+ {
+ cameraPitchLimit = pitchLimit;
+ }
+ bool move = camera.Move;
+ if (ImGui.Checkbox("Move", ref move))
+ {
+ camera.Move = move;
+ }
+ ImGui.SameLine();
+ bool fix = camera.Fix;
+ if (ImGui.Checkbox("Fix", ref fix))
+ {
+ camera.Fix = fix;
+ }
}
- ImGui.Text($"Move: {vp.Camera.Move}, Fix: {vp.Camera.Fix}");
+ ImGui.PopID();
}
}
ImGui.PopID();
@@ -854,10 +898,7 @@ namespace MHWNewCamera
float Rx = PadRx / (Int16.MaxValue / adjustedSensitivity);
float Ry = PadRy / (Int16.MaxValue / adjustedSensitivity);
cameraYaw += Rx;
- cameraPitch += Ry;
- float cap = cameraPitchLimit;
- if (cameraPitch > cap) cameraPitch = cap;
- else if (cameraPitch < -cap) cameraPitch = -cap;
+ cameraPitch = Math.Clamp(cameraPitch + Ry, -cameraPitchLimit, cameraPitchLimit);
camera.Target.X = camera.Position.X + ((float)Math.Cos(Single.DegreesToRadians(cameraPitch)) * (float)Math.Cos(Single.DegreesToRadians(cameraYaw)));
camera.Target.Y = camera.Position.Y + (float)Math.Sin(Single.DegreesToRadians(cameraPitch));
camera.Target.Z = camera.Position.Z + ((float)Math.Cos(Single.DegreesToRadians(cameraPitch)) * (float)Math.Sin(Single.DegreesToRadians(cameraYaw)));