Exemplo n.º 1
0
        /// <inheritdoc />
        public override bool RayCastSelf(ref RayCastData ray, out float distance, out Vector3 normal)
        {
            normal = Vector3.Up;

            // Check if skip raycasts
            if ((ray.Flags & RayCastData.FlagTypes.SkipEditorPrimitives) == RayCastData.FlagTypes.SkipEditorPrimitives)
            {
                distance = 0;
                return(false);
            }

            BoundingSphere sphere = new BoundingSphere(Transform.Translation, 7.0f);

            return(CollisionsHelper.RayIntersectsSphere(ref ray.Ray, ref sphere, out distance));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />.
        /// </summary>
        /// <param name="ray">The ray 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 Ray ray, out Vector3 point)
        {
            // Put ray in box space
            Ray bRay;

            Transformation.WorldToLocalVector(ref ray.Direction, out bRay.Direction);
            Transformation.WorldToLocal(ref ray.Position, out bRay.Position);

            // Perform a regular ray to BoundingBox check
            var  bb         = new BoundingBox(-Extents, Extents);
            bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point);

            // Put the result intersection back to world
            if (intersects)
            {
                Transformation.LocalToWorld(ref point, out point);
            }

            return(intersects);
        }
        /// <summary>
        /// Determines whether there is an intersection between a <see cref="Ray" /> and a <see cref="OrientedBoundingBox" />.
        /// </summary>
        /// <param name="ray">The ray 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 Ray ray, out Vector3 point)
        {
            // Put ray in box space
            Matrix.Invert(ref Transformation, out Matrix invTrans);

            Ray bRay;

            Vector3.TransformNormal(ref ray.Direction, ref invTrans, out bRay.Direction);
            Vector3.TransformCoordinate(ref ray.Position, ref invTrans, out bRay.Position);

            //Perform a regular ray to BoundingBox check
            var  bb         = new BoundingBox(-Extents, Extents);
            bool intersects = CollisionsHelper.RayIntersectsBox(ref bRay, ref bb, out point);

            //Put the result intersection back to world
            if (intersects)
            {
                Vector3.TransformCoordinate(ref point, ref Transformation, out point);
            }

            return(intersects);
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
    void DealDamage()
    {
        Vector3            bombPos = GetTransform().localPosition;
        List <IDamageable> targets = CollisionsHelper.GetAllDamageableTargetsInArea(bombPos, m_DamageRadius);

        if (targets != null && targets.Count > 0)
        {
            for (int i = 0; i < targets.Count; i++)
            {
                Vector3 directionToTarget = targets[i].GetTransform().localPosition - bombPos;
                float   distance          = directionToTarget.magnitude;
                float   damage            = Mathf.Lerp(m_MaxDamage, m_MinDamage, distance / m_DamageRadius);
                Debug.Log(string.Format("Target {0}: distance = {1}, original damage = {2}", i, distance, damage));
                if (CollisionsHelper.CheckCollisionWithWall(bombPos, directionToTarget, distance))
                {
                    Debug.Log("There is wall between -> decrease damage");
                    damage *= m_WallDamageMultiplier;
                }
                Debug.LogWarning(string.Format("Final Damage {0}", damage));
                targets[i].DealDamage(ref damage);
            }
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// Determines whether the current objects contains a <see cref="BoundingSphere" />.
 /// </summary>
 /// <param name="sphere">The sphere to test.</param>
 /// <returns>The type of containment the two objects have.</returns>
 public ContainmentType Contains(ref BoundingSphere sphere)
 {
     return(CollisionsHelper.SphereContainsSphere(ref this, ref sphere));
 }
Exemplo n.º 7
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>
        /// <returns>Whether the two objects intersected.</returns>
        public bool Intersects(ref Ray ray)
        {
            float distance;

            return(CollisionsHelper.RayIntersectsSphere(ref ray, ref this, out distance));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether the current objects contains a triangle.
 /// </summary>
 /// <param name="vertex1">The first vertex of the triangle to test.</param>
 /// <param name="vertex2">The second vertex of the triangle to test.</param>
 /// <param name="vertex3">The third vertex of the triangle to test.</param>
 /// <returns>The type of containment the two objects have.</returns>
 public ContainmentType Contains(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
 {
     return(CollisionsHelper.SphereContainsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Determines whether the current objects contains a <see cref="BoundingBox" />.
 /// </summary>
 /// <param name="box">The box to test.</param>
 /// <returns>The type of containment the two objects have.</returns>
 public ContainmentType Contains(ref BoundingBox box)
 {
     return(CollisionsHelper.SphereContainsBox(ref this, ref box));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingSphere" />.
 /// </summary>
 /// <param name="sphere">The sphere 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 BoundingSphere sphere, out Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out point));
 }
Exemplo n.º 11
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="line">When the method completes, contains the line of intersection as a <see cref="Ray" />, or a zero ray if there was no intersection.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Plane plane, out Ray line)
 {
     return(CollisionsHelper.PlaneIntersectsPlane(ref this, ref plane, out line));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a triangle.
 /// </summary>
 /// <param name="vertex1">The first vertex of the triangle to test.</param>
 /// <param name="vertex2">The second vertex of the triangle to test.</param>
 /// <param name="vertex3">The third vertex of the triangle 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 Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out point));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />.
 /// </summary>
 /// <param name="box">The box 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 BoundingBox box, out Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsBox(ref this, ref box, out point));
 }
Exemplo n.º 14
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="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 Ray ray, out Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsRay(ref this, ref ray, out point));
 }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
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>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Ray ray)
 {
     return(CollisionsHelper.RayIntersectsRay(ref this, ref ray, out _));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a triangle.
 /// </summary>
 /// <param name="vertex1">The first vertex of the triangle to test.</param>
 /// <param name="vertex2">The second vertex of the triangle to test.</param>
 /// <param name="vertex3">The third vertex of the triangle to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public PlaneIntersectionType Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
 {
     return(CollisionsHelper.PlaneIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3));
 }
Exemplo n.º 18
0
        /// <inheritdoc />
        public override bool RayCastSelf(ref Ray ray, out float distance)
        {
            BoundingSphere sphere = new BoundingSphere(Transform.Translation, 7.0f);

            return(CollisionsHelper.RayIntersectsSphere(ref ray, ref sphere, out distance));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingSphere" />.
 /// </summary>
 /// <param name="sphere">The sphere to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public PlaneIntersectionType Intersects(ref BoundingSphere sphere)
 {
     return(CollisionsHelper.PlaneIntersectsSphere(ref this, ref sphere));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />.
 /// </summary>
 /// <param name="box">The box to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public PlaneIntersectionType Intersects(ref BoundingBox box)
 {
     return(CollisionsHelper.PlaneIntersectsBox(ref this, ref box));
 }
Exemplo n.º 21
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));
 }
Exemplo n.º 22
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>
 /// <returns>Whether the two objects intersected.</returns>
 public PlaneIntersectionType Intersects(ref Plane plane)
 {
     return(CollisionsHelper.PlaneIntersectsSphere(ref plane, ref this));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a triangle.
 /// </summary>
 /// <param name="vertex1">The first vertex of the triangle to test.</param>
 /// <param name="vertex2">The second vertex of the triangle to test.</param>
 /// <param name="vertex3">The third vertex of the triangle 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 Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance)
 {
     return(CollisionsHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out distance));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a triangle.
 /// </summary>
 /// <param name="vertex1">The first vertex of the triangle to test.</param>
 /// <param name="vertex2">The second vertex of the triangle to test.</param>
 /// <param name="vertex3">The third vertex of the triangle to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
 {
     return(CollisionsHelper.SphereIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />.
 /// </summary>
 /// <param name="box">The box 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 BoundingBox box, out float distance)
 {
     return(CollisionsHelper.RayIntersectsBox(ref this, ref box, out distance));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingBox" />.
 /// </summary>
 /// <param name="box">The box to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref BoundingBox box)
 {
     return(CollisionsHelper.BoxIntersectsSphere(ref box, ref this));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingSphere" />.
 /// </summary>
 /// <param name="sphere">The sphere 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 BoundingSphere sphere, out float distance)
 {
     return(CollisionsHelper.RayIntersectsSphere(ref this, ref sphere, out distance));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a <see cref="BoundingSphere" />.
 /// </summary>
 /// <param name="sphere">The sphere to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref BoundingSphere sphere)
 {
     return(CollisionsHelper.SphereIntersectsSphere(ref this, ref sphere));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Determines if there is an intersection between the current object and a point.
 /// </summary>
 /// <param name="point">The point to test.</param>
 /// <returns>Whether the two objects intersected.</returns>
 public bool Intersects(ref Vector3 point)
 {
     return(CollisionsHelper.RayIntersectsPoint(ref this, ref point));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Determines whether the current objects contains a point.
 /// </summary>
 /// <param name="point">The point to test.</param>
 /// <returns>The type of containment the two objects have.</returns>
 public ContainmentType Contains(ref Vector3 point)
 {
     return(CollisionsHelper.SphereContainsPoint(ref this, ref point));
 }