コード例 #1
0
        private void ReadNodes(InternalBspLump lump, BinaryReader reader)
        {
            reader.BaseStream.Seek(lump.offset, SeekOrigin.Begin);
            nodes = new InternalBspNode[lump.size / Marshal.SizeOf(typeof(InternalBspNode))];

            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i]       = new InternalBspNode();
                nodes[i].plane = reader.ReadInt32();
                nodes[i].front = reader.ReadInt32();
                nodes[i].back  = reader.ReadInt32();
                nodes[i].bbox  = new int[6];

                for (int j = 0; j < nodes[i].bbox.Length; j++)
                {
                    nodes[i].bbox[j] = reader.ReadInt32();
                }

                TransformBoundingBox(nodes[i].bbox);
            }
        }
コード例 #2
0
ファイル: Quake3Level.cs プロジェクト: WolfgangSt/axiom
		private void ReadNodes( InternalBspLump lump, BinaryReader reader )
		{
			reader.BaseStream.Seek( lump.offset, SeekOrigin.Begin );

			for ( int i = 0; i < nodes.Length; i++ )
			{
				nodes[ i ] = new InternalBspNode();
				nodes[ i ].plane = reader.ReadInt32();
				nodes[ i ].front = reader.ReadInt32();
				nodes[ i ].back = reader.ReadInt32();
				nodes[ i ].bbox = new int[ 6 ];

				for ( int j = 0; j < nodes[ i ].bbox.Length; j++ )
					nodes[ i ].bbox[ j ] = reader.ReadInt32();

				TransformBoundingBox( nodes[ i ].bbox );
			}
		}
コード例 #3
0
        private void CreateNodes(Quake3Level q3lvl)
        {
            // Allocate memory for all nodes (leaves and splitters)
            nodes     = new BspNode[q3lvl.NumNodes + q3lvl.NumLeaves];
            numLeaves = q3lvl.NumLeaves;
            leafStart = q3lvl.NumNodes;

            // Run through and initialize the array so front/back node pointers
            // aren't null.
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new BspNode();
            }

            // Convert nodes
            // In our array, first q3lvl.NumNodes are non-leaf, others are leaves
            for (int i = 0; i < q3lvl.NumNodes; i++)
            {
                BspNode         node   = nodes[i];
                InternalBspNode q3node = q3lvl.Nodes[i];

                node.IsLeaf = false;
                node.Owner  = this;

                Plane splitPlane = new Plane();

                // Set plane
                splitPlane.Normal = new Vector3(
                    q3lvl.Planes[q3node.plane].normal[0],
                    q3lvl.Planes[q3node.plane].normal[1],
                    q3lvl.Planes[q3node.plane].normal[2]
                    );
                splitPlane.D = -q3lvl.Planes[q3node.plane].distance;

                node.SplittingPlane = splitPlane;

                // Set bounding box
                node.BoundingBox = new AxisAlignedBox(
                    new Vector3(
                        q3node.bbox[0],
                        q3node.bbox[1],
                        q3node.bbox[2]
                        ),
                    new Vector3(
                        q3node.bbox[3],
                        q3node.bbox[4],
                        q3node.bbox[5]
                        )
                    );

                // Set back pointer
                // Negative indexes in Quake3 mean leaves.
                if (q3node.back < 0)
                {
                    node.BackNode = nodes[leafStart + (~(q3node.back))];
                }
                else
                {
                    node.BackNode = nodes[q3node.back];
                }

                // Set front pointer
                // Negative indexes in Quake3 mean leaves
                if (q3node.front < 0)
                {
                    node.FrontNode = nodes[leafStart + (~(q3node.front))];
                }
                else
                {
                    node.FrontNode = nodes[q3node.front];
                }
            }
        }