Ejemplo n.º 1
0
        /// <summary>
        /// Gets the distance from the camera for the specified visual.
        /// </summary>
        /// <param name="c">
        /// The visual.
        /// </param>
        /// <param name="cameraPos">
        /// The camera position.
        /// </param>
        /// <param name="transform">
        /// The total transform of the visual.
        /// </param>
        /// <returns>
        /// The camera distance.
        /// </returns>
        private double GetCameraDistance(Visual3D c, Point3D cameraPos, Transform3D transform)
        {
            var bounds = Visual3DHelper.FindBounds(c, transform);

            switch (this.Method)
            {
            case SortingMethod.BoundingBoxCenter:
                var mid = new Point3D(
                    bounds.X + bounds.SizeX * 0.5, bounds.Y + bounds.SizeY * 0.5, bounds.Z + bounds.SizeZ * 0.5);
                return((mid - cameraPos).LengthSquared);

            case SortingMethod.BoundingBoxCorners:
                double d = double.MaxValue;
                d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z)));
                d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z)));
                d = Math.Min(
                    d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z)));
                d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z)));
                d = Math.Min(d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y, bounds.Z + bounds.SizeZ)));
                d = Math.Min(
                    d, cameraPos.DistanceTo(new Point3D(bounds.X + bounds.SizeX, bounds.Y, bounds.Z + bounds.SizeZ)));
                d = Math.Min(
                    d,
                    cameraPos.DistanceTo(
                        new Point3D(bounds.X + bounds.SizeX, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
                d = Math.Min(
                    d, cameraPos.DistanceTo(new Point3D(bounds.X, bounds.Y + bounds.SizeY, bounds.Z + bounds.SizeZ)));
                return(d);

            default:
                var boundingSphere = BoundingSphere.CreateFromRect3D(bounds);
                return(boundingSphere.DistanceFrom(cameraPos));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Zooms to fit the extents of the specified viewport.
        /// </summary>
        /// <param name="camera">
        /// The actual camera.
        /// </param>
        /// <param name="viewport">
        /// The viewport.
        /// </param>
        /// <param name="animationTime">
        /// The animation time.
        /// </param>
        public static void ZoomExtents(this ProjectionCamera camera, Viewport3D viewport, double animationTime = 0)
        {
            var bounds   = Visual3DHelper.FindBounds(viewport.Children);
            var diagonal = new Vector3D(bounds.SizeX, bounds.SizeY, bounds.SizeZ);

            if (bounds.IsEmpty || diagonal.LengthSquared < double.Epsilon)
            {
                return;
            }

            ZoomExtents(camera, viewport, bounds, animationTime);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the distance squared.
        /// </summary>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="visual">
        /// The visual.
        /// </param>
        /// <returns>
        /// The get distance squared.
        /// </returns>
        public static double GetDistanceSquared(Point3D position, Visual3D visual)
        {
            var bounds = Visual3DHelper.FindBounds(visual, Transform3D.Identity);

            return(Point3D.Subtract(bounds.Location, position).LengthSquared);
        }