Exemplo n.º 1
0
        private void OnDrawGizmos()
        {
            Plane3  plane  = CreatePlane3(Plane);
            Sphere3 sphere = CreateSphere3(Sphere);

            bool test = Intersection.TestPlane3Sphere3(ref plane, ref sphere);
            Plane3Sphere3Intr info;
            bool find = Intersection.FindPlane3Sphere3(ref plane, ref sphere, out info);

            FiguresColor();
            DrawPlane(ref plane, Plane);
            DrawSphere(ref sphere);

            if (find)
            {
                if (info.IntersectionType == IntersectionTypes.Other)
                {
                    ResultsColor();
                    DrawCircle(ref info.Circle);
                }
            }

            LogInfo(info.IntersectionType);
            if (test != find)
            {
                LogError("test != find");
            }
        }
Exemplo n.º 2
0
        public static void Test(
            Entity entity1, object[] boundingVolumes1, ref Matrix worldTransform1, ref Vector3 translation1, ref Quaternion rotation1, ref Vector3 scale1,
            Entity entity2, object[] boundingVolumes2, ref Matrix worldTransform2, ref Vector3 translation2, ref Quaternion rotation2, ref Vector3 scale2,
            bool needAllContacts, ref Contact contact
            )
        {
            Debug.Assert(scale1.X == scale1.Y && scale1.Y == scale1.Z);
            Debug.Assert(scale2.X == scale2.Y && scale2.Y == scale2.Z);

            for (int i = 0; i < boundingVolumes1.Length; ++i)
            {
                Sphere3 sphere1 = (Sphere3)boundingVolumes1[i];

                for (int j = 0; j < boundingVolumes2.Length; ++j)
                {
                    Sphere3 sphere2 = (Sphere3)boundingVolumes2[j];

                    Vector3 center1 = Vector3.Transform(sphere1.Center, worldTransform1);
                    float   radius1 = scale1.X * sphere1.Radius;
                    Vector3 center2 = Vector3.Transform(sphere2.Center, worldTransform2);
                    float   radius2 = scale2.X * sphere2.Radius;

                    Vector3 diff = center2 - center1;
                    if (diff.LengthSquared() < (radius1 + radius2) * (radius1 + radius2))
                    {
                        diff.Normalize();
                        Vector3 point = center1 + diff * radius1;
                        contact.AddContactPoint(ref point, ref diff);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void OnDrawGizmos()
        {
            Ray3    ray    = CreateRay3(Ray);
            Sphere3 sphere = CreateSphere3(Sphere);

            bool            test = Intersection.TestRay3Sphere3(ref ray, ref sphere);
            Ray3Sphere3Intr info;
            bool            find = Intersection.FindRay3Sphere3(ref ray, ref sphere, out info);

            FiguresColor();
            DrawRay(ref ray);
            DrawSphere(ref sphere);

            if (find)
            {
                ResultsColor();
                if (info.IntersectionType == IntersectionTypes.Point)
                {
                    DrawPoint(info.Point0);
                }
                else if (info.IntersectionType == IntersectionTypes.Segment)
                {
                    DrawSegment(info.Point0, info.Point1);
                    DrawPoint(info.Point0);
                    DrawPoint(info.Point1);
                }
            }

            LogInfo(info.IntersectionType);
            if (test != find)
            {
                LogError("test != find");
            }
        }
Exemplo n.º 4
0
    void OnMouseUp()
    {
        transform.localScale = new Vector3(1f, 1f, 1f);

        if (id == 1 && PlayerPrefs.GetString(Sphere1.gameObject.name) == "Open")
        {
            mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material;
        }
        else if (id == 2 && PlayerPrefs.GetString(Sphere2.gameObject.name) == "Open")
        {
            mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material;
        }
        else if (id == 3 && PlayerPrefs.GetString(Sphere3.gameObject.name) == "Open")
        {
            mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material;
        }
        else if (id == 4 && PlayerPrefs.GetString(Sphere4.gameObject.name) == "Open")
        {
            mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material;
        }
        else if (id == 5 && PlayerPrefs.GetString(Sphere5.gameObject.name) == "Open")
        {
            mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material;
        }
    }
Exemplo n.º 5
0
        public List <T> GetIntersecting(Sphere3 sphere)
        {
            var list = new List <T>();

            Root.AppendIntersecting(list, sphere);
            return(list);
        }
        private void OnDrawGizmos()
        {
            Vector3 v0 = V0.position;
            Vector3 v1 = V1.position;
            Vector3 v2 = V2.position;
            Vector3 v3 = V3.position;

            Sphere3 circumscribed;
            bool    b0 = Sphere3.CreateCircumscribed(v0, v1, v2, v3, out circumscribed);
            Sphere3 inscribed;
            bool    b1 = Sphere3.CreateInscribed(v0, v1, v2, v3, out inscribed);

            FiguresColor();
            DrawTetrahedron(v0, v1, v2, v3);

            ResultsColor();
            if (b0)
            {
                DrawSphere(ref circumscribed);
            }
            if (b1)
            {
                DrawSphere(ref inscribed);
            }

            LogInfo("Circumscribed: " + b0 + "   Inscribed: " + b1);
        }
Exemplo n.º 7
0
        public void IntersectsTouching()
        {
            Sphere3 left  = new Sphere3(new Vector3(0, 0, 1), 1);
            Sphere3 right = new Sphere3(new Vector3(0, 0, -1), 1);

            Assert.IsTrue(left.Intersects(right));
        }
Exemplo n.º 8
0
 private void Update()
 {
     if (Player.lose == false)
     {
         player.gameObject.GetComponent <Rigidbody2D>().velocity -= player.gameObject.GetComponent <Rigidbody2D>().velocity;
     }
     if (SelectNowSphere.id == 1 && PlayerPrefs.GetString(Sphere1.gameObject.name) == "Open")
     {
         mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material;
     }
     else if (SelectNowSphere.id == 2 && PlayerPrefs.GetString(Sphere2.gameObject.name) == "Open")
     {
         mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material;
     }
     else if (SelectNowSphere.id == 3 && PlayerPrefs.GetString(Sphere3.gameObject.name) == "Open")
     {
         mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material;
     }
     else if (SelectNowSphere.id == 4 && PlayerPrefs.GetString(Sphere4.gameObject.name) == "Open")
     {
         mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material;
     }
     else if (SelectNowSphere.id == 5 && PlayerPrefs.GetString(Sphere5.gameObject.name) == "Open")
     {
         mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material;
     }
 }
Exemplo n.º 9
0
        private void OnDrawGizmos()
        {
            Segment3 segment = CreateSegment3(P0, P1);
            Sphere3  sphere  = CreateSphere3(Sphere);

            bool test = Intersection.TestSegment3Sphere3(ref segment, ref sphere);
            Segment3Sphere3Intr info;
            bool find = Intersection.FindSegment3Sphere3(ref segment, ref sphere, out info);

            FiguresColor();
            DrawSegment(ref segment);
            DrawSphere(ref sphere);

            if (find)
            {
                ResultsColor();
                if (info.IntersectionType == IntersectionTypes.Point)
                {
                    DrawPoint(info.Point0);
                }
                else if (info.IntersectionType == IntersectionTypes.Segment)
                {
                    DrawSegment(info.Point0, info.Point1);
                    DrawPoint(info.Point0);
                    DrawPoint(info.Point1);
                }
            }

            LogInfo(info.IntersectionType);
            if (test != find)
            {
                LogError("test != find");
            }
        }
Exemplo n.º 10
0
    /// <summary>
    /// Cartesians to the cartPos vector3 to spherical coordinates.
    /// </summary>
    /// <returns>
    /// The to spherical.
    /// </returns>
    /// <param name='cartPos'>
    /// Cart position.
    /// </param>
    public static Sphere3 CartesianToSpherical(Vector3 cartPos)
    {
        Sphere3 spherePos = new Sphere3();

        spherePos.r     = Mathf.Sqrt(cartPos.x * cartPos.x + cartPos.y * cartPos.y + cartPos.z * cartPos.z);
        spherePos.theta = Mathf.Atan2(cartPos.z, cartPos.x);
        spherePos.phi   = Mathf.Acos(cartPos.y / spherePos.r);
        return(spherePos);
    }
Exemplo n.º 11
0
    /// <summary>
    /// Converts a sphere3 to cartesian coordinates.
    /// </summary>
    /// <returns>
    /// The to cartesian.
    /// </returns>
    /// <param name='spherePos'>
    /// Sphere position.
    /// </param>
    public static Vector3 SphericalToCartesian(Sphere3 spherePos)
    {
        Vector3 cartPos = new Vector3();

        cartPos.x = spherePos.r * Mathf.Cos(spherePos.theta) * Mathf.Sin(spherePos.phi);
        cartPos.y = spherePos.r * Mathf.Cos(spherePos.phi);
        cartPos.z = spherePos.r * Mathf.Sin(spherePos.theta) * Mathf.Sin(spherePos.phi);
        return(cartPos);
    }
Exemplo n.º 12
0
 private void Update()
 {
     if (ToggleToGenerate != _previous)
     {
         _points  = GenerateRandomSet3D(GenerateRadius, GenerateCountMin, GenerateCountMax);
         _sphere0 = Sphere3.CreateFromPointsAAB(_points);
         _sphere1 = Sphere3.CreateFromPointsAverage(_points);
     }
     _previous = ToggleToGenerate;
 }
Exemplo n.º 13
0
        public void Constructs()
        {
            var position = new Vector3(1, 2, 3);
            var radius   = 4f;

            var value = new Sphere3(position, radius);

            Assert.AreEqual(value.Position, position);
            Assert.AreEqual(value.Radius, radius);
        }
Exemplo n.º 14
0
        private void OnDrawGizmos()
        {
            Sphere3 sphere0 = CreateSphere3(Sphere0);
            Sphere3 sphere1 = CreateSphere3(Sphere1);

            bool test = Intersection.TestSphere3Sphere3(ref sphere0, ref sphere1);
            Sphere3Sphere3Intr info;
            bool find = Intersection.FindSphere3Sphere3(ref sphere0, ref sphere1, out info);

            FiguresColor();
            DrawSphere(ref sphere0);
            DrawSphere(ref sphere1);

            if (find)
            {
                ResultsColor();

                if (info.IntersectionType == Sphere3Sphere3IntrTypes.Same)
                {
                    DrawSphere(ref sphere0);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Point)
                {
                    DrawPoint(info.ContactPoint);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Sphere0Point)
                {
                    DrawSphere(ref sphere0);
                    DrawPoint(info.ContactPoint);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Sphere1Point)
                {
                    DrawSphere(ref sphere1);
                    DrawPoint(info.ContactPoint);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Sphere0)
                {
                    DrawSphere(ref sphere0);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Sphere1)
                {
                    DrawSphere(ref sphere1);
                }
                else if (info.IntersectionType == Sphere3Sphere3IntrTypes.Circle)
                {
                    DrawCircle(ref info.Circle);
                }
            }

            LogInfo(info.IntersectionType);
            if (test != find)
            {
                LogError("test != find");
            }
        }
Exemplo n.º 15
0
        /// <summary>Determines where the range clips a sphere</summary>
        /// <param name="sphere">Sphere that will be checked for intersection</param>
        /// <returns>The times at which the range enters or leaves the volume</returns>
        public LineContacts FindContacts(Sphere3 sphere)
        {
            throw new NotImplementedException();

            /*
             * return filterContacts(
             * Collisions.Line3Sphere3Collider.FindContacts(
             *  this.Start, this.End - this.Start, sphere.Center, sphere.Radius
             * )
             * );
             */
        }
Exemplo n.º 16
0
    void OnMouseUp()
    {
        BuySound.Play();
        transform.localScale = new Vector3(1f, 1f, 1f);

        if (PlayerPrefs.GetInt("Coins") >= 40 && SelectNowSphere.id == 1)
        {
            PlayerPrefs.SetString(Sphere1.GetComponent <SelectSphere>().nowSphere, "Open");

            mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material;

            PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 40);
            selectBtn.SetActive(true);
            gameObject.SetActive(false);
        }
        else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 2)
        {
            PlayerPrefs.SetString(Sphere2.GetComponent <SelectSphere>().nowSphere, "Open");
            mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material;

            PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150);
            selectBtn.SetActive(true);
            gameObject.SetActive(false);
        }
        else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 3)
        {
            PlayerPrefs.SetString(Sphere3.GetComponent <SelectSphere>().nowSphere, "Open");
            mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material;

            PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150);
            selectBtn.SetActive(true);
            gameObject.SetActive(false);
        }
        else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 4)
        {
            PlayerPrefs.SetString(Sphere4.GetComponent <SelectSphere>().nowSphere, "Open");
            mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material;

            PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150);
            selectBtn.SetActive(true);
            gameObject.SetActive(false);
        }
        else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 5)
        {
            PlayerPrefs.SetString(Sphere5.GetComponent <SelectSphere>().nowSphere, "Open");
            mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material;
            // PlayerPrefs.SetString("Now", Sphere5.GetComponent<SelectSphere>().nowSphere);
            PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150);
            selectBtn.SetActive(true);
            gameObject.SetActive(false);
        }
    }
        private void OnDrawGizmos()
        {
            Box3    box    = CreateBox3(Box);
            Sphere3 sphere = CreateSphere3(Sphere);

            bool test = Intersection.TestBox3Sphere3(ref box, ref sphere);

            FiguresColor();
            DrawBox(ref box);
            DrawSphere(ref sphere);

            LogInfo(test);
        }
