public override void Initialize(int width, int height)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PointSize(5f);

            test.Normal = new Vector3(0f, 1f, 0.5f);
            aabbs[0]    = new AABB(new Point(-2f, -2f, -2f), new Point(-1f, -1f, -1f));
            aabbs[1]    = new AABB(new Point(2f, 1f, 2f), new Point(4f, 3f, 4f));
            aabbs[2]    = new AABB(new Point(1f, 0f, 1f), new Point(0f, -1f, 0f));
            aabbs[3]    = new AABB(new Point(5f, 5f, 5f), new Point(-5f, -5f, -5f));

            bool[] results = new bool[] {
                false, false, true, true
            };
            int t = 0;

            for (int i = 0; i < aabbs.Length; ++i)
            {
                if (Intersects.AABBPlaneIntersect(aabbs[i], test) != results[t++])
                {
                    LogError("Expected aabb " + i + " to " +
                             (results[t - 1] ? "intersect" : "not intersect") +
                             " the plane");
                }
            }
        }
Exemple #2
0
        public override void Initialize(int width, int height)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            aabbs[0] = new AABB(new Point(-0.5f, -2f, -0.5f), new Point(0.5f, 2f, 0.5f));
            aabbs[1] = new AABB();
            aabbs[2] = new AABB(new Point(1f, 1f, 1f), new Point(3f, 3f, 3f));
            aabbs[3] = new AABB(new Point(-3f, -3f, -3f), new Point(-4f, -4f, -4f));

            bool[] results = new bool[] {
                true, true, false, false, true, true, true, false, false,
                true, true, false, false, false, false, true,
            };
            int t = 0;

            for (int i = 0; i < aabbs.Length; ++i)
            {
                for (int j = 0; j < aabbs.Length; ++j)
                {
                    if (Intersects.AABBAABBIntersect(aabbs[i], aabbs[j]) != results[t++])
                    {
                        LogError("aabb " + i + " and " + j + " should " +
                                 (results[t - 1] ? "" : "not ") + "intersect"
                                 );
                    }
                }
            }
        }
        public override void Initialize(int width, int height)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PointSize(5f);

            planes[0] = new Plane();
            planes[1] = new Plane(new Vector3(0f, 1f, 0.2f), 3f);
            planes[2] = new Plane(new Vector3(0f, 1f, 0f), -2f);
            planes[3] = new Plane(new Vector3(-1f, 1f, 2f), 3f);
            planes[4] = new Plane(new Vector3(1f, 0f, 0f), 3f);

            bool[] results = new bool[] {
                true, false, true, false, true
            };
            int t = 0;

            for (int i = 0; i < planes.Length; ++i)
            {
                if (Intersects.SpherePlaneIntersect(planes[i], test) != results[t++])
                {
                    LogError("Expected plane " + i + " to " +
                             (results[t - 1] ? "intersect" : "not intersect") +
                             " the sphere");
                }
            }
        }
        public override void Initialize(int width, int height)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            spheres[0] = new Sphere(new Point(0f, 0f, 0f), 2f);
            spheres[1] = new Sphere(new Point(0f, 3.5f, 0f), 1f);
            spheres[2] = new Sphere(new Point(0f, -3f, 0f), 1f);
            spheres[3] = new Sphere(new Point(1f, 0f, 0f), 1f);

            bool[] results = new bool[] {
                true, false, true, true, false, true, false, false, true,
                false, true, false, true, false, false, true
            };
            int t = 0;

            for (int i = 0; i < spheres.Length; ++i)
            {
                for (int j = 0; j < spheres.Length; ++j)
                {
                    if (Intersects.SphereSphereIntersect(spheres[i], spheres[j]) != results[t++])
                    {
                        LogError("sphere " + i + " and " + j + " should " +
                                 (results[t - 1] ? "" : "not ") + "intersect"
                                 );
                    }
                }
            }
        }
Exemple #5
0
        public bool Insert(OBJ obj)
        {
            //bounding sphere is model space, we need world
            Sphere worldSpaceSphere = new Sphere();

            worldSpaceSphere.Position = new Point(Matrix4.MultiplyPoint(obj.WorldMatrix, obj.BoundingSphere.Position.ToVector()));
            float scale = Math.Max(obj.WorldMatrix[0, 0], Math.Max(obj.WorldMatrix[1, 1], obj.WorldMatrix[2, 2]));

            worldSpaceSphere.Radius = obj.BoundingSphere.Radius * scale;
            if (Intersects.SphereAABBIntersect(worldSpaceSphere, Bounds))
            {
                //we know obj intersects node if a leaf
                //add to list, if not recurse
                if (Children != null)
                {
                    foreach (OctreeNode child in Children)
                    {
                        child.Insert(obj);
                    }
                }
                else
                {
                    Contents.Add(obj);
                }
                return(true);
            }
            return(false);
        }
Exemple #6
0
        public void RemoveRange()
        {
            var data = new List <Person> {
                new Person(), new Person(), new Person()
            };
            var itemsToRemove = data.Take(2).ToList();

            var sut = new FakeDbSet <Person>(data);

            var result = sut.RemoveRange(itemsToRemove);

            Assert.That(data, !Intersects.With(itemsToRemove));
            Assert.That(result, Is.EquivalentTo(itemsToRemove));
        }
        public override void Render()
        {
            base.Render();
            DrawOrigin();

            for (int i = 0; i < aabbs.Length; ++i)
            {
                GL.Color3(0f, 0f, 1f);
                if (Intersects.AABBPlaneIntersect(test, aabbs[i]))
                {
                    GL.Color3(1f, 0f, 0f);
                }
                aabbs[i].Render();
            }

            GL.Color3(0f, 0f, 1f);
            test.Render(5f);
        }
