public bool IsVisible(Vector3 start, Vector3 end)
        {
            Vector3 vDirection = end - start;
            Vector3 vPoint     = start;

            int iStepCount = (int)vDirection.Length();

            vDirection = vDirection / iStepCount;

            Leaf pLeaf = new Leaf()
            {
                area = -1
            };

            while (iStepCount > 0)
            {
                vPoint += vDirection;

                pLeaf = GetLeafForPoint(vPoint);

                if (pLeaf.area != -1)
                {
                    if (
                        (pLeaf.contents & ContentsFlag.CONTENTS_SOLID) == ContentsFlag.CONTENTS_SOLID ||
                        (pLeaf.contents & ContentsFlag.CONTENTS_DETAIL) == ContentsFlag.CONTENTS_DETAIL)
                    {
                        break;
                    }
                }

                iStepCount--;
            }
            return((pLeaf.contents & ContentsFlag.CONTENTS_SOLID) != ContentsFlag.CONTENTS_SOLID);
        }
        public Leaf GetLeafForPoint(Vector3 point)
        {
            int node = 0;

            Node  pNode;
            Plane pPlane;

            float d = 0.0f;

            while (node >= 0)
            {
                pNode  = nodes[node];
                pPlane = planes[pNode.planenum];

                d = Vector3.Dot(point, pPlane.normal) - pPlane.distance;

                if (d > 0)
                {
                    node = pNode.children[0];
                }
                else
                {
                    node = pNode.children[1];
                }
            }

            return(
                (-node - 1) >= 0 && -node - 1 < leafs.Length ?
                leafs[-node - 1] :
                new Leaf()
            {
                area = -1, contents = ContentsFlag.CONTENTS_EMPTY
            }
                );
        }
        private Vector3[] GetVertices(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_VERTEXES];

            stream.Position = lump.offset;
            Vector3[] vertices = new Vector3[(lump.length / 3) / 4];

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i]   = new Vector3();
                vertices[i].x = UtilityReader.ReadFloat(stream);
                vertices[i].y = UtilityReader.ReadFloat(stream);
                vertices[i].z = UtilityReader.ReadFloat(stream);
            }

            return(vertices);
        }
        private Plane[] GetPlanes(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_PLANES];

            Plane[] planes = new Plane[lump.length / 20];
            stream.Position = lump.offset;

            for (int i = 0; i < planes.Length; i++)
            {
                planes[i] = new Plane();

                Vector3 normal = new Vector3();
                normal.x = UtilityReader.ReadFloat(stream);
                normal.y = UtilityReader.ReadFloat(stream);
                normal.z = UtilityReader.ReadFloat(stream);

                planes[i].normal   = normal;
                planes[i].distance = UtilityReader.ReadFloat(stream);
                planes[i].type     = UtilityReader.ReadInt(stream);
            }

            return(planes);
        }