Exemplo n.º 18
0
        private void OnDrawGizmos()
        {
            AAB3    box    = CreateAAB3(Box_Point0, Box_Point1);
            Sphere3 sphere = CreateSphere3(Sphere);

            bool test = Intersection.TestAAB3Sphere3(ref box, ref sphere);

            FiguresColor();
            DrawAAB(ref box);
            DrawSphere(ref sphere);

            LogInfo(test);
        }
Exemplo n.º 19
0
        private void OnDrawGizmos()
        {
            Sphere3 sphere    = new Sphere3(Vector3ex.Zero, Rho);
            Vector3 cartesian = Mathfex.SphericalToCartesian(new Vector3(Rho, Theta, Phi));
            Vector3 spherical = Mathfex.CartesianToSpherical(cartesian);

            FiguresColor();
            DrawSphere(ref sphere);
            ResultsColor();
            DrawSegment(Vector3ex.Zero, cartesian);
            DrawPoint(cartesian);

            LogInfo("Cartesian: " + cartesian.ToStringEx() + "   Spherical: " + spherical.ToStringEx());
        }
        /// <summary>
        /// Tests for an intersection between a ray and a sphere
        /// </summary>
        public static Line3Intersection GetRayIntersection( Ray3 ray, Sphere3 sphere )
        {
            Vector3	originToCentre = ray.Origin - sphere.Centre;

            float	a0	= originToCentre.SqrLength - ( sphere.SqrRadius );
            float	a1	= ray.Direction.Dot( originToCentre );
            float	discriminant;
            Point3	intersectionPt;

            if ( a0 <= 0 )
            {
                //	1 intersection: The origin of the ray is inside the sphere
                discriminant = ( a1 * a1 ) - a0;
                float t = -a1 + Functions.Sqrt( discriminant );

                intersectionPt = ray.GetPointOnRay( t );
                return new Line3Intersection(  intersectionPt, ( intersectionPt - sphere.Centre ).MakeNormal( ), t );
            }
            if ( a1 >= 0 )
            {
                //	No intersections: Ray origin is outside the sphere, ray direction points away from the sphere
                return null;
            }

            discriminant = ( a1 * a1 ) - a0;
            if ( discriminant < 0 )
            {
                //	No intersections: Ray/sphere equation has no roots
                return null;
            }

            if ( discriminant < 0.0001f )	//	TODO: Magic number
            {
                //	1 intersection: Discriminant is close to zero - there's only root to the ray/sphere equation
                float t = -a1;
                intersectionPt = ray.GetPointOnRay( t );
                return new Line3Intersection(  intersectionPt, ( intersectionPt - sphere.Centre ).MakeNormal( ), t );
            }

            //	2 intersections: 2 roots to the ray/sphere equation. Choose the closest
            float root = Functions.Sqrt( discriminant );
            float t0 = -a1 - root;
            float t1 = -a1 + root;

            float closestT = ( t0 < t1 ) ? t0 : t1;

            intersectionPt = ray.GetPointOnRay( closestT );
            return new Line3Intersection(  intersectionPt, ( intersectionPt - sphere.Centre ).MakeNormal( ), closestT );
        }
        private void OnDrawGizmos()
        {
            Sphere3 sphere0 = CreateSphere3(Sphere0);
            Sphere3 sphere1 = CreateSphere3(Sphere1);

            Sphere3 sphere = sphere0;

            sphere.Include(sphere1);             // Sphere which merges sphere0 and sphere1

            FiguresColor();
            DrawSphere(ref sphere0);
            DrawSphere(ref sphere1);
            ResultsColor();
            DrawSphere(ref sphere);
        }
        private void OnDrawGizmos()
        {
            Vector3 point  = Point.position;
            Sphere3 sphere = CreateSphere3(Sphere);

            Vector3 closestPoint;
            float   dist = Distance.Point3Sphere3(ref point, ref sphere, out closestPoint);

            FiguresColor();
            DrawSphere(ref sphere);

            ResultsColor();
            DrawPoint(closestPoint);

            LogInfo(dist);
        }
