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(); }
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)); }