示例#1
0
        /// <summary>
        /// Gets the total transform of the specified visual.
        /// </summary>
        /// <param name="viewport">The viewport.</param>
        /// <param name="visual">The visual.</param>
        /// <returns>The transform.</returns>
        public static GeneralTransform3D GetTransform(this Viewport3D viewport, Visual3D visual)
        {
            if (visual == null)
            {
                return(null);
            }

            foreach (var ancestor in viewport.Children)
            {
                if (visual.IsDescendantOf(ancestor))
                {
                    var g = new GeneralTransform3DGroup();

                    // this includes the visual.Transform
                    var ta = visual.TransformToAncestor(ancestor);
                    if (ta != null)
                    {
                        g.Children.Add(ta);
                    }

                    // add the transform of the top-level ancestor
                    g.Children.Add(ancestor.Transform);

                    return(g);
                }
            }

            return(visual.Transform);
        }
示例#2
0
        public static Point?From3Dto2D(Visual3D space, Visual surface, Camera perspectiveCamera, Point3D target)
        {
            PerspectiveCamera      cmr   = perspectiveCamera as PerspectiveCamera;
            Point?                 rlt   = new Point();
            Vector3D               look  = cmr.Transform.Transform(cmr.LookDirection);
            Vector3D               d     = target - cmr.Transform.Transform(cmr.Position);
            double                 angle = AngleBetween(d, look);
            GeneralTransform3DTo2D gt    = space.TransformToAncestor(surface);

            rlt = gt.Transform(target);
            if (Math.Abs(angle) < cmr.FieldOfView / 2)
            {
                return(rlt);
            }
            return(null);
        }