Skip to content

Commit

Permalink
few tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Dec 1, 2022
1 parent 031e8fb commit 6bed27d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
3 changes: 3 additions & 0 deletions HandheldCompanion/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
<setting name="HIDInstancePath" serializeAs="String">
<value />
</setting>
<setting name="OverlayControllerMotion" serializeAs="String">
<value>True</value>
</setting>
</HandheldCompanion.Properties.Settings>
</userSettings>
</configuration>
12 changes: 12 additions & 0 deletions HandheldCompanion/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions HandheldCompanion/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,8 @@
<Setting Name="HIDInstancePath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="OverlayControllerMotion" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
10 changes: 5 additions & 5 deletions HandheldCompanion/Views/Pages/OverlayPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ private void SettingsManager_SettingValueChanged(string name, object value)
case "OverlayControllerAlwaysOnTop":
Toggle_AlwaysOnTop.IsOn = Convert.ToBoolean(value);
break;
case "OverlayControllerMotion":
Toggle_MotionActivated.IsOn = Convert.ToBoolean(value);
break;
}
});
}
Expand Down Expand Up @@ -250,12 +253,9 @@ private void Toggle_MotionActivated_Toggled(object sender, RoutedEventArgs e)
MainWindow.overlayModel.MotionActivated = Toggle_MotionActivated.IsOn;

if (!SettingsManager.IsInitialized)
return;

// On change of motion activated, reset object alignment
MainWindow.overlayModel.FaceCameraObjectAlignment = new Vector3D(0.0d, 0.0d, 0.0d);
return;

SettingsManager.SetProperty("OverlayMotionActivated", Toggle_MotionActivated.IsOn);
SettingsManager.SetProperty("OverlayControllerMotion", Toggle_MotionActivated.IsOn);
}
private void Toggle_FaceCamera_Toggled(object sender, RoutedEventArgs e)
{
Expand Down
39 changes: 26 additions & 13 deletions HandheldCompanion/Views/Windows/OverlayModel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ControllerCommon;
using ControllerCommon.Controllers;
using ControllerCommon.Utils;
using HandheldCompanion.Managers;
using HandheldCompanion.Models;
using HandheldCompanion.Views.Classes;
using PrecisionTiming;
Expand Down Expand Up @@ -33,7 +34,8 @@ public partial class OverlayModel : OverlayWindow
public bool MotionActivated = true;
public Vector3D DesiredAngleDeg = new Vector3D(0, 0, 0);
private Quaternion DevicePose = new Quaternion(0.0f, 0.0f, 1.0f, 0.0f);
private Vector3D DevicePoseRad = new Vector3D(0, 3.14, 0);
private Vector3D DevicePoseRad = new Vector3D(0, 3.14, 0);
private Vector3D DiffAngle = new Vector3D(0, 0, 0);

// TODO Dummy variables, placeholder and for testing
private short MotorLeftPlaceholder;
Expand All @@ -46,14 +48,33 @@ public OverlayModel()
{
InitializeComponent();

PipeClient.ServerMessage += OnServerMessage;
PipeClient.ServerMessage += OnServerMessage;
SettingsManager.SettingValueChanged += SettingsManager_SettingValueChanged;

// initialize timers
UpdateTimer = new PrecisionTimer();
UpdateTimer.SetAutoResetMode(true);
UpdateTimer.Tick += DrawModel;

UpdateModel();
}

private void SettingsManager_SettingValueChanged(string name, object value)
{
this.Dispatcher.Invoke(() =>
{
switch (name)
{
case "OverlayControllerMotion":
MotionActivated = Convert.ToBoolean(value);

// On change of motion activated, reset object alignment
FaceCameraObjectAlignment = new Vector3D(0.0d, 0.0d, 0.0d);
DevicePose = new Quaternion(0.0f, 0.0f, 1.0f, 0.0f);
DevicePoseRad = new Vector3D(0, 3.14, 0);
break;
}
});
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down Expand Up @@ -214,6 +235,8 @@ private void OnServerMessage(PipeMessage message)
return;

// Add return here if motion is not wanted for 3D model
if (!MotionActivated)
return;

PipeSensor sensor = (PipeSensor)message;
switch (sensor.type)
Expand Down Expand Up @@ -500,29 +523,19 @@ ref Model3DGroup ShoulderButton
ShoulderTrigger.Transform = Transform3DGroupShoulderTrigger;
// Transform shoulder button only with upward visibility
ShoulderButton.Transform = TransformShoulder;
}
}

private void UpdateModelVisual3D()
{
this.Dispatcher.Invoke(() =>
{
Transform3DGroup Transform3DGroupModel = new Transform3DGroup();

// When motion is disabled, overwrite poses with defaults
if (!MotionActivated)
{
DevicePose = new Quaternion(0.0f, 0.0f, 1.0f, 0.0f);
DevicePoseRad = new Vector3D(0, 3.14, 0);
}

// Device transformation based on pose
var Ax3DDevicePose = new QuaternionRotation3D(DevicePose);
DeviceRotateTransform = new RotateTransform3D(Ax3DDevicePose);
Transform3DGroupModel.Children.Add(DeviceRotateTransform);

// Face camera
Vector3D DiffAngle = new Vector3D(0, 0, 0);

// Determine diff angles
DiffAngle.X = (InputUtils.rad2deg((float)DevicePoseRad.X) - (float)FaceCameraObjectAlignment.X) - (float)DesiredAngleDeg.X;
DiffAngle.Y = (InputUtils.rad2deg((float)DevicePoseRad.Y) - (float)FaceCameraObjectAlignment.Y) - (float)DesiredAngleDeg.Y;
Expand Down

0 comments on commit 6bed27d

Please sign in to comment.