private void Transform(AstroObject astroObject, Matrix3D baseTransformation, FrameworkElement txt)
{
// Transform Model
if (astroObject == null)
{
return;
}
var m = Matrix.Identity;
m *= Matrix.CreateTranslation(0, 60, 0);
m *= Matrix.CreateRotationX(Microsoft.Xna.Framework.MathHelper.ToRadians(90));
m *= baseTransformation.ToXnaMatrix();
astroObject.Transform = m;
astroObject.IsVisible = true;
// Transform FrameworkElement
// Center at origin of the TextBlock
var centerAtOrigin = Matrix3DFactory.CreateTranslation(-txt.ActualWidth * 0.5, -txt.ActualHeight * 0.5, 0);
// Swap the y-axis
var scale = Matrix3DFactory.CreateScale(1, -1, 1);
// Move a bit away from the center
var translation = Matrix3DFactory.CreateTranslation(0, 50, 0);
// Calculate the complete transformation matrix based on the first detection result
var world = centerAtOrigin * translation * scale * baseTransformation;
// Calculate the final transformation matrix by using the camera projection matrix
var vp = Matrix3DFactory.CreateViewportTransformation(Viewport.ActualWidth, Viewport.ActualHeight);
var mp = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, vp);
// Apply the final transformation matrix to the TextBox
txt.Projection = new Matrix3DProjection {
ProjectionMatrix = mp
};
txt.Visibility = Visibility.Visible;
}