示例#1
0
        /// <summary>
        /// Computes move vector, based on new position of mouse and view direction.
        /// </summary>
        /// <param name="newPosition">New mouse position</param>
        /// <param name="viewDirection">view direction</param>
        /// <returns>Offset vector wrt manipulator origin</returns>
        public override Vector GetOffset(Point newPosition, Vector viewDirection)
        {
            Point hitPoint = Origin;

            using (var ray = GetRayGeometry(newPosition, viewDirection))
            {
                if (hitPlane != null)
                {
                    using (var testPlane = Plane.ByOriginXAxisYAxis(ManipulatorOrigin, hitPlane.XAxis, hitPlane.YAxis))
                    {
                        hitPoint = testPlane.Intersect(ray).FirstOrDefault() as Point;
                    }
                }
                else if (hitAxis != null)
                {
                    using (var axisLine = RayExtensions.ToOriginCenteredLine(ManipulatorOrigin, hitAxis))
                    {
                        hitPoint = axisLine.ClosestPointTo(ray);
                    }
                }
            }
            if (hitPoint == null)
            {
                return(Vector.ByCoordinates(0, 0, 0));
            }

            return(Vector.ByTwoPoints(ManipulatorOrigin, hitPoint));
        }
示例#2
0
 /// <summary>
 /// Draws axis line
 /// </summary>
 /// <param name="package"></param>
 /// <param name="axis"></param>
 /// <param name="name"></param>
 private void DrawAxisLine(ref IRenderPackage package, Vector axis, string name)
 {
     package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.AxisLine, Name, name);
     using (var line = RayExtensions.ToOriginCenteredLine(Origin, axis))
     {
         var color = GetAxisColor(GetAlignedAxis(axis));
         package.AddLineStripVertexCount(2);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z);
         package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
         package.AddLineStripVertex(line.EndPoint.X, line.EndPoint.Y, line.EndPoint.Z);
     }
 }
示例#3
0
        /// <summary>
        /// Computes move vector, based on new position of mouse and view direction.
        /// </summary>
        /// <param name="newPosition">New mouse position</param>
        /// <param name="viewDirection">view direction</param>
        /// <returns>Offset vector wrt Origin</returns>
        public Vector GetOffset(Point newPosition, Vector viewDirection)
        {
            Point hitPoint = Origin;

            using (var ray = GetRayGeometry(newPosition, viewDirection))
            {
                if (hitPlane != null)
                {
                    hitPoint = hitPlane.Intersect(ray).FirstOrDefault() as Point;
                }
                else if (hitAxis != null)
                {
                    var axis  = hitAxis.Cross(viewDirection);
                    var plane = Plane.ByOriginXAxisYAxis(Origin, hitAxis, axis);
                    hitPoint = plane.Intersect(ray).FirstOrDefault() as Point;
                    if (null != hitPoint)
                    {
                        var projection = hitAxis.Dot(Vector.ByTwoPoints(Origin, hitPoint));
                        hitPoint = Origin.Add(hitAxis.Normalized().Scale(projection));
                    }
                    else
                    {
                        using (var axisLine = RayExtensions.ToOriginCenteredLine(Origin, hitAxis))
                        {
                            hitPoint = axisLine.ClosestPointTo(ray);
                        }
                    }
                }
            }
            if (hitPoint == null)
            {
                return(Vector.ByCoordinates(0, 0, 0));
            }

            return(Vector.ByTwoPoints(Origin, hitPoint));
        }