本文整理汇总了C#中Viewport.Project方法的典型用法代码示例。如果您正苦于以下问题:C# Viewport.Project方法的具体用法?C# Viewport.Project怎么用?C# Viewport.Project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Viewport
的用法示例。
在下文中一共展示了Viewport.Project方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Offset
public static ScreenOffset Offset(Vector3 point, Rectangle bounds, Viewport viewport, Matrix projection,
Matrix view, Matrix currentAttitude)
{
// Create a World matrix for the point.
var world = Matrix.CreateWorld(point, new Vector3(0, 0, -1), new Vector3(0, 1, 0));
// Use Viewport.Project to project the point from 3D space into screen coordinates.
var projected = viewport.Project(Vector3.Zero, projection, view, world*currentAttitude);
if (projected.Z > 1 || projected.Z < 0)
{
// If the point is outside of this range, it is behind the camera.
// So hide the TextBlock for this point.
return default(ScreenOffset);
}
// Create a TranslateTransform to position the TextBlock.
// Offset by half of the TextBlock's RenderSize to center it on the point.
var tt = new ScreenOffset
{
TranslateX = projected.X - (bounds.Width/2),
TranslateY = projected.Y - (bounds.Height/2),
Scale = 1/projected.Z
};
return tt;
}