本文整理汇总了C#中Sledge.UI.Viewport2D.ZeroUnusedCoordinate方法的典型用法代码示例。如果您正苦于以下问题:C# Viewport2D.ZeroUnusedCoordinate方法的具体用法?C# Viewport2D.ZeroUnusedCoordinate怎么用?C# Viewport2D.ZeroUnusedCoordinate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sledge.UI.Viewport2D
的用法示例。
在下文中一共展示了Viewport2D.ZeroUnusedCoordinate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTransformationMatrix
public override Matrix4? GetTransformationMatrix(Viewport2D viewport, ViewportEvent e, BaseBoxTool.BoxState state, Document doc, IEnumerable<Widget> activeWidgets)
{
var origin = viewport.ZeroUnusedCoordinate((state.PreTransformBoxStart + state.PreTransformBoxEnd) / 2);
var rw = activeWidgets.OfType<RotationWidget>().FirstOrDefault();
if (rw != null) origin = rw.GetPivotPoint();
var forigin = viewport.Flatten(origin);
var origv = (state.MoveStart - forigin).Normalise();
var newv = (viewport.ScreenToWorld(e.X, viewport.Height - e.Y) - forigin).Normalise();
var angle = DMath.Acos(Math.Max(-1, Math.Min(1, origv.Dot(newv))));
if ((origv.Cross(newv).Z < 0)) angle = 2 * DMath.PI - angle;
var shf = KeyboardState.Shift;
var def = Select.RotationStyle;
var snap = (def == RotationStyle.SnapOnShift && shf) || (def == RotationStyle.SnapOffShift && !shf);
if (snap)
{
var deg = angle * (180 / DMath.PI);
var rnd = Math.Round(deg / 15) * 15;
angle = rnd * (DMath.PI / 180);
}
Matrix4 rotm;
if (viewport.Direction == Viewport2D.ViewDirection.Top) rotm = Matrix4.CreateRotationZ((float)angle);
else if (viewport.Direction == Viewport2D.ViewDirection.Front) rotm = Matrix4.CreateRotationX((float)angle);
else rotm = Matrix4.CreateRotationY((float)-angle); // The Y axis rotation goes in the reverse direction for whatever reason
var mov = Matrix4.CreateTranslation((float)-origin.X, (float)-origin.Y, (float)-origin.Z);
var rot = Matrix4.Mult(mov, rotm);
return Matrix4.Mult(rot, Matrix4.Invert(mov));
}