Exemple #8
0
        public override void Render()
        {
            base.Render();
            DrawOrigin();

            for (int i = 0; i < aabbs.Length; ++i)
            {
                GL.Color3(0f, 0f, 1f);
                for (int j = 0; j < aabbs.Length; ++j)
                {
                    if (i != j && Intersects.AABBAABBIntersect(aabbs[i], aabbs[j]))
                    {
                        GL.Color3(1f, 0f, 0f);
                        break;
                    }
                }
                aabbs[i].Render();
            }
        }
        public override void Render()
        {
            base.Render();
            DrawOrigin();

            for (int i = 0; i < spheres.Length; ++i)
            {
                GL.Color3(0f, 0f, 1f);
                for (int j = 0; j < spheres.Length; ++j)
                {
                    if (i != j && Intersects.SphereSphereIntersect(spheres[i], spheres[j]))
                    {
                        GL.Color3(1f, 0f, 0f);
                        break;
                    }
                }
                spheres[i].Render();
            }
        }
        public override void Render()
        {
            base.Render();
            DrawOrigin();

            GL.Disable(EnableCap.CullFace);
            for (int i = 0; i < planes.Length; ++i)
            {
                GL.Color3(0f, 0f, 1f);
                if (Intersects.SpherePlaneIntersect(test, planes[i]))
                {
                    GL.Color3(1f, 0f, 0f);
                }
                planes[i].Render();
            }
            GL.Enable(EnableCap.CullFace);

            GL.Color3(0f, 0f, 1f);
            test.Render();
        }
Exemple #11
0
        public override void Render()
        {
            GL.Disable(EnableCap.Lighting);
            base.Render();
            DrawOrigin();
            GL.Enable(EnableCap.Lighting);

            GL.Color3(0f, 0f, 1f);
            foreach (OBJ obj in objs)
            {
                obj.Render();
            }

            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.CullFace);
            float t = 0;

            foreach (Ray test in tests)
            {
                bool intersection = false;
                foreach (OBJ obj in objs)
                {
                    if (Intersects.OBJRaycast(test, obj, out t))
                    {
                        intersection = true;
                    }
                }
                if (intersection)
                {
                    GL.Color3(0f, 1f, 0f);
                }
                else
                {
                    GL.Color3(1f, 0f, 0f);
                }
                test.Render();
            }
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Lighting);
        }
Exemple #12
0
        public OBJ Raycast(Ray ray, out float t)
        {
            debugVisited = true;


            //none leaf nodes
            if (Children != null)
            {
                foreach (OctreeNode child in Children)
                {
                    //AABB Ray intersection?
                    if (LinesAndRays.RaycastAABB(ray, child.Bounds, out t))
                    {
                        //recursively call raycast
                        OBJ result = child.Raycast(ray, out t);
                        //return whatever is hit
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                }
            }
            //leaf node
            //bounds already intersect ray
            else if (Contents != null)
            {
                //loop through all children
                foreach (OBJ content in Contents)
                {
                    //return first hit child
                    if (Intersects.OBJRaycast(ray, content, out t))
                    {
                        return(content);
                    }
                }
            }
            t = 0f;
            return(null);
        }
Exemple #13
0
        private bool IntersectsWithSelection(Vehicle vehicle, Vector2 topLeftV, Vector2 bottomRightV)
        {
            //Buffer selection
            topLeftV.X     -= 20f;
            topLeftV.Y     -= 20f;
            bottomRightV.X += 20f;
            bottomRightV.Y += 20f;

            //Cheap calculation if our selection box has intersected with the center of a vehicle
            Vector2 vehicleLocation = vehicle.GetPosition();

            if (vehicleLocation.X > topLeftV.X && vehicleLocation.X < bottomRightV.X && vehicleLocation.Y > topLeftV.Y && vehicleLocation.Y < bottomRightV.Y)
            {
                return(true);
            }

            //Else we will do a rotated bounding box detection
            BoundingBox boundingBoxVehicle   = new BoundingBox(vehicle.GetSize(), vehicleLocation, vehicle.GetDirectionRadian());
            BoundingBox boundingBoxSelection = new BoundingBox(topLeftV, bottomRightV);

            return(Intersects.IsBoundingBoxCollision(boundingBoxVehicle, boundingBoxSelection));
        }
        public override void Render()
        {
            GL.Disable(EnableCap.Lighting);
            base.Render();
            DrawOrigin();
            GL.Enable(EnableCap.Lighting);

            GL.Color3(0f, 0f, 1f);
            foreach (OBJ obj in objs)
            {
                obj.Render();
            }

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.Disable(EnableCap.Lighting);
            foreach (AABB test in tests)
            {
                bool intersection = false;
                foreach (OBJ obj in objs)
                {
                    if (Intersects.OBJAABBIntersect(test, obj))
                    {
                        intersection = true;
                    }
                }
                if (intersection)
                {
                    GL.Color3(0f, 1f, 0f);
                }
                else
                {
                    GL.Color3(1f, 0f, 0f);
                }
                test.Render();
            }
            GL.Enable(EnableCap.Lighting);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
        }
Exemple #15
0
 public bool Intersects(Block block)
 {
     return(Intersects(block, (0, 0)));
 }