From f947b22ce7ce156b25ed0f88cb9ac14c5c6239a4 Mon Sep 17 00:00:00 2001 From: CasperH2O Date: Thu, 1 Dec 2022 13:20:59 +0100 Subject: [PATCH] Transform overlay model only when new pose info is availible. (#305) --- .../Views/Windows/OverlayModel.xaml.cs | 92 ++++++++++++------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs b/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs index 29364f61c..6da364a30 100644 --- a/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs +++ b/HandheldCompanion/Views/Windows/OverlayModel.xaml.cs @@ -36,13 +36,17 @@ public partial class OverlayModel : OverlayWindow private Quaternion DevicePose = new Quaternion(0.0f, 0.0f, 1.0f, 0.0f); private Vector3D DevicePoseRad = new Vector3D(0, 3.14, 0); private Vector3D DiffAngle = new Vector3D(0, 0, 0); + Transform3DGroup Transform3DGroupModelPrevious = new Transform3DGroup(); // TODO Dummy variables, placeholder and for testing private short MotorLeftPlaceholder; private short MotorRightPlaceholder; - private float TriggerAngleShoulderLeft; - private float TriggerAngleShoulderRight; + private float TriggerAngleShoulderLeft; + private float TriggerAngleShoulderLeftPrev; + private float TriggerAngleShoulderRight; + private float TriggerAngleShoulderRightPrev; + private float ShoulderButtonsAngleDegPrev; public OverlayModel() { @@ -568,8 +572,12 @@ private void UpdateModelVisual3D() Transform3DGroupModel.Children.Add(DeviceRotateTransformFaceCameraX); } - // Transform mode with group - ModelVisual3D.Content.Transform = Transform3DGroupModel; + // Transform mode with group if there are any changes + if (Transform3DGroupModel != Transform3DGroupModelPrevious) + { + ModelVisual3D.Content.Transform = Transform3DGroupModel; + Transform3DGroupModelPrevious = Transform3DGroupModel; + } // Upward visibility rotation for shoulder buttons // Model angle to compensate for @@ -602,35 +610,53 @@ private void UpdateModelVisual3D() else if (ModelPoseXDeg < 45.0f) { ShoulderButtonsAngleDeg = 0.0f; - } - - // Left shoulder buttons visibility rotation and trigger button angle - Model3DGroup Placeholder = CurrentModel.ButtonMap[ControllerButtonFlags.LeftShoulder][0]; - - UpwardVisibilityRotationShoulderButtons(ShoulderButtonsAngleDeg, - CurrentModel.UpwardVisibilityRotationAxisLeft, - CurrentModel.UpwardVisibilityRotationPointLeft, - TriggerAngleShoulderLeft, - CurrentModel.ShoulderTriggerRotationPointCenterLeftMillimeter, - ref CurrentModel.LeftShoulderTrigger, - ref Placeholder - ); - - CurrentModel.ButtonMap[ControllerButtonFlags.LeftShoulder][0] = Placeholder; - - // Right shoulder buttons visibility rotation and trigger button angle - Placeholder = CurrentModel.ButtonMap[ControllerButtonFlags.RightShoulder][0]; - - UpwardVisibilityRotationShoulderButtons(ShoulderButtonsAngleDeg, - CurrentModel.UpwardVisibilityRotationAxisRight, - CurrentModel.UpwardVisibilityRotationPointRight, - TriggerAngleShoulderRight, - CurrentModel.ShoulderTriggerRotationPointCenterRightMillimeter, - ref CurrentModel.RightShoulderTrigger, - ref Placeholder - ); - - CurrentModel.ButtonMap[ControllerButtonFlags.RightShoulder][0] = Placeholder; + } + Model3DGroup Placeholder = new Model3DGroup(); + + // Left shoulder buttons visibility rotation and trigger button angle + // only perform when model or triggers are in a different position + if (ShoulderButtonsAngleDeg != ShoulderButtonsAngleDegPrev || TriggerAngleShoulderLeft != TriggerAngleShoulderLeftPrev) + { + + Placeholder = CurrentModel.ButtonMap[ControllerButtonFlags.LeftShoulder][0]; + + UpwardVisibilityRotationShoulderButtons(ShoulderButtonsAngleDeg, + CurrentModel.UpwardVisibilityRotationAxisLeft, + CurrentModel.UpwardVisibilityRotationPointLeft, + TriggerAngleShoulderLeft, + CurrentModel.ShoulderTriggerRotationPointCenterLeftMillimeter, + ref CurrentModel.LeftShoulderTrigger, + ref Placeholder + ); + + CurrentModel.ButtonMap[ControllerButtonFlags.LeftShoulder][0] = Placeholder; + + TriggerAngleShoulderLeftPrev = TriggerAngleShoulderLeft; + } + + // Right shoulder buttons visibility rotation and trigger button angle + // only perform when model or triggers are in a different position + if (ShoulderButtonsAngleDeg != ShoulderButtonsAngleDegPrev || TriggerAngleShoulderRight != TriggerAngleShoulderRightPrev) + { + + Placeholder = CurrentModel.ButtonMap[ControllerButtonFlags.RightShoulder][0]; + + UpwardVisibilityRotationShoulderButtons(ShoulderButtonsAngleDeg, + CurrentModel.UpwardVisibilityRotationAxisRight, + CurrentModel.UpwardVisibilityRotationPointRight, + TriggerAngleShoulderRight, + CurrentModel.ShoulderTriggerRotationPointCenterRightMillimeter, + ref CurrentModel.RightShoulderTrigger, + ref Placeholder + ); + + CurrentModel.ButtonMap[ControllerButtonFlags.RightShoulder][0] = Placeholder; + + TriggerAngleShoulderRightPrev = TriggerAngleShoulderRight; + } + + ShoulderButtonsAngleDegPrev = ShoulderButtonsAngleDeg; + }); } #endregion