Beispiel #1
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            Vector3D normal = this.CalculateTransformationForSpotLightAdorner().Transform(new Vector3D(0.0, 0.0, 1.0));

            normal.Normalize();
            Plane3D          plane3D            = new Plane3D(normal, this.centerOfCone);
            Viewport3DVisual adorningViewport3D = this.ActiveView.AdornerLayer.GetAdornerSet3DContainer(this.ActiveAdorner.Element.Viewport).ShadowAdorningViewport3D;
            Ray3D            ray = CameraRayHelpers.RayFromViewportPoint(adorningViewport3D.Viewport.Size, adorningViewport3D.Camera, this.LastMousePosition + mousePositionDelta);
            double           t;

            if (!plane3D.IntersectWithRay(ray, out t))
            {
                return;
            }
            double    num1      = Math.Atan((ray.Evaluate(t) - this.centerOfCone).Length / 1.0) / Math.PI * 180.0;
            SpotLight spotLight = (SpotLight)this.Selected3DElement.ViewObject.PlatformSpecificObject;

            if (this.ActiveAdorner.TypeOfConeAngle == SpotLightAdornerBehavior3D.TypeOfConeAngle.InnerConeAngle)
            {
                double num2 = spotLight.OuterConeAngle - spotLight.InnerConeAngle;
                this.Selected3DElement.SetValue(SpotLightElement.InnerConeAngleProperty, (object)num1);
                this.Selected3DElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)(num1 + num2));
            }
            else
            {
                this.Selected3DElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)num1);
            }
            this.ActiveAdorner.PositionAndOrientGeometry();
        }
        private BoundingVolume BuildFrustumFromViewport(Viewport3DHitTestHelper.ViewportInformation viewport, List <Point> frustumOutline)
        {
            List <Ray3D> list1  = new List <Ray3D>(frustumOutline.Count);
            Point        point1 = new Point(0.0, 0.0);

            for (int index = 0; index < frustumOutline.Count; ++index)
            {
                list1.Add(CameraRayHelpers.RayFromViewportPoint(viewport.Bounds, viewport.Camera, frustumOutline[index]));
                point1 += (Vector)frustumOutline[index];
            }
            Point          point2  = (Point)Vector.Divide((Vector)point1, (double)frustumOutline.Count);
            Point3D        point3D = new Point3D(0.0, 0.0, 0.0);
            List <Plane3D> list2   = new List <Plane3D>();

            for (int index = 0; index < frustumOutline.Count; ++index)
            {
                Vector3D normal = Vector3D.AngleBetween(list1[index].Direction, list1[(index + 1) % frustumOutline.Count].Direction) <= 0.0001 ? Vector3D.CrossProduct(list1[index].Direction, list1[(index + 1) % frustumOutline.Count].Origin - list1[index].Origin) : Vector3D.CrossProduct(list1[index].Direction, list1[(index + 1) % frustumOutline.Count].Direction);
                normal.Normalize();
                list2.Add(new Plane3D(normal, list1[index].Origin));
                point3D += (Vector3D)list1[index].Origin;
            }
            bool           flag           = list2[0].GetSignedDistanceFromPoint(list1[2].Origin) < 0.0;
            BoundingVolume boundingVolume = new BoundingVolume();

            for (int index = 0; index < frustumOutline.Count; ++index)
            {
                Plane3D frustumSide = list2[index];
                if (flag)
                {
                    Vector3D normal = frustumSide.Normal;
                    normal.Negate();
                    frustumSide = new Plane3D(normal, list1[index].Origin);
                }
                boundingVolume.AddSide(frustumSide);
            }
            Ray3D ray3D = CameraRayHelpers.RayFromViewportPoint(viewport.Bounds, viewport.Camera, point2);

            this.frustumCenterRay = new Ray3D((Point3D)Vector3D.Divide((Vector3D)point3D, (double)frustumOutline.Count), ray3D.Direction);
            ProjectionCamera projectionCamera = viewport.Camera as ProjectionCamera;

            if (projectionCamera != null)
            {
                boundingVolume.NearFrustum = new Plane3D(ray3D.Direction, this.frustumCenterRay.Origin);
                if (!double.IsPositiveInfinity(projectionCamera.FarPlaneDistance))
                {
                    Vector3D direction = ray3D.Direction;
                    direction.Negate();
                    boundingVolume.FarFrustum = new Plane3D(direction, this.frustumCenterRay.Origin + (projectionCamera.FarPlaneDistance - projectionCamera.NearPlaneDistance) * ray3D.Direction);
                }
            }
            return(boundingVolume);
        }
Beispiel #3
0
        public static Vector3D VectorBetweenPointsOnPlane(Viewport3D viewport, Plane3D plane, Point initialPoint, Point endPoint)
        {
            Size   viewportSize = new Size(viewport.ActualWidth, viewport.ActualHeight);
            Ray3D  ray1         = CameraRayHelpers.RayFromViewportPoint(viewportSize, viewport.Camera, initialPoint);
            Ray3D  ray2         = CameraRayHelpers.RayFromViewportPoint(viewportSize, viewport.Camera, endPoint);
            double t1;
            double t2;

            if (!plane.IntersectWithRay(ray1, out t1) || !plane.IntersectWithRay(ray2, out t2))
            {
                return(new Vector3D(0.0, 0.0, 0.0));
            }
            return(ray2.Evaluate(t2) - ray1.Evaluate(t1));
        }