Exemplo n.º 23
0
        private void OnDrawGizmos()
        {
            if (null != drawSphereGoArr)
            {
                foreach (GameObject item in drawSphereGoArr)
                {
                    if (item == null)
                    {
                        continue;
                    }

                    Sphere3 sphere = new Sphere3(item.transform.position, item.transform.localScale.x);
                    Gizmos.DrawWireSphere(sphere.Center, sphere.Radius);
                }
            }
        }
Exemplo n.º 24
0
        private void OnDrawGizmos()
        {
            Vector3 point  = Point.position;
            Sphere3 sphere = CreateSphere3(Sphere);

            bool cont = sphere.Contains(point);

            FiguresColor();
            DrawSphere(ref sphere);
            if (cont)
            {
                ResultsColor();
            }
            DrawPoint(point);

            LogInfo(cont);
        }
        private void OnDrawGizmos()
        {
            Plane3  plane  = CreatePlane3(Plane);
            Vector3 point  = Point.position;
            AAB3    aab    = CreateAAB3(AABMin, AABMax);
            Box3    box    = CreateBox3(Box);
            Sphere3 sphere = CreateSphere3(Sphere);

            // Get side information.
            // -1 - on the negative side of the plane
            //  0 - on the plane or intersecting the plane
            // +1 - on the positive side of the plane
            int pointSide  = plane.QuerySide(point);
            int aabSide    = plane.QuerySide(ref aab);
            int boxSide    = plane.QuerySide(ref box);
            int sphereSide = plane.QuerySide(ref sphere);

            // true when an object is on the positive side of the plane
            bool pointPos  = plane.QuerySidePositive(point);
            bool aabPos    = plane.QuerySidePositive(ref aab);
            bool boxPos    = plane.QuerySidePositive(ref box);
            bool spherePos = plane.QuerySidePositive(ref sphere);

            // true when an object is on the negative side of the plane
            bool pointNeg  = plane.QuerySideNegative(point);
            bool aabNeg    = plane.QuerySideNegative(ref aab);
            bool boxNeg    = plane.QuerySideNegative(ref box);
            bool sphereNeg = plane.QuerySideNegative(ref sphere);

            // Note that positive/negative tests are little bit more optimized than just query,
            // as they don't have separate check for 0 case.

            FiguresColor();
            DrawPlane(ref plane, Plane);

            SetColor(pointSide); DrawPoint(point);
            SetColor(aabSide); DrawAAB(ref aab);
            SetColor(boxSide); DrawBox(ref box);
            SetColor(sphereSide); DrawSphere(ref sphere);

            LogInfo("PointSignedDistance: " + plane.SignedDistanceTo(point) + " PointNeg: " + pointNeg + " PointPos: " + pointPos + "     AABNeg: " + aabNeg + " AABPos: " + aabPos + "     BoxNeg: " + boxNeg + " BoxPos: " + boxPos + "     SphereNeg: " + sphereNeg + " SpherePos: " + spherePos);
        }
