示例#1
0
        private void ParsePolygons(idLexer lexer, CollisionModel model)
        {
            idToken token = lexer.CheckTokenType(TokenType.Number, 0);

            float[] tmp;
            Vector3 normal;

            lexer.ExpectTokenString("{");

            while (lexer.CheckTokenString("}") == false)
            {
                // parse polygon
                int edgeCount = lexer.ParseInt();

                CollisionModelPolygon p = new CollisionModelPolygon();
                p.Material = _traceModelMaterial;
                p.Contents = ContentFlags.All;
                p.Edges    = new int[edgeCount];

                lexer.ExpectTokenString("(");

                for (int i = 0; i < edgeCount; i++)
                {
                    p.Edges[i] = lexer.ParseInt();
                }

                lexer.ExpectTokenString(")");

                tmp    = lexer.Parse1DMatrix(3);
                normal = new Vector3(tmp[0], tmp[1], tmp[2]);

                p.Plane.Normal = normal;
                p.Plane.D      = lexer.ParseFloat();

                tmp          = lexer.Parse1DMatrix(3);
                p.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

                tmp          = lexer.Parse1DMatrix(3);
                p.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

                token = lexer.ExpectTokenType(TokenType.String, 0);

                // get material
                p.Material   = idE.DeclManager.FindMaterial(token.ToString());
                p.Contents   = p.Material.ContentFlags;
                p.CheckCount = 0;

                // filter polygon into tree
                FilterPolygonIntoTree(model, model.Node, p);
            }
        }
		private void ParsePolygons(idLexer lexer, CollisionModel model)
		{
			idToken token = lexer.CheckTokenType(TokenType.Number, 0);
			float[] tmp;
			Vector3 normal;

			lexer.ExpectTokenString("{");

			while(lexer.CheckTokenString("}") == false)
			{
				// parse polygon
				int edgeCount = lexer.ParseInt();

				CollisionModelPolygon p = new CollisionModelPolygon();
				p.Material = _traceModelMaterial;
				p.Contents = ContentFlags.All;
				p.Edges = new int[edgeCount];

				lexer.ExpectTokenString("(");

				for(int i = 0; i < edgeCount; i++)
				{
					p.Edges[i] = lexer.ParseInt();
				}

				lexer.ExpectTokenString(")");

				tmp = lexer.Parse1DMatrix(3);
				normal = new Vector3(tmp[0], tmp[1], tmp[2]);

				p.Plane.Normal = normal;
				p.Plane.D = lexer.ParseFloat();

				tmp = lexer.Parse1DMatrix(3);
				p.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

				tmp = lexer.Parse1DMatrix(3);
				p.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

				token = lexer.ExpectTokenType(TokenType.String, 0);

				// get material
				p.Material = idE.DeclManager.FindMaterial(token.ToString());
				p.Contents = p.Material.ContentFlags;
				p.CheckCount = 0;

				// filter polygon into tree
				FilterPolygonIntoTree(model, model.Node, p);
			}
		}
示例#3
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);
        }
		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);
		}