Ejemplo n.º 1
0
        private Leaf[] GetLeafs(Stream stream)
        {
            Lump lump = header.lumps[(int)LumpType.LUMP_LEAFS];
            Leaf[] leafData = new Leaf[lump.length / 56];
            stream.Position = lump.offset;

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

                leafData[i].contents = (ContentsFlag)UtilityReader.ReadInt(stream);
                leafData[i].cluster = UtilityReader.ReadShort(stream);
                leafData[i].area = UtilityReader.ReadShort(stream);
                leafData[i].flags = UtilityReader.ReadShort(stream);

                leafData[i].mins = new short[3];
                leafData[i].mins[0] = UtilityReader.ReadShort(stream);
                leafData[i].mins[1] = UtilityReader.ReadShort(stream);
                leafData[i].mins[2] = UtilityReader.ReadShort(stream);

                leafData[i].maxs = new short[3];
                leafData[i].maxs[0] = UtilityReader.ReadShort(stream);
                leafData[i].maxs[1] = UtilityReader.ReadShort(stream);
                leafData[i].maxs[2] = UtilityReader.ReadShort(stream);

                leafData[i].firstleafface = UtilityReader.ReadUShort(stream);
                leafData[i].numleaffaces = UtilityReader.ReadUShort(stream);
                leafData[i].firstleafbrush = UtilityReader.ReadUShort(stream);
                leafData[i].numleafbrushes = UtilityReader.ReadUShort(stream);
                leafData[i].leafWaterDataID = UtilityReader.ReadShort(stream);
            }

            return leafData;
        }
Ejemplo n.º 2
0
        public bool IsVisible(Vector3D start, Vector3D end)
        {
            Vector3D vDirection = end - start;
            Vector3D vPoint = start;

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

            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;
        }