Skip to content

Commit

Permalink
Transform overlay model only when new pose info is availible. (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperH2O authored Dec 1, 2022
1 parent 6bed27d commit f947b22
Showing 1 changed file with 59 additions and 33 deletions.
92 changes: 59 additions & 33 deletions HandheldCompanion/Views/Windows/OverlayModel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f947b22

Please sign in to comment.