예제 #1
0
 /// <summary>
 /// R_CullBox
 /// Returns true if the box is completely outside the frustom
 /// </summary>
 public static bool CullBox(ref Vector3 mins, ref Vector3 maxs, ref Plane[] frustum)
 {
     for (var i = 0; i < 4; i++)
     {
         if (MathLib.BoxOnPlaneSide(ref mins, ref maxs, frustum[i]) == 2)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// SV_FindTouchedLeafs
        /// </summary>
        private void FindTouchedLeafs(MemoryEdict ent, MemoryNodeBase node)
        {
            if (node.contents == ( Int32 )Q1Contents.Solid)
            {
                return;
            }

            // add an efrag if the node is a leaf

            if (node.contents < 0)
            {
                if (ent.num_leafs == ProgramDef.MAX_ENT_LEAFS)
                {
                    return;
                }

                var leaf    = ( MemoryLeaf )node;
                var leafnum = Array.IndexOf(sv.worldmodel.Leaves, leaf) - 1;

                ent.leafnums[ent.num_leafs] = ( Int16 )leafnum;
                ent.num_leafs++;
                return;
            }

            // NODE_MIXED
            var n          = ( MemoryNode )node;
            var splitplane = n.plane;
            var sides      = MathLib.BoxOnPlaneSide(ref ent.v.absmin, ref ent.v.absmax, splitplane);

            // recurse down the contacted sides
            if ((sides & 1) != 0)
            {
                FindTouchedLeafs(ent, n.children[0]);
            }

            if ((sides & 2) != 0)
            {
                FindTouchedLeafs(ent, n.children[1]);
            }
        }
예제 #3
0
        /// <summary>
        /// R_SplitEntityOnNode
        /// </summary>
        private void SplitEntityOnNode(MemoryNodeBase node)
        {
            if (node.contents == ( int )Q1Contents.Solid)
            {
                return;
            }

            // add an efrag if the node is a leaf
            if (node.contents < 0)
            {
                if (this._EfragTopNode == null)
                {
                    this._EfragTopNode = node as MemoryNode;
                }

                var leaf = (MemoryLeaf)( object )node;

                // grab an efrag off the free list
                var ef = this.Host.Client.cl.free_efrags;
                if (ef == null)
                {
                    this.Host.Console.Print("Too many efrags!\n");
                    return;     // no free fragments...
                }

                this.Host.Client.cl.free_efrags = this.Host.Client.cl.free_efrags.entnext;

                ef.entity = this._AddEnt;

                // add the entity link
                // *lastlink = ef;
                if (this._LastObj is Entity)
                {
                    ((Entity)this._LastObj).efrag = ef;
                }
                else
                {
                    ((EFrag)this._LastObj).entnext = ef;
                }

                this._LastObj = ef; // lastlink = &ef->entnext;
                ef.entnext    = null;

                // set the leaf links
                ef.leaf     = leaf;
                ef.leafnext = leaf.efrags;
                leaf.efrags = ef;

                return;
            }

            // NODE_MIXED
            var n = node as MemoryNode;

            if (n == null)
            {
                return;
            }

            var splitplane = n.plane;
            var sides      = MathLib.BoxOnPlaneSide(ref this._EMins, ref this._EMaxs, splitplane);

            if (sides == 3)
            {
                // split on this plane
                // if this is the first splitter of this bmodel, remember it
                if (this._EfragTopNode == null)
                {
                    this._EfragTopNode = n;
                }
            }

            // recurse down the contacted sides
            if ((sides & 1) != 0)
            {
                this.SplitEntityOnNode(n.children[0]);
            }

            if ((sides & 2) != 0)
            {
                this.SplitEntityOnNode(n.children[1]);
            }
        }