コード例 #1
0
ファイル: EventMode.cs プロジェクト: LordNed/Winditor
        private BindingVector3 Raycast(FRay ray, WCamera camera)
        {
            BindingVector3        selected_vec            = null;
            List <BindingVector3> vecs_to_raycast         = GetCameraVectorProperties();
            List <Tuple <float, BindingVector3> > results = new List <Tuple <float, BindingVector3> >();

            foreach (BindingVector3 bv in vecs_to_raycast)
            {
                FPlane plane = new FPlane(ray.Direction.Normalized(), bv.BackingVector);

                float dist = float.MaxValue;
                plane.RayIntersectsPlane(ray, out dist);

                Vector3 plane_intersect_point          = camera.Transform.Position + (plane.Normal * dist);
                float   distance_from_billboard_center = (plane_intersect_point - bv.BackingVector).Length;

                if (distance_from_billboard_center < 50.0f)
                {
                    float point_dist = (camera.Transform.Position - bv.BackingVector).Length;
                    results.Add(new Tuple <float, BindingVector3>(point_dist, bv));
                }
            }

            results.Sort(delegate(Tuple <float, BindingVector3> x, Tuple <float, BindingVector3> y)
            {
                return(x.Item1.CompareTo(y.Item1));
            });

            if (results.Count > 0)
            {
                selected_vec = results[0].Item2;
            }

            return(selected_vec);
        }
コード例 #2
0
ファイル: EventMode.cs プロジェクト: LordNed/Winditor
        public void Update(WSceneView view)
        {
            m_View = view;
            UpdateSelectionGizmo(view);

            // Add our gizmo to the renderer this frame.
            if (TransformGizmo != null)
            {
                ((IRenderable)TransformGizmo).AddToRenderer(view);
            }

            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (TransformGizmo != null && TransformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1) && !m_bOverrideSceneCamera)
            {
                FRay           mouseRay = view.ProjectScreenToWorld(WInput.MousePosition);
                BindingVector3 addedVec = Raycast(mouseRay, view.ViewCamera);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                // Replace the previous selection with the current selection, if it's valid.
                if (!ctrlPressed & !shiftPressed)
                {
                    EditorSelection.ClearSelection();

                    if (addedVec != null)
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
                else if (addedVec != null && (ctrlPressed && !shiftPressed))
                {
                    if (EditorSelection.SelectedObjects.Contains(addedVec))
                    {
                        EditorSelection.RemoveFromSelection(addedVec);
                    }
                    else
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
                else if (addedVec != null && shiftPressed)
                {
                    if (!EditorSelection.SelectedObjects.Contains(addedVec))
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
            }
            if (m_CopyCameraRequest != null)
            {
                m_CopyCameraRequest.RequestingCut.CopySettingsFromCamera(view.ViewCamera, m_CopyCameraRequest.IsStart);
                m_CopyCameraRequest = null;
            }
            if (WInput.GetMouseButton(1) && m_bOverrideSceneCamera)
            {
                RestoreSceneCamera(view);
            }

            UpdateGizmoTransform();
        }