Skip to content

Commit

Permalink
Merge pull request #1385 from ergoxiv/hotfix/vector-and-quaternion-ex…
Browse files Browse the repository at this point in the history
…tensions

Simplified and optimized vector and quaternion use in Anamnesis
  • Loading branch information
StoiaCode authored Sep 13, 2024
2 parents 5f2adb8 + ae9b633 commit 01c21fd
Show file tree
Hide file tree
Showing 35 changed files with 226 additions and 794 deletions.
5 changes: 3 additions & 2 deletions Anamnesis/Actor/DefaultCharacterFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Anamnesis.Actor;

using Anamnesis.Files;
using Anamnesis.Memory;
using System.Numerics;

public static class DefaultCharacterFile
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public static class DefaultCharacterFile
MainHand = new CharacterFile.WeaponSave()
{
Color = Color.Black,
Scale = Vector.One,
Scale = Vector3.One,
ModelSet = 301,
ModelBase = 31,
ModelVariant = 1,
Expand All @@ -51,7 +52,7 @@ public static class DefaultCharacterFile
OffHand = new CharacterFile.WeaponSave()
{
Color = Color.Black,
Scale = Vector.One,
Scale = Vector3.One,
ModelSet = 301,
ModelBase = 31,
ModelVariant = 1,
Expand Down
5 changes: 3 additions & 2 deletions Anamnesis/Actor/Extensions/INpcBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

namespace Anamnesis.Actor;

using System;
using Anamnesis.Files;
using Anamnesis.GameData;
using Anamnesis.GameData.Excel;
using Anamnesis.Memory;
using Anamnesis.Services;
using System;
using System.Numerics;

public static class INpcBaseExtensions
{
Expand Down Expand Up @@ -182,7 +183,7 @@ private static CharacterFile ToFile(this INpcAppearance appearance)
CharacterFile.WeaponSave save = new CharacterFile.WeaponSave();

save.Color = Color.White;
save.Scale = Vector.One;
save.Scale = Vector3.One;
save.ModelSet = item.ModelSet;
save.ModelBase = item.ModelBase;
save.ModelVariant = item.ModelVariant;
Expand Down
3 changes: 2 additions & 1 deletion Anamnesis/Actor/Pages/PosePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace Anamnesis.Actor.Pages;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using XivToolsWpf;
using CmQuaternion = Anamnesis.Memory.Quaternion;
using XivToolsWpf.Math3D.Extensions;
using CmQuaternion = System.Numerics.Quaternion;

/// <summary>
/// Interaction logic for CharacterPoseView.xaml.
Expand Down
21 changes: 0 additions & 21 deletions Anamnesis/Actor/Posing/Extensions/PointExtensions.cs

This file was deleted.

42 changes: 0 additions & 42 deletions Anamnesis/Actor/Posing/Extensions/QuaternionExtensions.cs

This file was deleted.

41 changes: 0 additions & 41 deletions Anamnesis/Actor/Posing/Extensions/VectorExtensions.cs

This file was deleted.

9 changes: 5 additions & 4 deletions Anamnesis/Actor/Posing/Views/Pose3DView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

namespace Anamnesis.Actor.Views;

using PropertyChanged;
using Serilog;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using PropertyChanged;
using Serilog;
using XivToolsWpf;
using XivToolsWpf.Math3D.Extensions;
using Colors = System.Windows.Media.Colors;

/// <summary>
Expand All @@ -36,7 +37,7 @@ public Pose3DView()

this.CameraRotaion = new RotateTransform3D();
QuaternionRotation3D camRot = new QuaternionRotation3D();
camRot.Quaternion = CameraService.Instance.Camera?.Rotation3d ?? Quaternion.Identity;
camRot.Quaternion = CameraService.Instance.Camera?.Rotation3d.ToMedia3DQuaternion() ?? Quaternion.Identity;
this.CameraRotaion.Rotation = camRot;
this.CameraPosition = new TranslateTransform3D();
Transform3DGroup transformGroup = new Transform3DGroup();
Expand Down Expand Up @@ -184,7 +185,7 @@ private async Task UpdateCamera()
this.Skeleton.ReadTranforms();

// TODO: allow the user to rotate camera with the mouse instead
this.CameraRotation = CameraService.Instance.Camera.Rotation3d;
this.CameraRotation = CameraService.Instance.Camera.Rotation3d.ToMedia3DQuaternion();

// Apply camera rotation
QuaternionRotation3D rot = (QuaternionRotation3D)this.CameraRotaion.Rotation;
Expand Down
6 changes: 3 additions & 3 deletions Anamnesis/Actor/Posing/Visuals/BoneTargetVisual3d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Anamnesis.Posing.Visuals;

using Anamnesis.Actor;
using Anamnesis.Actor.Views;
using System;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using Anamnesis.Actor;
using Anamnesis.Actor.Views;
using XivToolsWpf.Meida3D;
using XivToolsWpf.Math3D;

public class BoneTargetVisual3d : ModelVisual3D, IDisposable
{
Expand Down
22 changes: 11 additions & 11 deletions Anamnesis/Actor/Posing/Visuals/BoneVisual3d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace Anamnesis.Actor;

using System;
using System.Collections.Generic;
using System.Windows.Media.Media3D;
using Anamnesis.Memory;
using Anamnesis.Actor.Extensions;
using Anamnesis.Memory;
using Anamnesis.Posing.Visuals;
using Anamnesis.Services;
using MaterialDesignThemes.Wpf;
using PropertyChanged;
using XivToolsWpf.Meida3D;

using CmQuaternion = Anamnesis.Memory.Quaternion;
using CmVector = Anamnesis.Memory.Vector;
using System;
using System.Collections.Generic;
using System.Windows.Media.Media3D;
using XivToolsWpf.Math3D;
using XivToolsWpf.Math3D.Extensions;
using CmQuaternion = System.Numerics.Quaternion;
using CmVector = System.Numerics.Vector3;
using Quaternion = System.Windows.Media.Media3D.Quaternion;

[AddINotifyPropertyChangedInterface]
Expand Down Expand Up @@ -264,8 +264,8 @@ public virtual void ReadTransform(bool readChildren = false)
}

// Store the new parent-relative transform info
this.Position = position.ToCmVector();
this.Rotation = rotation.ToCmQuaternion();
this.Position = position.FromMedia3DPoint();
this.Rotation = rotation.FromMedia3DQuaternion();

// Set the Media3D hierarchy transforms
this.rotation.Quaternion = rotation;
Expand Down Expand Up @@ -352,7 +352,7 @@ public virtual void WriteTransform(ModelVisual3D root, bool writeChildren = true

if (this.CanRotate)
{
CmQuaternion newRot = rotation.ToCmQuaternion();
CmQuaternion newRot = rotation.FromMedia3DQuaternion();
if (!transformMemory.Rotation.IsApproximately(newRot))
{
transformMemory.Rotation = newRot;
Expand Down
3 changes: 2 additions & 1 deletion Anamnesis/Actor/Posing/Visuals/SkeletonVisual3d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace Anamnesis.Actor;
using System.Windows.Input;
using System.Windows.Media.Media3D;
using XivToolsWpf;
using AnQuaternion = Anamnesis.Memory.Quaternion;
using XivToolsWpf.Math3D.Extensions;
using AnQuaternion = System.Numerics.Quaternion;

[AddINotifyPropertyChangedInterface]
public class SkeletonVisual3d : ModelVisual3D, INotifyPropertyChanged
Expand Down
6 changes: 4 additions & 2 deletions Anamnesis/Core/ITransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

namespace Anamnesis.Memory;

using System.Numerics;

public interface ITransform
{
bool CanTranslate { get; }
Vector Position { get; set; }
Vector3 Position { get; set; }

bool CanRotate { get; }
public Quaternion Rotation { get; set; }

bool CanScale { get; }
bool CanLinkScale { get; }
bool ScaleLinked { get; }
public Vector Scale { get; set; }
public Vector3 Scale { get; set; }
}
Loading

0 comments on commit 01c21fd

Please sign in to comment.