Esempio n. 1
0
        private void GetHitLocation(ref Vector2 location, out SceneGraphNode hit, out Vector3 hitLocation)
        {
            // Get mouse ray and try to hit any object
            var ray       = ConvertMouseToRay(ref location);
            var gridPlane = new Plane(Vector3.Zero, Vector3.Up);

            hit = Editor.Instance.Scene.Root.RayCast(ref ray, out var closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders);
            if (hit != null)
            {
                // Use hit location
                hitLocation = ray.Position + ray.Direction * closest;
            }
            else if (Grid.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f)
            {
                // Use grid location
                hitLocation = ray.Position + ray.Direction * closest;
            }
            else
            {
                // Use area in front of the viewport
                hitLocation = ViewPosition + ViewDirection * 100;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="Plane" />.
 /// </summary>
 /// <param name="plane">The plane to test.</param>
 /// <param name="point">
 /// When the method completes, contains the point of intersection,
 /// or <see cref="Vector3.Zero" /> if there was no intersection.
 /// </param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Plane plane, out Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out point));
 }
Esempio n. 3
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="Plane" />.
 /// </summary>
 /// <param name="plane">The plane to test.</param>
 /// <param name="distance">
 /// When the method completes, contains the distance of the intersection,
 /// or 0 if there was no intersection.
 /// </param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Plane plane, out float distance)
 {
     return(CollisionsHelper.RayIntersectsPlane(ref this, ref plane, out distance));
 }
Esempio n. 4
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="Ray" />.
 /// </summary>
 /// <param name="ray">The ray to test.</param>
 /// <param name="distance">When the method completes, contains the distance of the intersection, or 0 if there was no intersection.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Ray ray, out Real distance)
 {
     return(CollisionsHelper.RayIntersectsPlane(ref ray, ref this, out distance));
 }
Esempio n. 5
0
        /// <inheritdoc />
        public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data)
        {
            var result = base.OnDragDrop(ref location, data);

            if (result != DragDropEffect.None)
            {
                return(result);
            }

            // Check if drag sth
            Vector3        hitLocation = ViewPosition;
            SceneGraphNode hit         = null;

            if (_dragAssets.HasValidDrag || _dragActorType.HasValidDrag)
            {
                // Get mouse ray and try to hit any object
                var   ray       = ConvertMouseToRay(ref location);
                float closest   = float.MaxValue;
                var   gridPlane = new Plane(Vector3.Zero, Vector3.Up);
                hit = Editor.Instance.Scene.Root.RayCast(ref ray, ref closest, SceneGraphNode.RayCastData.FlagTypes.SkipColliders);
                if (hit != null)
                {
                    // Use hit location
                    hitLocation = ray.Position + ray.Direction * closest;
                }
                else if (Grid.Enabled && CollisionsHelper.RayIntersectsPlane(ref ray, ref gridPlane, out closest) && closest < 4000.0f)
                {
                    // Use grid location
                    hitLocation = ray.Position + ray.Direction * closest;
                }
                else
                {
                    // Use area in front of the viewport
                    hitLocation = ViewPosition + ViewDirection * 100;
                }
            }

            // Drag assets
            if (_dragAssets.HasValidDrag)
            {
                result = _dragAssets.Effect;

                // Process items
                for (int i = 0; i < _dragAssets.Objects.Count; i++)
                {
                    var item = _dragAssets.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }
            // Drag actor type
            else if (_dragActorType.HasValidDrag)
            {
                result = _dragActorType.Effect;

                // Process items
                for (int i = 0; i < _dragActorType.Objects.Count; i++)
                {
                    var item = _dragActorType.Objects[i];
                    Spawn(item, hit, ref hitLocation);
                }
            }

            return(result);
        }