示例#1
0
        private bool InsideAllChildren(CollisionModelNode node, idBounds bounds)
        {
            if (node.PlaneType != -1)
            {
                float v  = (node.PlaneType == 0) ? bounds.Min.X : (node.PlaneType == 1) ? bounds.Min.Y : bounds.Min.Z;
                float v2 = (node.PlaneType == 0) ? bounds.Max.X : (node.PlaneType == 1) ? bounds.Max.Y : bounds.Max.Z;

                if (v >= node.PlaneDistance)
                {
                    return(false);
                }
                else if (v2 <= node.PlaneDistance)
                {
                    return(false);
                }
                else if (InsideAllChildren(node.Children[0], bounds) == false)
                {
                    return(false);
                }
                else if (InsideAllChildren(node.Children[1], bounds) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        private void GetNodeBounds_R(ref idBounds bounds, CollisionModelNode node)
        {
            while (true)
            {
                foreach (CollisionModelPolygon poly in node.Polygons)
                {
                    bounds.AddPoint(poly.Bounds.Min);
                    bounds.AddPoint(poly.Bounds.Max);
                }

                foreach (CollisionModelBrush brush in node.Brushes)
                {
                    bounds.AddPoint(brush.Bounds.Min);
                    bounds.AddPoint(brush.Bounds.Max);
                }

                if (node.PlaneType == -1)
                {
                    break;
                }

                GetNodeBounds_R(ref bounds, node.Children[1]);
                node = node.Children[0];
            }
        }
示例#3
0
        private ContentFlags GetNodeContents(CollisionModelNode node)
        {
            ContentFlags contents = 0;

            while (true)
            {
                foreach (CollisionModelPolygon p in node.Polygons)
                {
                    contents |= p.Contents;
                }

                foreach (CollisionModelBrush b in node.Brushes)
                {
                    contents |= b.Contents;
                }

                if (node.PlaneType == -1)
                {
                    break;
                }

                contents |= GetNodeContents(node.Children[1]);
                node      = node.Children[0];
            }

            return(contents);
        }
示例#4
0
        private void FilterPolygonIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelPolygon p)
        {
            while (node.PlaneType != -1)
            {
                if (InsideAllChildren(node, p.Bounds) == true)
                {
                    break;
                }

                float v  = (node.PlaneType == 0) ? p.Bounds.Min.X : (node.PlaneType == 1) ? p.Bounds.Min.Y : p.Bounds.Min.Z;
                float v2 = (node.PlaneType == 0) ? p.Bounds.Max.X : (node.PlaneType == 1) ? p.Bounds.Max.Y : p.Bounds.Max.Z;

                if (v >= node.PlaneDistance)
                {
                    node = node.Children[0];
                }
                else if (v2 <= node.PlaneDistance)
                {
                    node = node.Children[1];
                }
                else
                {
                    FilterPolygonIntoTree(model, node.Children[1], p);
                    node = node.Children[0];
                }
            }

            node.Polygons.Add(p);
        }
示例#5
0
        private void FilterBrushIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelBrush b)
        {
            while (node.PlaneType != -1)
            {
                if (InsideAllChildren(node, b.Bounds) == true)
                {
                    break;
                }

                float v  = (node.PlaneType == 0) ? b.Bounds.Min.X : (node.PlaneType == 1) ? b.Bounds.Min.Y : b.Bounds.Min.Z;
                float v2 = (node.PlaneType == 0) ? b.Bounds.Max.X : (node.PlaneType == 1) ? b.Bounds.Max.Y : b.Bounds.Max.Z;

                if (v >= node.PlaneDistance)
                {
                    node = node.Children[0];
                }
                else if (v2 <= node.PlaneDistance)
                {
                    node = node.Children[1];
                }
                else
                {
                    FilterBrushIntoTree(model, node.Children[1], b);
                    node = node.Children[0];
                }
            }

            node.Brushes.Add(b);
        }
示例#6
0
        private idBounds GetNodeBounds(CollisionModelNode node)
        {
            idBounds bounds = idBounds.Zero;

            bounds.Clear();

            GetNodeBounds_R(ref bounds, node);

            if (bounds.IsCleared == true)
            {
                bounds = idBounds.Zero;
            }

            return(bounds);
        }
示例#7
0
        private void SetupTraceModelStructure()
        {
            // setup model
            CollisionModel model = new CollisionModel();

            _models[idE.MaxSubModels] = model;

            // create node to hold the collision data
            CollisionModelNode node = new CollisionModelNode();

            node.PlaneType = -1;
            model.Node     = node;

            // allocate vertex and edge arrays
            //model.Vertices = new CollisionModelVertex[idE.MaxTraceModelVertices];
            //model->edges = (cm_edge_t *) Mem_ClearedAlloc( model->maxEdges * sizeof(cm_edge_t) );

            // create a material for the trace model polygons
            _traceModelMaterial = idE.DeclManager.FindMaterial("_tracemodel", false);

            if (_traceModelMaterial == null)
            {
                idConsole.FatalError("_tracemodel material not found");
            }

            // allocate polygons

            /*for ( i = 0; i < MAX_TRACEMODEL_POLYS; i++ ) {
             *      trmPolygons[i] = AllocPolygonReference( model, MAX_TRACEMODEL_POLYS );
             *      trmPolygons[i]->p = AllocPolygon( model, MAX_TRACEMODEL_POLYEDGES );
             *      trmPolygons[i]->p->bounds.Clear();
             *      trmPolygons[i]->p->plane.Zero();
             *      trmPolygons[i]->p->checkcount = 0;
             *      trmPolygons[i]->p->contents = -1;		// all contents
             *      trmPolygons[i]->p->material = trmMaterial;
             *      trmPolygons[i]->p->numEdges = 0;
             * }
             * // allocate brush for position test
             * trmBrushes[0] = AllocBrushReference( model, 1 );
             * trmBrushes[0]->b = AllocBrush( model, MAX_TRACEMODEL_POLYS );
             * trmBrushes[0]->b->primitiveNum = 0;
             * trmBrushes[0]->b->bounds.Clear();
             * trmBrushes[0]->b->checkcount = 0;
             * trmBrushes[0]->b->contents = -1;		// all contents
             * trmBrushes[0]->b->numPlanes = 0;*/
        }
示例#8
0
        private CollisionModelNode ParseNodes(idLexer lexer, CollisionModel model, CollisionModelNode parent)
        {
            model.NodeCount++;

            lexer.ExpectTokenString("(");

            CollisionModelNode node = new CollisionModelNode();

            node.Parent        = parent;
            node.PlaneType     = lexer.ParseInt();
            node.PlaneDistance = lexer.ParseFloat();

            lexer.ExpectTokenString(")");

            if (node.PlaneType != -1)
            {
                node.Children[0] = ParseNodes(lexer, model, node);
                node.Children[1] = ParseNodes(lexer, model, node);
            }

            return(node);
        }
		private void SetupTraceModelStructure()
		{
			// setup model
			CollisionModel model = new CollisionModel();

			_models[idE.MaxSubModels] = model;

			// create node to hold the collision data
			CollisionModelNode node = new CollisionModelNode();
			node.PlaneType = -1;
			model.Node = node;

			// allocate vertex and edge arrays
			//model.Vertices = new CollisionModelVertex[idE.MaxTraceModelVertices];
			//model->edges = (cm_edge_t *) Mem_ClearedAlloc( model->maxEdges * sizeof(cm_edge_t) );

			// create a material for the trace model polygons
			_traceModelMaterial = idE.DeclManager.FindMaterial("_tracemodel", false);

			if(_traceModelMaterial == null)
			{
				idConsole.FatalError("_tracemodel material not found");
			}

			// allocate polygons
			/*for ( i = 0; i < MAX_TRACEMODEL_POLYS; i++ ) {
				trmPolygons[i] = AllocPolygonReference( model, MAX_TRACEMODEL_POLYS );
				trmPolygons[i]->p = AllocPolygon( model, MAX_TRACEMODEL_POLYEDGES );
				trmPolygons[i]->p->bounds.Clear();
				trmPolygons[i]->p->plane.Zero();
				trmPolygons[i]->p->checkcount = 0;
				trmPolygons[i]->p->contents = -1;		// all contents
				trmPolygons[i]->p->material = trmMaterial;
				trmPolygons[i]->p->numEdges = 0;
			}
			// allocate brush for position test
			trmBrushes[0] = AllocBrushReference( model, 1 );
			trmBrushes[0]->b = AllocBrush( model, MAX_TRACEMODEL_POLYS );
			trmBrushes[0]->b->primitiveNum = 0;
			trmBrushes[0]->b->bounds.Clear();
			trmBrushes[0]->b->checkcount = 0;
			trmBrushes[0]->b->contents = -1;		// all contents
			trmBrushes[0]->b->numPlanes = 0;*/
		}
		private bool InsideAllChildren(CollisionModelNode node, idBounds bounds)
		{
			if(node.PlaneType != -1)
			{
				float v = (node.PlaneType == 0) ? bounds.Min.X : (node.PlaneType == 1) ? bounds.Min.Y : bounds.Min.Z;
				float v2 = (node.PlaneType == 0) ? bounds.Max.X : (node.PlaneType == 1) ? bounds.Max.Y : bounds.Max.Z;

				if(v >= node.PlaneDistance)
				{
					return false;
				}
				else if(v2 <= node.PlaneDistance)
				{
					return false;
				}
				else if(InsideAllChildren(node.Children[0], bounds) == false)
				{
					return false;
				}
				else if(InsideAllChildren(node.Children[1], bounds) == false)
				{
					return false;
				}
			}

			return true;
		}
		private CollisionModelNode ParseNodes(idLexer lexer, CollisionModel model, CollisionModelNode parent)
		{
			model.NodeCount++;

			lexer.ExpectTokenString("(");

			CollisionModelNode node = new CollisionModelNode();
			node.Parent = parent;
			node.PlaneType = lexer.ParseInt();
			node.PlaneDistance = lexer.ParseFloat();

			lexer.ExpectTokenString(")");

			if(node.PlaneType != -1)
			{
				node.Children[0] = ParseNodes(lexer, model, node);
				node.Children[1] = ParseNodes(lexer, model, node);
			}

			return node;
		}
		private ContentFlags GetNodeContents(CollisionModelNode node)
		{
			ContentFlags contents = 0;
			
			while(true)
			{
				foreach(CollisionModelPolygon p in node.Polygons)
				{
					contents |= p.Contents;
				}

				foreach(CollisionModelBrush b in node.Brushes)
				{
					contents |= b.Contents;
				}

				if(node.PlaneType == -1)
				{
					break;
				}

				contents |= GetNodeContents(node.Children[1]);
				node = node.Children[0];
			}

			return contents;
		}
		private void GetNodeBounds_R(ref idBounds bounds, CollisionModelNode node)
		{
			while(true)
			{
				foreach(CollisionModelPolygon poly in node.Polygons)
				{
					bounds.AddPoint(poly.Bounds.Min);
					bounds.AddPoint(poly.Bounds.Max);
				}

				foreach(CollisionModelBrush brush in node.Brushes)
				{
					bounds.AddPoint(brush.Bounds.Min);
					bounds.AddPoint(brush.Bounds.Max);
				}

				if(node.PlaneType == -1)
				{
					break;
				}

				GetNodeBounds_R(ref bounds, node.Children[1]);
				node = node.Children[0];
			}
		}
		private idBounds GetNodeBounds(CollisionModelNode node)
		{
			idBounds bounds = idBounds.Zero;
			bounds.Clear();

			GetNodeBounds_R(ref bounds, node);

			if(bounds.IsCleared == true)
			{
				bounds = idBounds.Zero;
			}

			return bounds;
		}
		private void FilterPolygonIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelPolygon p)
		{
			while(node.PlaneType != -1)
			{
				if(InsideAllChildren(node, p.Bounds) == true)
				{					
					break;
				}

				float v = (node.PlaneType == 0) ? p.Bounds.Min.X : (node.PlaneType == 1) ? p.Bounds.Min.Y : p.Bounds.Min.Z;
				float v2 = (node.PlaneType == 0) ? p.Bounds.Max.X : (node.PlaneType == 1) ? p.Bounds.Max.Y : p.Bounds.Max.Z;

				if(v >= node.PlaneDistance)
				{
					node = node.Children[0];
				}
				else if(v2 <= node.PlaneDistance)
				{
					node = node.Children[1];
				}
				else
				{
					FilterPolygonIntoTree(model, node.Children[1], p);
					node = node.Children[0];
				}
			}

			node.Polygons.Add(p);
		}
		private void FilterBrushIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelBrush b)
		{
			while(node.PlaneType != -1)
			{
				if(InsideAllChildren(node, b.Bounds) == true)
				{
					break;
				}

				float v = (node.PlaneType == 0) ? b.Bounds.Min.X : (node.PlaneType == 1) ? b.Bounds.Min.Y : b.Bounds.Min.Z;
				float v2 = (node.PlaneType == 0) ? b.Bounds.Max.X : (node.PlaneType == 1) ? b.Bounds.Max.Y : b.Bounds.Max.Z;

				if(v >= node.PlaneDistance)
				{
					node = node.Children[0];
				}
				else if(v2 <= node.PlaneDistance)
				{
					node = node.Children[1];
				}
				else
				{
					FilterBrushIntoTree(model, node.Children[1], b);
					node = node.Children[0];
				}
			}

			node.Brushes.Add(b);
		}