Skip to content

Commit

Permalink
Camera support fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Oct 19, 2024
1 parent 509d2c6 commit 5867afd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
3 changes: 2 additions & 1 deletion Amethyst/Installer/Views/SetupDevices.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<Grid Style="{ThemeResource GridCardSingleStyle}"
Width="250" Height="320" Opacity="{x:Bind BoolToOpacity(IsEnabled)}">

<TextBlock HorizontalAlignment="Center" Text="{x:Bind Name}"
<TextBlock HorizontalAlignment="Center" Text="{x:Bind Name}"
HorizontalTextAlignment="Center"
Style="{ThemeResource SubtitleTextBlockStyle}" />

<Viewbox Child="{x:Bind Icon}" Margin="40,90"
Expand Down
1 change: 1 addition & 0 deletions Amethyst/Installer/Views/SetupServices.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Width="250" Height="320" Opacity="{x:Bind BoolToOpacity(IsEnabled)}">

<TextBlock HorizontalAlignment="Center" Text="{x:Bind Name}"
HorizontalTextAlignment="Center"
Style="{ThemeResource SubtitleTextBlockStyle}" />

<Viewbox Child="{x:Bind Icon}" Margin="40,90"
Expand Down
72 changes: 41 additions & 31 deletions Amethyst/Pages/General.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,17 @@ private void CameraImage_OnSizeChanged(object sender, SizeChangedEventArgs e)
!AppData.Settings.CameraPreviewEnabled)
{
// If no image, keep the Canvas at its default size
SkeletonDrawingCanvas.Width = 640;
SkeletonDrawingCanvas.Height = 480;
if (AppPlugins.BaseTrackingDevice.Guid is "K2VRTEAM-AME2-APII-DVCE-DVCEKINECTV2")
{
SkeletonDrawingCanvas.Width = 1920;
SkeletonDrawingCanvas.Height = 1080;
}
else
{
SkeletonDrawingCanvas.Width = 640;
SkeletonDrawingCanvas.Height = 480;
}

Canvas.SetLeft(SkeletonDrawingCanvas, 0);
Canvas.SetTop(SkeletonDrawingCanvas, 0);
return;
Expand Down Expand Up @@ -1153,8 +1162,17 @@ private void SkeletonDrawingCanvas_Loaded(object sender, RoutedEventArgs e)
!AppData.Settings.CameraPreviewEnabled)
{
// If no image, keep the Canvas at its default size
SkeletonDrawingCanvas.Width = 640;
SkeletonDrawingCanvas.Height = 480;
if (AppPlugins.BaseTrackingDevice.Guid is "K2VRTEAM-AME2-APII-DVCE-DVCEKINECTV2")
{
SkeletonDrawingCanvas.Width = 1920;
SkeletonDrawingCanvas.Height = 1080;
}
else
{
SkeletonDrawingCanvas.Width = 640;
SkeletonDrawingCanvas.Height = 480;
}

Canvas.SetLeft(SkeletonDrawingCanvas, 0);
Canvas.SetTop(SkeletonDrawingCanvas, 0);
}
Expand Down Expand Up @@ -1491,7 +1509,16 @@ private void SkPoint(Ellipse ellipse, TrackedJoint joint,
if (matHeight < 1) matHeight = matHeightDefault;

// Where to scale by 1.0 in perspective
const double normalDistance = 3, normalEllipseStrokeSize = 2, normalEllipseSize = 8;
const double normalDistance = 3;

double normalEllipseStrokeSize = 2, normalEllipseSize = 8;
if (AppPlugins.BaseTrackingDevice.CameraImage is not null)
{
var actualHeight = Math.Max(CameraImage.ActualHeight, 480.0);

normalEllipseStrokeSize *= actualHeight / 480.0;
normalEllipseSize *= actualHeight / 480.0;
}

// Compose perspective constants, make it 70%
var multiply = .7 * (normalDistance /
Expand Down Expand Up @@ -1538,40 +1565,24 @@ private void SkPoint(Ellipse ellipse, TrackedJoint joint,
// Move the ellipse to the appropriate point
if (AppPlugins.BaseTrackingDevice.CameraImage is not null &&
AppPlugins.BaseTrackingDevice.MapCoordinate(joint.Position, out var mapped))
{
var actualWidth = Math.Max(CameraImage.ActualWidth, 640.0);
var actualHeight = Math.Max(CameraImage.ActualHeight, 480.0);

ellipse.Margin = new Thickness(
// Left
mapped.Left * actualWidth / 640.0f -
(normalEllipseSize + normalEllipseStrokeSize) / 2.0,

// Top
mapped.Top * actualHeight / 480.0f -
(normalEllipseSize + normalEllipseStrokeSize) / 2.0,

// Not used
mapped.Left - (normalEllipseSize + normalEllipseStrokeSize) / 2.0,
mapped.Top - (normalEllipseSize + normalEllipseStrokeSize) / 2.0,
0, 0
);
}
else
{
ellipse.Margin = new Thickness(
// Left
joint.Position.X * 300.0 *
Math.Min(sScaleW, sScaleH) * multiply +
matWidth / 2.0 - (normalEllipseSize + normalEllipseStrokeSize) / 2.0,

// Top
joint.Position.Y * -300.0 *
Math.Min(sScaleW, sScaleH) * multiply +
matHeight / 3.0 - (normalEllipseSize + normalEllipseStrokeSize) / 2.0,

// Not used
0, 0
);
}

ellipse.Visibility = Visibility.Visible;
}
Expand All @@ -1594,7 +1605,11 @@ private bool SkLine(Line line, TrackedJoint fromJoint, TrackedJoint toJoint)
if (matHeight < 1) matHeight = matHeightDefault;

// Where to scale by 1.0 in perspective
const double normalDistance = 3, normalLineStrokeSize = 4;
const double normalDistance = 3;

double normalLineStrokeSize = 4;
if (AppPlugins.BaseTrackingDevice.CameraImage is not null)
normalLineStrokeSize *= Math.Max(CameraImage.ActualHeight, 480.0) / 480.0;

// Compose perspective constants, make it 70%
var fromMultiply = .7 * (normalDistance /
Expand Down Expand Up @@ -1622,13 +1637,8 @@ private bool SkLine(Line line, TrackedJoint fromJoint, TrackedJoint toJoint)
AppPlugins.BaseTrackingDevice.MapCoordinate(fromJoint.Position, out var fromMapped) &&
AppPlugins.BaseTrackingDevice.MapCoordinate(toJoint.Position, out var toMapped))
{
var actualWidth = Math.Max(CameraImage.ActualWidth, 640.0);
var actualHeight = Math.Max(CameraImage.ActualHeight, 480.0);

(line.X1, line.Y1) = (fromMapped.Left * actualWidth / 640.0f,
fromMapped.Top * actualHeight / 480.0f);
(line.X2, line.Y2) = (toMapped.Left * actualWidth / 640.0f,
toMapped.Top * actualHeight / 480.0f);
(line.X1, line.Y1) = (fromMapped.Left, fromMapped.Top);
(line.X2, line.Y2) = (toMapped.Left, toMapped.Top);
}
else
{
Expand Down

0 comments on commit 5867afd

Please sign in to comment.