Exemplo n.º 26
0
        public static void Test(
            Entity entity1, object[] boundingVolumes1, ref Matrix worldTransform1, ref Vector3 translation1, ref Quaternion rotation1, ref Vector3 scale1,
            Entity entity2, object[] boundingVolumes2, ref Matrix worldTransform2, ref Vector3 translation2, ref Quaternion rotation2, ref Vector3 scale2,
            bool needAllContacts, ref Contact contact
            )
        {
            for (int i = 0; i < boundingVolumes1.Length; ++i)
            {
                AlignedBox3Tree tree1 = (AlignedBox3Tree)boundingVolumes1[i];

                for (int j = 0; j < boundingVolumes2.Length; ++j)
                {
                    Sphere3 sphere2 = (Sphere3)boundingVolumes2[j];

                    Debug.Assert(scale2.X == scale2.Y && scale2.Y == scale2.Z);
                    Sphere3 transformedSphere2 = new Sphere3(Vector3.Transform(sphere2.Center, worldTransform2), sphere2.Radius * scale2.X);

                    Test(entity1, tree1.Root, tree1.Positions, ref worldTransform1, ref translation1, ref rotation1, ref scale1,
                         entity2, ref transformedSphere2, ref worldTransform2, ref translation2, ref rotation2, ref scale2,
                         needAllContacts, ref contact);
                }
            }
        }
