/// <summary> /// For an object 'node' that is being manipulated, this function returns /// the offset (in world space) from the object's origin to to the point that is being /// "snapped from". This calculation is determined by the snapping modes.</summary> /// <param name="node">The object that is being snapped-to some other object</param> /// <param name="snapFromMode">The "snap from" mode, as a string. See SnapFromModes property. /// Pass in 'null' to get the default which is the offset to the pivot point.</param> /// <param name="axisType">Whether the Y axis is up or down</param> /// <returns>Offset from this object's origin to the "snap from" point, in world space</returns> /// <remarks>Must be kept in sync with SnapFromModes property.</remarks> public static Vec3F CalcSnapFromOffset( ITransformable node, string snapFromMode, AxisSystemType axisType) { SnapFromMode mode = GetSnapFromMode(snapFromMode); return(CalcSnapFromOffset(node, mode, axisType)); }
public static Vec3F CalcSnapFromOffset(ITransformable node, SnapFromMode snapFrom) { // AABB in local space. AABB box = node.As <IBoundable>().LocalBoundingBox; Vec3F offsetLocal = box.Center; switch (snapFrom) { case SnapFromMode.Pivot: offsetLocal = node.Pivot; break; case SnapFromMode.Origin: offsetLocal = box.Center; break; case SnapFromMode.TopCenter: offsetLocal.Y = box.Max.Y; break; case SnapFromMode.BottomCenter: offsetLocal.Y = box.Min.Y; break; case SnapFromMode.FrontCenter: offsetLocal.Z = box.Max.Z; break; case SnapFromMode.BackCenter: offsetLocal.Z = box.Min.Z; break; case SnapFromMode.LeftCenter: offsetLocal.X = box.Min.X; break; case SnapFromMode.RightCenter: offsetLocal.X = box.Max.X; break; default: throw new ArgumentOutOfRangeException("Invalid snap-from node"); } Path <DomNode> path = new Path <DomNode>(node.Cast <DomNode>().GetPath()); Matrix4F toWorld = TransformUtils.CalcPathTransform(path, path.Count - 1); Vec3F offset; toWorld.TransformVector(offsetLocal, out offset); //local-to-world return(offset); //world }
/// <summary> /// For an object 'node' that is being manipulated, this function returns /// the offset (in world space) from the object's origin to to the point that is being /// "snapped from". This calculation is determined by the snapping modes.</summary> /// <param name="node">The object that is being snapped-to some other object</param> /// <param name="snapFromMode">The "snap from" mode, as an enum</param> /// <param name="axisType">Axis system type (y or z is up)</param> /// <param name="pivot">Pass in either node.RotatePivot or node.ScalePivot</param> /// <returns>Offset from this object's origin to the "snap from" point, in world space</returns> /// <remarks>Must be kept in sync with SnapFromModes property.</remarks> public static Vec3F CalcSnapFromOffset( ITransformable node, SnapFromMode snapFromMode, AxisSystemType axisType, Vec3F pivot) { switch (snapFromMode) { case SnapFromMode.Pivot: { Vec3F offset; Path <DomNode> path = new Path <DomNode>(node.Cast <DomNode>().Ancestry); Matrix4F parentToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2); node.Transform.TransformVector(pivot, out offset); //local-to-parent parentToWorld.TransformVector(offset, out offset); //parent-to-world return(offset); //world } case SnapFromMode.Origin: return(new Vec3F(0, 0, 0)); case SnapFromMode.BottomCenter: { Box box = node.BoundingBox; Vec3F btmWorld; if (axisType == AxisSystemType.YIsUp) { btmWorld = new Vec3F( (box.Min.X + box.Max.X) * 0.5f, box.Min.Y, (box.Min.Z + box.Max.Z) * 0.5f); } else { btmWorld = new Vec3F( (box.Min.X + box.Max.X) * 0.5f, (box.Min.Y + box.Max.Y) * 0.5f, box.Min.Z); } Vec3F origin = node.Transform.Translation; Vec3F offset = btmWorld - origin; //local space offset Path <DomNode> path = new Path <DomNode>(node.Cast <DomNode>().GetPath()); Matrix4F parentToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2); parentToWorld.TransformVector(offset, out offset); return(offset); } default: throw new ArgumentException("Invalid snap-from node"); } }
/// <summary> /// For an object 'node' that is being manipulated, this function returns /// the offset (in world space) from the object's origin to to the point that is being /// "snapped from". This calculation is determined by the snapping modes.</summary> /// <param name="node">The object that is being snapped-to some other object</param> /// <param name="snapFromMode">The "snap from" mode, as an enum</param> /// <param name="axisType">Whether the Y axis is up or down</param> /// <returns>Offset from this object's origin to the "snap from" point, in world space</returns> /// <remarks>Must be kept in sync with SnapFromModes property.</remarks> public static Vec3F CalcSnapFromOffset( ITransformable node, SnapFromMode snapFromMode, AxisSystemType axisType) { Vec3F rotatePivot = new Vec3F(); if ((node.TransformationType & TransformationTypes.RotatePivot) != 0) { rotatePivot = node.RotatePivot; } return(CalcSnapFromOffset(node, snapFromMode, axisType, rotatePivot)); }
/// <summary> /// Gets the user-readable string that corresponds to the given SnapFromMode enum</summary> /// <param name="mode">SnapFromMode value</param> /// <returns>String corresponding to given SnapFromMode value</returns> public static string GetSnapFromMode(SnapFromMode mode) { switch (mode) { case SnapFromMode.Pivot: return(Pivot); case SnapFromMode.Origin: return(Origin); case SnapFromMode.BottomCenter: return(BottomCenter); default: throw new ArgumentOutOfRangeException("mode"); } }
public static Vec3F CalcSnapFromOffset(ITransformable node, SnapFromMode snapFrom) { // AABB in local space. AABB box = node.As<IBoundable>().LocalBoundingBox; Vec3F offsetLocal = box.Center; switch (snapFrom) { case SnapFromMode.Pivot: offsetLocal = node.Pivot; break; case SnapFromMode.Origin: offsetLocal = box.Center; break; case SnapFromMode.TopCenter: offsetLocal.Y = box.Max.Y; break; case SnapFromMode.BottomCenter: offsetLocal.Y = box.Min.Y; break; case SnapFromMode.FrontCenter: offsetLocal.Z = box.Max.Z; break; case SnapFromMode.BackCenter: offsetLocal.Z = box.Min.Z; break; case SnapFromMode.LeftCenter: offsetLocal.X = box.Min.X; break; case SnapFromMode.RightCenter: offsetLocal.X = box.Max.X; break; default: throw new ArgumentOutOfRangeException("Invalid snap-from node"); } Path<DomNode> path = new Path<DomNode>(node.Cast<DomNode>().GetPath()); Matrix4F toWorld = TransformUtils.CalcPathTransform(path, path.Count - 1); Vec3F offset; toWorld.TransformVector(offsetLocal, out offset); //local-to-world return offset; //world }
/// <summary> /// For an object 'node' that is being manipulated, this function returns /// the offset (in world space) from the object's origin to to the point that is being /// "snapped from". This calculation is determined by the snapping modes.</summary> /// <param name="node">The object that is being snapped-to some other object</param> /// <param name="snapFromMode">The "snap from" mode, as an enum</param> /// <param name="axisType">Whether the Y axis is up or down</param> /// <returns>Offset from this object's origin to the "snap from" point, in world space</returns> /// <remarks>Must be kept in sync with SnapFromModes property.</remarks> public static Vec3F CalcSnapFromOffset( ITransformable node, SnapFromMode snapFromMode, AxisSystemType axisType) { Vec3F rotatePivot = new Vec3F(); if ((node.TransformationType & TransformationTypes.RotatePivot) != 0) rotatePivot = node.RotatePivot; return CalcSnapFromOffset(node, snapFromMode, axisType, rotatePivot); }
/// <summary> /// For an object 'node' that is being manipulated, this function returns /// the offset (in world space) from the object's origin to to the point that is being /// "snapped from". This calculation is determined by the snapping modes.</summary> /// <param name="node">The object that is being snapped-to some other object</param> /// <param name="snapFromMode">The "snap from" mode, as an enum</param> /// <param name="axisType">Axis system type (y or z is up)</param> /// <param name="pivot">Pass in either node.RotatePivot or node.ScalePivot</param> /// <returns>Offset from this object's origin to the "snap from" point, in world space</returns> /// <remarks>Must be kept in sync with SnapFromModes property.</remarks> public static Vec3F CalcSnapFromOffset( ITransformable node, SnapFromMode snapFromMode, AxisSystemType axisType, Vec3F pivot) { switch (snapFromMode) { case SnapFromMode.Pivot: { Vec3F offset; Path<DomNode> path = new Path<DomNode>(node.Cast<DomNode>().Ancestry); Matrix4F parentToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2); node.Transform.TransformVector(pivot, out offset); //local-to-parent parentToWorld.TransformVector(offset, out offset); //parent-to-world return offset; //world } case SnapFromMode.Origin: return new Vec3F(0, 0, 0); case SnapFromMode.BottomCenter: { Box box = node.BoundingBox; Vec3F btmWorld; if (axisType == AxisSystemType.YIsUp) { btmWorld = new Vec3F( (box.Min.X + box.Max.X) * 0.5f, box.Min.Y, (box.Min.Z + box.Max.Z) * 0.5f); } else { btmWorld = new Vec3F( (box.Min.X + box.Max.X) * 0.5f, (box.Min.Y + box.Max.Y) * 0.5f, box.Min.Z); } Vec3F origin = node.Transform.Translation; Vec3F offset = btmWorld - origin; //local space offset Path<DomNode> path = new Path<DomNode>(node.Cast<DomNode>().GetPath()); Matrix4F parentToWorld = TransformUtils.CalcPathTransform(path, path.Count - 2); parentToWorld.TransformVector(offset, out offset); return offset; } default: throw new ArgumentException("Invalid snap-from node"); } }
/// <summary> /// Gets the user-readable string that corresponds to the given SnapFromMode enum</summary> /// <param name="mode">SnapFromMode value</param> /// <returns>String corresponding to given SnapFromMode value</returns> public static string GetSnapFromMode(SnapFromMode mode) { switch (mode) { case SnapFromMode.Pivot: return Pivot; case SnapFromMode.Origin: return Origin; case SnapFromMode.BottomCenter: return BottomCenter; default: throw new ArgumentOutOfRangeException("mode"); } }