private void RenderAccessoryItem(DrawingContext drawingContext, Skeleton person, AccessoryItem item)
{
SkeletonPoint headPos = person.Joints[JointType.Head].Position;
ColorImagePoint colorImagePoint = _sensor.CoordinateMapper.MapSkeletonPointToColorPoint(headPos,
_sensor.ColorStream
.Format);
double g = item.Width; // Objektgroesse in m.
double r = headPos.Z; // Entfernung in m.
double imgWidth = 2 * Math.Atan(g / (2 * r)) * ActualWidth;
double aspectRatio = item.Image.Width / item.Image.Height;
double imgHeight = imgWidth / aspectRatio;
double offsetX = 0, offsetY = 0;
switch (item.Position)
{
case AccessoryPositon.Hat:
offsetY = -1.1*imgHeight;
break;
case AccessoryPositon.Beard:
offsetY = imgHeight/4;
break;
}
double headX = colorImagePoint.X * (ActualWidth / _sensor.ColorStream.FrameWidth) + offsetX;
double headY = colorImagePoint.Y * (ActualHeight / _sensor.ColorStream.FrameHeight) + offsetY;
AccessoryRect = new Rect(headX - imgWidth / 2, headY, imgWidth, imgHeight);
drawingContext.DrawImage(item.Image, AccessoryRect);
}