Exemplo n.º 27
0
        public void AppendIntersecting(IList <T> list, Sphere3 sphere)
        {
            // see if the item is in the overbounds.
            foreach (var item in Items)
            {
                if (item.BoundingSphere.Intersects(sphere))
                {
                    list.Add(item);
                }
            }

            // recurse for all children that has influence over the item.
            if (!IsLeaf)
            {
                foreach (var child in children)
                {
                    if (child.Influence.Contains(sphere.Position))
                    {
                        child.AppendIntersecting(list, sphere);
                    }
                }
            }
        }
Exemplo n.º 28
0
        private static void Test(
            Entity entity1, AlignedBox3TreeNode node1, Vector3[] positions1, ref Matrix worldTransform1, ref Vector3 translation1, ref Quaternion rotation1, ref Vector3 scale1,
            Entity entity2, ref Sphere3 sphere2, ref Matrix worldTransform2, ref Vector3 translation2, ref Quaternion rotation2, ref Vector3 scale2,
            bool needAllContacts, ref Contact contact
            )
        {
            /*Sphere3 sphere1;
             * node1.BoundingBox.CreateSphere3(ref worldTransform1, out sphere1);
             * Vector3 diff = sphere1.Center - sphere2.Center;
             * if (diff.LengthSquared() > (sphere1.Radius + sphere2.Radius) * (sphere1.Radius + sphere2.Radius))
             * {
             *  return;
             * }
             */
            Box3   box1, box2;
            Matrix identityMatrix = Matrix.Identity;

            node1.BoundingBox.CreateBox3(ref worldTransform1, out box1);
            sphere2.CreateBox3(ref identityMatrix, out box2);
            if (!Intersection.IntersectBox3Box3(ref box1, ref box2))
            {
                return;
            }

            // see if this node has some primitives => has no children
            if (!node1.HasChildren)
            {
                // test here for all triangles...
                int tricount = node1.NumTriangles;
                for (int i = 0; i < tricount; ++i)
                {
                    //size_t contacts_size = contacts.size();
                    Triangle3 tri = node1.GetTriangle(positions1, i);
                    tri.Vertex0 = Vector3.Transform(tri.Vertex0, worldTransform1);
                    tri.Vertex1 = Vector3.Transform(tri.Vertex1, worldTransform1);
                    tri.Vertex2 = Vector3.Transform(tri.Vertex2, worldTransform1);

                    Vector3 sphereCenter    = sphere2.Center;
                    Vector3 closestPoint    = Vector3.Zero;
                    float   squaredDistance = SquaredDistance.Vector3Triangle3(ref sphereCenter, ref tri, out closestPoint);
                    if (squaredDistance < sphere2.Radius * sphere2.Radius)
                    {
                        if (!contact.ContainsPoint(ref closestPoint))
                        {
                            Vector3 normal = tri.Normal;
                            contact.AddContactPoint(ref closestPoint, ref normal);
                        }

                        if (!needAllContacts)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                Test(
                    entity1, node1.Left, positions1, ref worldTransform1, ref translation1, ref rotation1, ref scale1,
                    entity2, ref sphere2, ref worldTransform2, ref translation2, ref rotation2, ref scale2,
                    needAllContacts, ref contact
                    );

                if (!needAllContacts && contact.Count > 0)
                {
                    return;
                }

                Test(
                    entity1, node1.Right, positions1, ref worldTransform1, ref translation1, ref rotation1, ref scale1,
                    entity2, ref sphere2, ref worldTransform2, ref translation2, ref rotation2, ref scale2,
                    needAllContacts, ref contact
                    );
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of Sphere3 and copies the
 /// Sphere3 's' variable passed to it.
 /// </summary>
 /// <param name='s'>
 /// S.
 /// </param>
 public Sphere3(Sphere3 s)
 {
     this.phi   = s.phi;
     this.theta = s.theta;
     this.r     = s.r;
 }
Exemplo n.º 30
0
 public Vector3 ToCartesian()
 {
     return(Sphere3.SphericalToCartesian(this));
 }
Exemplo n.º 31
0
        public void IntersectsOverlapping()
        {
            Sphere3 value = new Sphere3(new Vector3(0, 0, 0), 1);

            Assert.IsTrue(value.Intersects(value));
        }